Customize AMQP routing key for axon events


I have noticed that axon uses the package name of the event to generate the routing key. For e.g

Package : com.application.event.WorkflowStartedEvent has a routing key

Routing Key: com.application.event

This is good but now we want to customize the routing key. Can you let me know how to customize the routing key.

If you’re using Axon 3 and Spring Boot, all you need to do is define a bean that implements RoutingKeyResolver. It gives you a message (an event) and expects you to return the String you want to use as routing key in AMQP.

If you don’t use Spring Boot, it is probably also enough to just define the bean, depending on how you have configured the SpringAMQPPublisher. Otherwise, you might have to explicitly set the RoutingKeyResolver on the SpringAMQPPublisher instance.

Hope this helps.


Yes that worked for me. Thanks

Hi Ajinkya,
Would you mind posting the code of your RoutingKeyResolver implementation?

Best Regards
Harvey Sama

Sure, You have to implement the RoutingKeyResolver and Inject the RoutingKeyResolver bean. This should do the job.



  • Routing key resolver.

Ok. Thanks.