Showing results for 
Search instead for 
Did you mean: 

Integration testing involving rabbitmq

I need help on how to write integration testing involving the rabbitMQ message broker.

This is the overall system architecture

Service(Producer) --> Message Borker(Environment 1) --> Controllers(Our Application) --> Message Broker(Environment 2) --> Consumer Devices

I am planning to place my integration testing programs at the service level wherein I will mimic a message to be sent to a Message broker. Later I will listen for the response and assert it.

Though its an asynchronous system, testing synchronous way seems to be an easy approach.

Is there any better approach to do the integration testing for my application flow. Could you please give me pointers for integration testing.


TestContainers may be helpful /omegleshagle but you will nee docker. 

IMO it pretty much depends on what exactly do you want to test. In general, you application consumer should have some method like "onMessage" that gets the message and this is an entry point of the consumer that triggers your business flows.

If so, assuming this entry point is implemented as a bean you can inject it into the test class and call it directly effectively bypassing all the rabbitmq integration layer.

One small caveat with this approach is that you'll have to exclude all rabbit mq related beans from loaded in the test context.

Now this approach will let you test a single service's business logic, which is good.

It however falls short when you want to test:

  • Message protocol (that the messages passing over wire are correct indeed)
  • Integration (when the producer that sends the message to some exchange, the consumer actually gets the message)
  • Non functional tests (like load tests to make sure that consumer doesn't get overwhelmed under load)