我是AWS SWF的新手,嘗試創建一些活動,工作流和工作流啓動器。 我發現了很多例子,在他們的幫助下,我現在可以註冊一個域,創建一些活動並創建一個工作流,但是我無法編寫一個程序來啓動我的工作流執行。如何編寫swf初學者程序
有人可以幫助我在這裏。下面是我的代碼至今:
ActivityWorker.java:
@Activities
@ActivityRegistrationOptions(
defaultTaskHeartbeatTimeoutSeconds = FlowConstants.NONE,
defaultTaskScheduleToCloseTimeoutSeconds = 300,
defaultTaskScheduleToStartTimeoutSeconds = FlowConstants.NONE,
defaultTaskStartToCloseTimeoutSeconds = 300)
public interface ActivityWorker {
@Activity(name = "swftest1", version = "1.0")
@ExponentialRetry(
initialRetryIntervalSeconds=10,
backoffCoefficient=1,
maximumAttempts=5)
public String print() throws IOException;
@Activity(name = "swftest2", version = "1.0")
@ExponentialRetry(
initialRetryIntervalSeconds=10,
backoffCoefficient=1,
maximumAttempts=5)
public String print2() throws IOException;
}
ActivityWorkerImpl.java
public class ActivityWorkerImpl implements ActivityWorker{
@Override
public String print() throws IOException {
System.out.println("Hello..");
return "Printing..";
}
@Override
public String print2() throws IOException {
System.out.println("Hello..");
return "Printing2..";
}
}
Worker.java
@Workflow
@WorkflowRegistrationOptions(
defaultExecutionStartToCloseTimeoutSeconds = 600,
defaultTaskStartToCloseTimeoutSeconds = 300)
public interface Worker {
@Execute(version = "1.0", name="worker1")
public void greet();
}
WorkerImpl.java
public class WorkerImpl implements Worker{
private final ActivityWorkerImpl actWorkerImpl = new ActivityWorkerImpl();
@Override
public void greet() {
new TryCatchFinally() {
@Override
protected void doTry() throws Throwable {
String res= downloadFromS3();
System.out.println("res.."+res);
}
@Override
protected void doCatch(Throwable e) throws Throwable {
throw e;
}
@Override
protected void doFinally() throws Throwable {
// noop
}
};
}
@Asynchronous
private String downloadFromS3() throws IOException {
return this.actWorkerImpl.print();
}
}
Host.java
public class ActivityHost {
public static void main(String[] args) throws Exception {
String domain = "test1";
String taskListToPoll = "HelloWorldList";
ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70*1000);
String swfAccessId = "myid";
String swfSecretKey = "mysecretekey";
AWSCredentials awsCredentials = new BasicAWSCredentials(swfAccessId, swfSecretKey);
AmazonSimpleWorkflow swf = new AmazonSimpleWorkflowClient(awsCredentials, config);
ActivityWorker activityworker = new ActivityWorker(swf, domain, taskListToPoll);
//adding activity
activityworker.addActivitiesImplementation(new ActivityWorkerImpl());
activityworker.start();
//adding workflow
WorkflowWorker worker = new WorkflowWorker(swf,domain, taskListToPoll);
worker.addWorkflowImplementationType(WorkerImpl.class);
worker.start();
}
}
Aftere運行Host.java,我能看到在AWS控制檯,但如何觸發我的工作流程,我無法弄清楚我的活動和工作流程。
有人可以幫我在這裏。
謝謝你的幫助。我指的是相同的例子。我檢查了helloworld示例,並在WorkflowExecutionStarter.java類中引用了BookingWorkflowClientExternalFactory clientFactory,它沒有位於src文件夾中的任何位置,我無法從它的來源找到它... – user3541321
我已經更新了答案,並鏈接到安裝說明。 –