Cannot find workflow definition even though I register it to worker

59 views Asked by At

I'm registering two workflows to my Cadence worker based on Spring Boot. However, even though I successfully register all my workflows and start the worker, I'm only able to use one workflow. Here is a code snippet.

@Configuration
public class CadenceAutoConfiguration {
  @Bean
  public WorkflowClient workflowClient() {
    return WorkflowClient.newInstance(
        new WorkflowServiceTChannel(ClientOptions.defaultInstance()),
        WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
  }

  @EventListener(ApplicationStartedEvent.class)
  public void startWorker(ApplicationStartedEvent event) {
    System.out.println("Starting workers");
    ApplicationContext context = event.getApplicationContext();
    WorkflowClient workflowClient = context.getBean(WorkflowClient.class);
    WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
    Worker worker = factory.newWorker(TASK_LIST);

    worker.registerWorkflowImplementationTypes(WorkflowA.class);
    worker.registerWorkflowImplementationTypes(WorkflowB.class);
    worker.registerWorkflowImplementationTypes(WorkflowC.class);
    factory.start();
  }
}

I'm only able to use WorkflowC. When I try to invoke WorkflowA and WorkflowB, I got workflow definition not found error. Wonder how to fix the issue?

Tried to restart the worker and Cadence server but didn't work

1

There are 1 answers

0
Chris Qin On BEST ANSWER

The problem comes from the worker.registerWorkflowImplementationTypes. This method takes a varag as an input argument and every time this method is called, it will override the previous calls. In this example, the worker will only have WorkflowC registered because the first two calls are overridden.

The correct way to register the implementation class is passing all classes into this method by doing something like

worker.registerWorkflowImplementationTypes(WorkflowC.class, WorkflowB.class, WorkflowC.class);

This will make sure all workflow classes are loaded to the worker at once.