Testing event handlers in a distributed system

I have a command/query distributed system where i’m using RabbitMQ as a way to send messages from the command to the query. In the query service, I have an application class that registers to receive message from the queue and an event handler (in a separate class) that handles those messages and I was wondering the best way to unit test this code. I know Axon provides testing framework but I didn’t see a way to test having the event handler in a separate projects (distributed system).
Is there a way to mimic sending messages and test if the event handler is handling those message and if it’s doing what it’s suppose to be doing? or should i only be concerned with testing the event handler functionality?

below is my code:


public class IntegrationRunQueryApplication {

   public static void main(String[] args) {
      SpringApplication.run(IntegrationRunQueryApplication .class, args);

    public Serializer axonJsonSerializer() { return new JacksonSerializer();}

    public SpringAMQPMessageSource IntegrationsQueue(Serializer serializer){
        return new SpringAMQPMessageSource(new DefaultAMQPMessageConverter(serializer)){
            @RabbitListener(queues = "Integrations")
            public void onMessage(Message message, Channel channel) throws Exception{
                super.onMessage(message, channel);



public class IntegrationRunListener {
    private IntegrationRunRepository repository;

    public IntegrationRunListener (){}

    public IntegrationRunListener (IntegrationRunRepository repository){
        this.repository = repository;

    public void onRunCreated(IntegrationRunCreatedEvent event){
        repository.save(new IntegrationRunEntity(event.getGuid(), event.getIntegrationId(), event.getPartner(), event.getCategory(), event.getIntegrationRunDate()));




the test fixtures in Axon are meant for testing Aggregates and Sagas. They won’t help you here.
If you want to mimic sending messages to Rabbit, without really doing so, your best option is to invoke the onMessage() method on the SpringAMQPMessageSource bean directly. This will trigger exactly the same mechanism that the rabbit integration (by Spring) would do. As “channel”, you can use a Stub/Mock value. I don’t think Axon uses it anyway. Note that the Message on this method is a Spring Messaging Message, not an Axon one.

Hope this helps.