Saga and event handling


What to do if you want to call an external system from within a saga, and you get for example a timeout exception because that external system is tempararily unavailable. How to handle (temp) exceptions?

Will a tracking event processor retry until it succeed? Any other option?

kind regards,

You might call the external system from another thread (or an asynchronous command handler) and have it publish an event with the results of the service call, successful or not. Your saga can listen for that event. That way you aren’t tying up a saga manager thread waiting for the results, and other events can be handled by other saga instances while the external call is in progress.

In general, for high throughput, I’ve found it’s a good idea to avoid doing any blocking operations from inside a saga event handler. A saga should only issue commands, schedule events, and update its state.

That said, if you *do* make a synchronous service call from inside a saga event handler, consider catching exceptions in the saga code rather than relying on Axon to retry. That gives you better control over the error recovery behavior which can be hugely important if the service call isn’t idempotent - you wouldn’t want Axon to blindly retry a “send money to someone” service call that timed out but might have succeeded on the remote side!