Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 4.08 KB

File metadata and controls

102 lines (72 loc) · 4.08 KB

Redpanda

Testcontainers can be used to automatically instantiate and manage Redpanda containers. More precisely Testcontainers uses the official Docker images for Redpanda

!!! note This module uses features provided in docker.redpanda.com/redpandadata/redpanda.

Example

Create a Redpanda to use it in your tests:

Creating a Redpanda inside_block:constructorWithVersion

Now your tests or any other process running on your machine can get access to running Redpanda broker by using the following bootstrap server location:

Bootstrap Servers inside_block:getBootstrapServers

Redpanda also provides a schema registry implementation. Like the Redpanda broker, you can access by using the following schema registry location:

Schema Registry inside_block:getSchemaRegistryAddress

It is also possible to enable security capabilities of Redpanda by using:

Enable security inside_block:security

Superusers can be created by using:

Register Superuser inside_block:createSuperUser

Below is an example of how to create the AdminClient:

Create Admin Client inside_block:createAdminClient

There are scenarios where additional listeners are needed because the consumer/producer can be another container in the same network or a different process where the port to connect differs from the default exposed port 9092. E.g Toxiproxy.

Register additional listener inside_block:registerListener

Container defined in the same network:

Create kcat container inside_block:createKCatContainer

Client using the new registered listener:

Produce/Consume via new listener inside_block:produceConsumeMessage

The following examples shows how to register a proxy as a new listener in RedpandaContainer:

Use SocatContainer to create the proxy

Create Proxy inside_block:createProxy

Register the listener and advertised listener

Register Listener inside_block:registerListenerAndAdvertisedListener

Client using the new registered listener:

Produce/Consume via new listener inside_block:produceConsumeMessageFromProxy

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

=== "Gradle"

testImplementation "org.testcontainers:testcontainers-redpanda:{{latest_version}}"

=== "Maven"

<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-redpanda</artifactId>
    <version>{{latest_version}}</version>
    <scope>test</scope>
</dependency>