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.
โ08-04-2022 10:09 PM
TestContainers may be helpful testcontainers.org/modules/rabbitmq /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:
โ08-26-2022 05:18 AM