Asynchronous Saga Manager in Axon 3

When using Asynchronous commandBus, the saga seem to be handling the same event multiple times. Here is the config for the commandBus

@Bean
public CommandBus asynchronousCommandBus(final TransactionManager transactionManager) {
AsynchronousCommandBus asynchronousCommandBus = new AsynchronousCommandBus();
asynchronousCommandBus.registerHandlerInterceptor(new TransactionManagingInterceptor<>(transactionManager));
return asynchronousCommandBus;
}

What am I missing. The saga works fine when using SimpleCommandBus.

Regards,

Livious

Which Axon version are you using? Which other beans are you defining (e.g. SagaConfiguration beans)?

Allard

Thanks for your response, I am using version 3.0.4. The other beans configured as as below :

@Bean
public SagaRepository pain009BatchSagaSagaRepository() {
return new AnnotatedSagaRepository<>(InterbankPain009BatchSaga.class, sagaStore, resourceInjector());
}

@Bean
public AbstractSagaManager statusReportBatchSagaAbstractSagaManager() {
AnnotatedSagaManager annotatedSagaManager = new AnnotatedSagaManager<>(InterbankPain009BatchSaga.class, pain009BatchSagaSagaRepository());
return annotatedSagaManager;
}

Just to give you more context of what we are trying to do. We are receiving and processing a batch of transactions, for each transaction we dispatch a command which result in an event. The SAGA listen to these events and keep count of the transactions with the same associationProperty before writing the transaction to the database. Using the SimpleCommandBus this works fine, if i receive a batch of 10 transaction, 10 records will be in the DB. However, if we change to AsynchronousCommandBus more than 10 records will the in the DB as some of the recored will be handled multiple times by the SAGA. Another interesting fact is that if I change the SAGA to a normal event listener, everything works fine, 10 records will be in the DB.

In our case we have to use the SAGA for our solution to work.

Please kindly assist.

Regards,

Livious

Hi Livious,

Sounds like the Saga is registered twice somehow.
I guess you’ve debugged the situation; have you checked if you had different Saga instances for the first and the second hit of an Saga Event Handler?
If yes, that suggests the saga is registered twice in the config.

Cheers,

Steven

Hi Steven,

I have not debugged to that level of detail, what is strange to me is that one transaction can be handle once the next transaction as many as 4 times and this number keeps on changing and is not consistence.
Do you have any idea what will cause the saga instance to register multiple time?

Regards,

Livious

Hi Livious,

The one thing I think of right now, is that you’ve got (1) the saga annotated with @Saga in a Spring Boot application and (2) are creating the saga instance in a configuration file as well.
Cant say I’ve tested such a set up myself, but I do recall a similar issue some months ago, which was due to a duplicate Saga Instance (hence why I’m pointing it out).

In an earlier response from your side you pointed out you’re specifying some Saga beans yourself.
If you’re in a Spring Boot environment and have you’re saga annotated with @Saga, you shouldn’t be required to create your own saga repository and saga manager.
The latter (saga manager) is the component which fires up a saga for certain events, so a duplicate SagaManager bean for you Saga might just be the issue here.

Hope this helps!

Cheers,

Steven

Hi Steven

Thanks for your responses, I really appreciate your assistance.

I have removed the SagaManager bean from my configuration and I have left the @Saga declaration on the saga class, however the problem still exist. My analysis at the moment is that all work fine when using the SimpleCommandBus, but as soon as this is changed to AsynchronousCommandBus the saga start handling the same event multiple times.

At the moment I have no clue how to resolve the issue.

Regards,

Livious

Hi Livious,

how do you observe the duplicate invocation? Do you have any SagaConfiguration beans in your application context?

Honestly, I don’t think the implementation of the Command Bus has anything to do with how often an event invokes a Saga. It seems more likely that even in the SimpleCommandBus case the invocation happens twice, but you don’t notice because it runs in the same transaction.

Allard