public static void main(String[] args) throws Exception { AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(); service.setEndpoint("https://swf.us-east-1.amazonaws.com"); String domain = "helloWorldWalkthrough"; String taskListToPoll = "HelloWorldAsyncList"; WorkflowWorker wfw = new WorkflowWorker(service, domain, taskListToPoll); wfw.setRegisterDomain(true); wfw.setDomainRetentionPeriodInDays(1); wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class); wfw.start(); ActivityWorker aw = new ActivityWorker(service, domain, taskListToPoll); aw.addActivitiesImplementation(new GreeterActivitiesImpl()); aw.start(); GreeterWorkflowClientExternalFactory clientFactory = new GreeterWorkflowClientExternalFactoryImpl(service, domain); GreeterWorkflowClientExternal client = clientFactory.getClient(); client.greet(); }
@Before public void setUp() throws Exception { configuration = new SWFConfiguration(); configuration.setDomainName("testDomain"); swClient = mock(AmazonSimpleWorkflowClient.class); configuration.setAmazonSWClient(swClient); configuration.setStartWorkflowOptionsParameters(Collections.<String, Object>emptyMap()); endpoint = new SWFEndpoint(); endpoint.setConfiguration(configuration); clientExternal = mock(DynamicWorkflowClientExternalImpl.class); camelSWFWorkflowClient = new CamelSWFWorkflowClient(endpoint, configuration) { @Override DynamicWorkflowClientExternal getDynamicWorkflowClient(String workflowId, String runId) { return clientExternal; } }; }
@Value.Default public AmazonSimpleWorkflow swf() { //SWF holds the connection for 60 seconds to see if a decision is available final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ofSeconds(60); final Duration DEFAULT_SOCKET_TIMEOUT = DEFAULT_CONNECTION_TIMEOUT.plusSeconds(10); return new AmazonSimpleWorkflowClient(new DefaultAWSCredentialsProviderChain(), new ClientConfiguration().withConnectionTimeout((int) DEFAULT_CONNECTION_TIMEOUT.toMillis()) .withSocketTimeout((int) DEFAULT_SOCKET_TIMEOUT.toMillis())); }
/** * Create a new SWF client given the current configuration. * * @return an AmazonSimpleWorkflow client */ AmazonSimpleWorkflow createSWFClient() { AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials(); AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(credentials, new ClientConfiguration().withSocketTimeout(SOCKET_TIMEOUT)); service.setEndpoint(swfServiceUrl); return service; }
private AmazonSimpleWorkflowClient createSWClient() throws Exception { AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); ClientConfiguration clientConfiguration = new ClientConfiguration(); if (!configuration.getClientConfigurationParameters().isEmpty()) { setProperties(clientConfiguration, configuration.getClientConfigurationParameters()); } AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(credentials, clientConfiguration); if (!configuration.getSWClientParameters().isEmpty()) { setProperties(client, configuration.getSWClientParameters()); } return client; }
@Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); amazonSWClient = mock(AmazonSimpleWorkflowClient.class); registry.bind("amazonSWClient", amazonSWClient); return registry; }
@Produces @Singleton public SWFClientProvider getClientProvider() throws Exception { AmazonSimpleWorkflowClient client = SWFUtils.createWorkflowClient(); if (client != null) { SWFUtils.registerDomain(client); } return new SWFClientProvider(client); }
public static AmazonSimpleWorkflowClient createWorkflowClient() { BasicCredentialsProvider credentials = BasicCredentialsProvider.standard(); AmazonSimpleWorkflowClient client = !credentials.isValid() ? null : (AmazonSimpleWorkflowClient) AmazonSimpleWorkflowClientBuilder.standard() .withCredentials(credentials) .withRegion("eu-west-1") .build(); return client; }
public AmazonSimpleWorkflowClient getSWClient() { return configuration.getAmazonSWClient() != null ? configuration.getAmazonSWClient() : amazonSWClient; }
public AmazonSimpleWorkflowClient getAmazonSWClient() { return amazonSWClient; }
/** * To use the given AmazonSimpleWorkflowClient as client */ public void setAmazonSWClient(AmazonSimpleWorkflowClient amazonSWClient) { this.amazonSWClient = amazonSWClient; }
static AmazonSimpleWorkflow createSWFClient() { AWSCredentials awsCredentials = new BasicAWSCredentials("{swfAccessId}", "{swfSecretKey}"); AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(awsCredentials); client.setEndpoint("{swfServiceUrl}"); return client; }
public AmazonSimpleWorkflow createSWFClient() { AWSCredentials awsCredentials = new BasicAWSCredentials(this.swfAccessId, this.swfSecretKey); AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(awsCredentials); client.setEndpoint(this.swfServiceUrl); return client; }
SWFClientProvider(AmazonSimpleWorkflowClient client) { this.client = client; }
public AmazonSimpleWorkflowClient getClient() { return client; }
@Test public void deciderAndWorker() throws Exception { AmazonSimpleWorkflowClient swfClient = provider.getClient(); Assume.assumeNotNull("AWS client not null", swfClient); WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("swfClient", swfClient); camelctx.addRoutes(new RouteBuilder() { public void configure() { String options = "amazonSWClient=#swfClient&domainName=" + SWFUtils.DOMAIN + "&activityList=swf-alist&workflowList=swf-wlist&version=1.0"; from("aws-swf://activity?" + options + "&eventName=processActivities") .log("FOUND ACTIVITY TASK ${body}") .setBody(constant("1")) .to("mock:worker"); from("aws-swf://workflow?" + options + "&eventName=processWorkflows") .log("FOUND WORKFLOW TASK ${body}").filter(header(SWFConstants.ACTION).isEqualTo(SWFConstants.EXECUTE_ACTION)) .to("aws-swf://activity?" + options + "&eventName=processActivities") .setBody(constant("Message two")) .to("aws-swf://activity?" + options + "&eventName=processActivities") .log("SENT ACTIVITY TASK ${body}") .to("mock:decider"); from("direct:start") .to("aws-swf://workflow?" + options + "&eventName=processWorkflows") .log("SENT WORKFLOW TASK ${body}") .to("mock:starter"); } }); MockEndpoint decider = camelctx.getEndpoint("mock:decider", MockEndpoint.class); MockEndpoint worker = camelctx.getEndpoint("mock:worker", MockEndpoint.class); MockEndpoint starter = camelctx.getEndpoint("mock:starter", MockEndpoint.class); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.sendBody("direct:start", "Hello world!"); starter.expectedMessageCount(1); decider.expectedMinimumMessageCount(1); worker.expectedMessageCount(2); String workflowId = starter.getReceivedExchanges().get(0).getIn().getHeader(SWFConstants.WORKFLOW_ID, String.class); Assert.assertNotNull(SWFConstants.WORKFLOW_ID + " not null", workflowId); SWFUtils.terminateWorkflowExecution(swfClient, workflowId); } finally { camelctx.stop(); } }
public static void terminateWorkflowExecution(AmazonSimpleWorkflowClient swfClient, String workflowId) { TerminateWorkflowExecutionRequest terminateReq = new TerminateWorkflowExecutionRequest() .withWorkflowId(workflowId) .withDomain(DOMAIN); swfClient.terminateWorkflowExecution(terminateReq); }