Testcontainers RabbitMQ Extension with advanced testing capabilities.
Features:
Gradle
testImplementation "io.goodforgod:testcontainers-extensions-rabbitmq:0.14.0"
Maven
<dependency>
<groupId>io.goodforgod</groupId>
<artifactId>testcontainers-extensions-rabbitmq</artifactId>
<version>0.14.0</version>
<scope>test</scope>
</dependency>
RabbitMQ Java client must be on classpath.
Gradle
testImplementation "com.rabbitmq:amqp-client:5.21.0"
@TestcontainersRabbitMQ(mode = ContainerMode.PER_CLASS,
topology = @Topology(
queues = @Queue(name = "orders"),
exchanges = @Exchange(name = "events", type = Exchange.Type.DIRECT),
bindings = @Binding(queue = "orders", exchange = "events", routingKey = "orders.created")))
class ExampleTests {
@ConnectionRabbitMQ
private RabbitMQConnection connection;
@Test
void test() {
var consumer = connection.subscribe("orders");
connection.send("events", "orders.created", Event.ofValue("value1"), Event.ofValue("value2"));
consumer.assertReceivedAtLeast(2, Duration.ofSeconds(5));
}
}
RabbitMQConnection can be injected to a field or method parameter and used to publish messages,
subscribe queues, assert received messages and declare topology.
@TestcontainersRabbitMQ automatically starts RabbitMQ with the specified image in different modes.
It also supports declaring topology before tests run.
Available container modes:
PER_RUNPER_CLASSPER_METHODTopology can be configured directly in annotation:
@TestcontainersRabbitMQ(
topology = @Topology(
queues = @Queue(name = "orders"),
exchanges = @Exchange(name = "events", type = Exchange.Type.DIRECT),
bindings = @Binding(queue = "orders", exchange = "events", routingKey = "orders.created")))
class ExampleTests {}
Topology reset modes:
NONEPER_CLASSPER_METHODIf you want to use an already running RabbitMQ instance, the extension supports:
EXTERNAL_TEST_RABBITMQ_URIEXTERNAL_TEST_RABBITMQ_*Prefix conversion rules: cut prefix, lower-case and replace _ with ..
This project licensed under the Apache License 2.0 - see the LICENSE file for details.