How to retry runtime errors from commands dispatched from saga events?


I’m trying to test a scenario where I have to retry commands that throw runtime exceptions from a saga transaction, but I’m just receiving a log with the message bellow with no retry.

2020-02-12 19:50:05.121 WARN 78539 --- [ault-executor-0] o.a.c.gateway.DefaultCommandGateway : Command '' resulted in org.axonframework.commandhandling.CommandExecutionException(java.util.concurrent.CompletionException: Error while getting for request: get [index][_doc][xx-xx-xx-xx]: routing [null])

Do I have to configure some custom error handler to deal with this situation, or the expected behavior is to retry all runtime exceptions?

I really don’t understand how to put something in retry, I appreciate some tips from you folks.



It appears you are using CommandGateway from your Saga.
All the methods on that interface suggest the caller handle errors – based on the general assumption that the sender of the command knows best how to handle errors.

How to handle the error, whether retry, delayed retry, send a notification to someone, or just log it and end the saga is application-specific.

If you want to retry after delay you might consider scheduling an event:
However, in my experience, as Sagas grow in complexity and issue multiple commands to multiple destinations, their state machine nature becomes harder to implement.

Another approach is for the Saga to assume its commands are reliable by delegating to another service which is responsible for retrying. I’ve been using this approach recently.

Hope this helps…

Hi Steven,

It really hopes, thanks.

This is exactly my case, a Saga sending commands to different aggregations.

I’ll try to follow what you lastly mentioned by delegating the retry to another service, as Saga keeps running until reaches a @EndSaga I can control the state and maybe reschedule some events, I’m wondering if I can use the ExponentialBackOffIntervalRetryScheduler for these cases and how to implement it too.