Best practice to manage NoHandlerForCommandException in production?


I’m doing some tests with Axon related to exception management. I want to validate things before presenting it as a valid framework for production … Which I hope so :wink:

One situation doesn’t make me comfortable for production: how to properly manage the situation of asynchronous commands for which no CommandHandler has subscribed?

Here’s a short description of the use case I’m speaking about:
1/ a command is dispatched by a caller in async. mode (no return code expected) through a CustomCommandGateway,
2/ no CommandHandler has subscribed to it,
3/ the caller doesn’t get any CustomCommandGateway: hence, it has no way to know whether its Command should be processed!
4/ a WARN log message is generated by Axon LoggingCallback.

A workaround is to declare NoHandlerForCommandException as a throwable exception on the method definition in the CustomCommandGateway. But explictelly throwing Runtime exceptions like this, is not eleguant …

So, is there any recommendation to manage properly this situation in production? The only option I foresee now, is to raise alerts from the WARN log message.

In a more pro-active way, can we imagine to check at deployment that all commands have a subscribed CommandHandler before turning the system “on”?

FYI I’m using Axon 2.3.

You could extend org.axonframework.commandhandling.CommandHandlerInterceptor and translate any exception to a specific exception known on the Command Gateway. You can then add the interceptor to your CommandBus config.


you can also register a command callback on the CommandGateway, which is invoked for each command sent through that gateway.

Regarding the subscriptions at startup, how do you configure your application? Do you use a dependency injection framework (e.g. Spring)?



Yes I do use Spring for DI.

I will take some time to see how to use a command callback on the CommandGateway as you suggest.