I have a Saga and the Saga sends Commands to different microservices on specific Events. Some of the microservices may be down more than others so, I want to configure a CommandGateway with a RetryScheduler and also to implement my own IntervalRetryScheduler so that I'm able to do a retry for every RuntimeException but only for some Axon Commands (this was a big help Why does the RetryScheduler in Axon Framework not retry after a NoHandlerForCommandException?).
Everything works as expected, my only concern is if there are any issues coming from the fact that some Commands will be sent with the default CommandGateway and some with my custom CommandGateway that has the custom retry built in ?
For now I would not use the custom CommandGateway even for Commands with no retry
I've gone with the distinct CommandGateway beans approach
@Bean
public CommandGateway commandGateway(){
Configurer configurer = DefaultConfigurer.defaultConfiguration();
CommandBus commandBus = configurer.buildConfiguration().commandBus();
CommandGateway commandGateway = DefaultCommandGateway.builder().commandBus(commandBus).build();
return commandGateway;
}
@Bean
public CommandGateway commandGatewayWithRetry(){
Configurer configurer = DefaultConfigurer.defaultConfiguration();
CommandBus commandBus = configurer.buildConfiguration().commandBus();
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
RetryScheduler rs = IntervalRetrySchedulerImpl.builder().retryExecutor(scheduledExecutorService).maxRetryCount(5).retryInterval(1000).build();
CommandGateway commandGateway = DefaultCommandGateway.builder().commandBus(commandBus).retryScheduler(rs).build();
return commandGateway;
}