Can commands be intercepted based on their type?

Hi Guys,

In Axon 4.2 MessageHandlerInterceptor, it seem to intercept any and every command.

I need to add some additional checks on certain type of commands to see whether it is should be allowed to proceed.

I would prefer to register an interceptor per command type.Will I need to have a load of instanceof if-statements in a single interceptor? Does anyone have a good example?

PS: My previous question was unanswered, (!topic/axonframework/dvplEKhI62w). Most likely this query will go under the radar as well…!!! any how trying my luck!!


Hi Roy,

If you are looking for more fine grained control on a message handler prior to executing the actual annotated method, I think you should have a look at Handler Enhancer Definitions.
Providing your own HandlerEnhancerDefinition allows you to wrap a given MessageHandlingMember when for example the payload is of the type you want to wrap it on.

For convenience on your part it is recommended to create an implementation of the WrappedMessageHandlingMember as a result of the HandlerEnhancerDefinition#wrapHandler(MessageHandlingMember) call.

This implementation should then contain the logic you’d like to perform when message handling occurs.


PS. I see that your previous question has been answered too, luckily :wink:

Know that this forum is a community effort, with AxonIQ people adding their insights when time allows it.
It thus might take some time to receive a response to questions.

If response times are of the essence to your project, it might be worthwhile to discuss this further with AxonIQ directly.