What I learned today — 6 January 2018
Using the Axon Framework’s retry semantics to retry failed commands
By default Axon’s CommandGateway
implementations will retry RuntimeExceptions
, but will never retry checked exception, as those are considered to be business exceptions that can not be recovered without intervention.
If one wishes to customize how failed commands are retried one has to reconfigure the CommandGateway
. This is fine if one makes general changes that affect how all commands issued through the gateway are handled, but the API does not easily support changing the retry behavior for just one command (or a small subset of commands). In order to do this one must create a CommandGateway
for just those commands. The factory pattern may be useful here. Axon provides a CommandGatewayFactory
class that can be used here. Create this object with the correct CommandBus
and a RetryScheduler
. Axon only provides one implementation, the IntervalRetryScheduler
, which is suitable for simple interval-based retrying. The CommandGatewayFactory
also allows registering interceptors and callbacks.