|
| 1 | +package com.uber.cadence.samples.spring.cadence; |
| 2 | + |
| 3 | +import static com.uber.cadence.samples.common.SampleConstants.DOMAIN; |
| 4 | +import static com.uber.cadence.samples.spring.common.Constant.TASK_LIST; |
| 5 | + |
| 6 | +import com.uber.cadence.client.WorkflowClient; |
| 7 | +import com.uber.cadence.client.WorkflowClientOptions; |
| 8 | +import com.uber.cadence.samples.spring.workflows.HelloWorldWorkflowImpl; |
| 9 | +import com.uber.cadence.serviceclient.ClientOptions; |
| 10 | +import com.uber.cadence.serviceclient.WorkflowServiceTChannel; |
| 11 | +import com.uber.cadence.worker.Worker; |
| 12 | +import com.uber.cadence.worker.WorkerFactory; |
| 13 | +import org.springframework.boot.context.event.ApplicationStartedEvent; |
| 14 | +import org.springframework.context.ApplicationContext; |
| 15 | +import org.springframework.context.annotation.Bean; |
| 16 | +import org.springframework.context.annotation.Configuration; |
| 17 | +import org.springframework.context.event.EventListener; |
| 18 | + |
| 19 | +@Configuration |
| 20 | +public class CadenceAutoConfiguration { |
| 21 | + @Bean |
| 22 | + public WorkflowClient workflowClient() { |
| 23 | + return WorkflowClient.newInstance( |
| 24 | + new WorkflowServiceTChannel(ClientOptions.defaultInstance()), |
| 25 | + WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); |
| 26 | + } |
| 27 | + |
| 28 | + @EventListener(ApplicationStartedEvent.class) |
| 29 | + public void startWorker(ApplicationStartedEvent event) { |
| 30 | + System.out.println("Starting workers"); |
| 31 | + |
| 32 | + ApplicationContext context = event.getApplicationContext(); |
| 33 | + WorkflowClient workflowClient = context.getBean(WorkflowClient.class); |
| 34 | + WorkerFactory factory = WorkerFactory.newInstance(workflowClient); |
| 35 | + Worker worker = factory.newWorker(TASK_LIST); |
| 36 | + worker.registerWorkflowImplementationTypes(HelloWorldWorkflowImpl.class); |
| 37 | + factory.start(); |
| 38 | + } |
| 39 | +} |
0 commit comments