Georg Muehlenberg
Georg Muehlenberg

Reputation: 565

How to empty all Queues in a RabbitMQ Testcontainer with Java?

How to empty all Queues for a RabbitMQ Testcontainer in Java?

Scenario

We're in an Integration Test scenario where we hand around a reusable RabbitMQ Testcontainer. Between test runs, we want to clear the container.

Techstack

What we got so far

Purging a single Queue is easy with spring-amqp. Managing all queues via command line is feasible. But RabbitMQ will retain the unacked messages on purging. This could of course pollute the next test run, so we need to clear those unacked messages too.

What we need to do

We need to find the open channels, close them to nack the messages and then purge the queue. Every queue. Has anyone a bash script for it? Or is there a simple solution, like clearing the Testcontainer itself in Java with a single call?

Upvotes: 0

Views: 46

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

See if RabbitMQ Management API does the trick for you: https://docs.spring.io/spring-amqp/reference/amqp/management-rest-api.html.

So, you would need to use this Testcontainers configuration then:

RabbitMQContainer RABBITMQ = new RabbitMQContainer("rabbitmq:management")
        .withExposedPorts(5672, 15672)
        .withStartupTimeout(Duration.ofMinutes(2));

Upvotes: 0

Related Questions