Handling exceptions in axon when listening to the same event multiple times in same spring boot application

We are in the process of integrating axon to our existing spring boot application. We are using Axon 4.1.2 and Axon Server currently.

For example in the registration process, we fire a RegisterCommand, which is read by the RegisterAggregate and which fires the RegistrationDoneEvent.

There are two EventHandlers listening to this RegistrationDoneEvent. Which are RegistrationNeo4jEventHandler and RegistrationSqlEventHandler.

Everything works fine when there are no exceptions. However, when there IS an exception, let’s say the RegistrationNeo4jEventHandler receives the event if there is an exception, then the RegistrationSqlEventHandler sill gets called and it seems everything is still rolled back on the SqlEventHandler even though the SqlEventHandler ran successfully.

How can we make it so that the RegistrationSqlEventHandler completes and commits BUT the RegistrationNeo4jEventHandler retries?

trying of the event entirely upon failure? Let’s say if we had four event handlers (HandlerA, HandlerB, HandlerC, HandlerD) listening to the SAME event. If HandlerC fails we want to trigger it to be retried when we lets say fixed the underlying issue BUT also make sure that the other handlers which listened to the SAME event are not rerun.

The following code snippets include the aggregate and the event handlers.

RegisterAggregate

`
@Aggregate
public class RegisterAggregate {

@CommandHandler
public RegisterAggregate(RegisterCommand command) {
apply(new RegistrationDoneEvent(command));
}
}
`

RegistrationSqlEventHandler

`
@Service
@Transactional
public class RegistrationSqlEventHandler {

@EventHandler
@Order(Ordered.HIGHEST_PRECEDENCE)
public void on(RegistrationDoneEvent event) {

}
}
`

RegistrationNeo4jEventHandler

`
@Service
@Transactional
public class RegistrationNeo4jEventHandler {

@EventHandler
public void on(RegistrationDoneEvent event) {

}
}
`

Hi all,

This question was posted by Milinda on StackOverflow as well, which received an approved answer.
If you are thus encountering a similar problem, we recommend to check out said question here.

Cheers,
Steven