What to do in case of a transient error in an EventHandler

Hello,

I’ve implemented a CQRS/Event Sourcing application with an external event store and several views. Some views are (for good reasons) managed using a subscribing mode.

I’m wondering how to manage transient error with such views as a network issue or a temporary outage of the underlying database. I can see two possibilities:

  • Either catch the error, compensate the event stored in the external event and send back the error to the consumer. Then it would be up to the consumer to manage either reprocessing or display an error in the HMI for example
  • Implement a try/catch/retry loop. Each time I face a transient error, I loop in the @EventHandler.

What would be the best scenario? If the first scenario is preferable, I don’t really see how to catch the error. Assuming it was the same thread in charge of the @CommandHandler, the @EventSourcingHandler, and the @EventHandler, I thought I would be able to catch an @EventHandler error when I’m doing an AggregateLifecycle.apply() for example.

Thanks for the help

Hello,

When it comes to handling of exceptions in event handlers you can implement ListenerInvocationErrorHandler and configure it within EventHandlingConfiguration. Regarding your two strategies, it really depends on your use case - whether you want to propagate the error to the caller or not. It seems like a good approach to combine those two propositions - retry for number of times and if you don’t succeed throw an exception to the caller. Not sure whether this answers your question, but I’m looking forward to your reply!

Cheers,
Milan.