文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
StartMatchingJob
搭配 AWS SDK 使用
下列程式碼範例示範如何使用 StartMatchingJob
。
- SDK for Java 2.x
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Starts a matching job asynchronously for the specified workflow name. * * @param workflowName the name of the workflow for which to start the matching job * @return a {@link CompletableFuture} that completes with the job ID of the started matching job, or an empty * string if the operation fails */ public CompletableFuture<String> startMatchingJobAsync(String workflowName) { StartMatchingJobRequest jobRequest = StartMatchingJobRequest.builder() .workflowName(workflowName) .build(); return getResolutionAsyncClient().startMatchingJob(jobRequest) .whenComplete((response, exception) -> { if (response != null) { String jobId = response.jobId(); logger.info("Job ID: " + jobId); } else { if (exception == null) { throw new CompletionException("An unknown error occurred while starting the job.", null); } Throwable cause = exception.getCause(); if (cause instanceof ConflictException) { throw new CompletionException("The job is already running. Resolve conflicts before starting a new job.", cause); } // Wrap other AWS exceptions in a CompletionException. throw new CompletionException("Failed to start the job: " + exception.getMessage(), exception); } }) .thenApply(response -> response != null ? response.jobId() : ""); }
-
如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 StartMatchingJob。
-