3.0M4 AsynchronousCommandBus and Sagas Issue

Hello,

I was encountering an issue, where I was implementing a saga.

  • the Saga is triggred by one event an emits a command. It associates with a new porperty, and drops the original association.
  • the command results in an event, which is supposed to trigger the second @SagaEventHandler

When using an AsynchronousCommandBus the second event handler is not triggered. After a lot of debugging, I did go down to the configuration to simplify the environment and replaced the command bus with a SimpleCommandBus suddenly the Saga started to work.

`
@Bean
public CommandBus commandBus() {
// AsynchronousCommandBus commandBus = new AsynchronousCommandBus();
SimpleCommandBus commandBus = new SimpleCommandBus();
commandBus.setDispatchInterceptors(Arrays.asList(new BeanValidationInterceptor<>()));
return commandBus;
}

`

Do I have to make additional configurations on the AsynchronousCommandBus?

I actually like to work with the Asynchronous Command Bus, even during development, as it forces you to not make any assumptions about the sequence of execution of things.

Does anyone have insights on this issue ?

Thanks a lot.

Best regards,
Dominic

Hi Dominic,

my guess is that you have hit an interesting race condition, which I always address in my trainings.
When a Saga sends a command from which it is interested in the resulting events, the association must always happen before the command is sent. Otherwise, the event may have been published already before the Saga is actually associated with the concept.

The reason it does work with a SimpleCommandBus (assuming you’re also using SimpleEventBus) is because in this situation, Axon will postpone actual publication of the events until all previous events have been handled. In that case, the association is made before the events are handled. In the AsyncCommandBus situation, Axon doesn’t wait, and the Command is handled before the association is stored.

Hope this helps.
Cheers,

Allard

Thank you. That makes sense, and changing the sequence of association and command dispatching fixed the issue immediately.

Dominic