从Amazon Simple Workflow Service的角度来看,活动执行是一对 API 调用:PollForActivityTask
它们RespondActivityTaskCompleted
共享一个任务令牌。这些调用不需要来自同一个线程、进程甚至主机。
默认情况下, AWS Flow Framework同步执行活动。使用@ManualActivityCompletion
注解表示活动方法返回时活动未完成。此类活动应使用提供的明确完成(或失败)ManualActivityCompletionClient
。
以下是摘自AWS Flow Framework 开发人员指南的示例:
@ManualActivityCompletion
public String getName() {
ActivityExecutionContext executionContext = contextProvider.getActivityExecutionContext();
String taskToken = executionContext.getTaskToken();
sendEmail("abc@xyz.com",
"Please provide a name for the greeting message and close task with token: " + taskToken);
return "This will not be returned to the caller";
}
public class CompleteActivityTask {
public void completeGetNameActivity(String taskToken) {
AmazonSimpleWorkflow swfClient = new AmazonSimpleWorkflowClient(…); //pass in user credentials
ManualActivityCompletionClientFactory manualCompletionClientFactory = new ManualActivityCompletionClientFactoryImpl(swfClient);
ManualActivityCompletionClient manualCompletionClient
= manualCompletionClientFactory.getClient(taskToken);
String result = "Hello World!";
manualCompletionClient.complete(result);
}
public void failGetNameActivity(String taskToken, Throwable failure) {
AmazonSimpleWorkflow swfClient
= new AmazonSimpleWorkflowClient(…); //pass in user credentials
ManualActivityCompletionClientFactory manualCompletionClientFactory
= new ManualActivityCompletionClientFactoryImpl(swfClient);
ManualActivityCompletionClient manualCompletionClient
= manualCompletionClientFactory.getClient(taskToken);
manualCompletionClient.fail(failure);
}
}
使用实现活动是@ManualActivityCompletion
实现细节。工作流代码通过相同的接口调用它,并且与同步实现的任何活动没有区别。