How exactly I can create one HandlerInterceptor for a specific command on axon 3? Someone suggest me in another topic use HandlerInterceptor to prevalidate my commands before applying the event.
Also, how I could add some metadata (tenant name) to all my commands and events?
I saw some people using CommandHandlerInterceptor and UnitOfWorkListenerAdapter to do that but I dont find those classes on AXON3.
unfortunately, that’s right. RegisterHandlerInterceptor is not (yet) part of the CommandBus interface.
By the way, you probably want to use the Dispatch Interceptor here, instead of the HandlerInterceptor. The Dispatch Interceptor is always invoked in the thread that dispatches the event (the thread that will also have the ThreadLocal TenantUtil).
Were there any updates regarding the use of command intercepters (or command interceptors)?
Is it possible to create beans of type MessageDispatchInterceptor and have these picked up by the auto configure automatically (similar to the CorrelationDataProvider for example)?
The examples shown here work, but these are depending on an instance of the command bus to be ready, which may cause cyclic dependencies when putting other AXON related stuff in the same configuration file.
interceptors aren’t automatically picked up from the application context, because there are so many places where interceptors can be configured, that it’s unlikely you want them everywhere.
The cyclic dependency problem is a known one. I have some ideas to work around them, which I hope to be able to implement in upcoming releases. I don’t expect it will make it in 3.2.
In the xxx-spring-boot-autoconfigure project, you create an interface which developers can implement.
public interface XxxConfigurationCustomizer {
void customize(XxxBuilder builder);
}
Then you pick it up in the auto-configuration and use it
@Configuration @ConditionalOnClass({ Xxx.class })
public class XxxAutoConfiguration {
@Autowired(required = false)
private List configurationCustomizers;
@Bean @ConditionalOnMissingBean
public XxxBuilder xxxBuilder(/* Pass other services here /) {
final DefaultXxx.Builder builder = DefaultXxx.builder();
/ Initilaise it with the defaults */
return builder;
}