I have an application that uses Axon tracing extension. When used with SpringBoot, the tracing extension auto-configures its own TracingCommandGateway
via TracingAutoConfiguration.tracingCommandGateway()
.
When I want to add a RetryScheduler
in the picture, it looks like the only way is to copy and modify configuration from TracingAutoConfiguration.tracingCommandGateway()
. In addition, to support the usage of the axon.extension.tracing.enabled
configuration property and the case when it is set to false
, I also have to add configuration for DefaultCommandGateway
. With all this, I ended with a configuration similar to the following:
@ConditionalOnProperty(value = "axon.extension.tracing.enabled", havingValue = "false", matchIfMissing = false)
@Bean
CommandGateway defaultCommandGateway(CommandBus commandBus) {
ScheduledExecutorService scheduledExecutorService = ...
RetryScheduler retryScheduler = ...
CommandGateway defaultCommandGateway = DefaultCommandGateway
.builder()
.commandBus(commandBus)
.retryScheduler(retryScheduler)
.build()
return defaultCommandGateway
}
@ConditionalOnProperty(value = "axon.extension.tracing.enabled", havingValue = "true", matchIfMissing = true)
@Bean
CommandGateway tracingCommandGateway(
Tracer tracer, CommandBus commandBus, OpenTraceDispatchInterceptor openTraceDispatchInterceptor, OpenTraceHandlerInterceptor openTraceHandlerInterceptor,
MessageTagBuilderService messageTagBuilderService)
{
...
ScheduledExecutorService scheduledExecutorService = ...
RetryScheduler retryScheduler = ...
CommandGateway commandGatewayDelegate = DefaultCommandGateway
.builder()
.commandBus(commandBus)
.retryScheduler(retryScheduler)
.build()
TracingCommandGateway tracingCommandGateway = TracingCommandGateway
.builder()
.tracer(tracer)
.delegateCommandGateway(commandGatewayDelegate)
.messageTagBuilderService(messageTagBuilderService)
.build()
...
return tracingCommandGateway
}
As you might guess, I’m not quite happy with such a setup :
- trying to add a
RetryScheduler
on the gateway requires rewriting the gateway config. WithoutRetryScheduler
, my SpringBoot configuration is blissfully unaware of the gateway. - to support configuration above, I have to declare
org.axonframework.extensions.tracing:axon-tracing-spring-boot-starter
andio.opentracing.contrib:opentracing-spring-cloud-starter
as compile dependencies. Without configuringRetryScheduler
, they are declared as runtime only dependencies. - my Spring Boot configuration have to import all those classes from the tracing extension and opentracing library
- my SpringBoot configuration has to deal with the fact that the user may turn off tracing
I’m not quite sure how this can be tackled (and if it is worth dealing with it at all). There are several possibilities, I guess:
- extending
CommandGateway
interface with something likeregisterRetryScheduler()
method. This will be quite a significant breaking change. However, it will allow custom registration of aRetryScheduler
, for example, inApplicationListener<ApplicationStartedEvent>
Spring listener. - adding another interface, something like
RetryableCommandGateway
orRetrySchedulerSupport
. Then gateway implementation can implement it at its own pace. In my case, it will require slight modification of bothDefaultCommandGateway
andTracingCommandGateway
. - modifying
DefaultCommandGateway
andTracingCommandGateway
Spring Boot auto-configuration where auto-configuration can check ifRetryScheduler
is available in the context, and if it is, register it on a gateway.
WDYT?
If I’m missing some alternative way for registering a RetryScheduler that is already present in the framework, please advise.
Tnx