Home

Apache Pulsar Module

qianmoQqianmoQ· 更新于 2026-10-13· 阅读 5 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Apache Pulsar Module

Testcontainers can be used to automatically create Apache Pulsar containers without external services.

It's based on the official Apache Pulsar docker image, it is recommended to read the official guide.

Example

Create a PulsarContainer to use it in your tests:

Create a Pulsar container

PulsarContainer pulsar = new PulsarContainer("apachepulsar/pulsar:3.0.0");

Then you can retrieve the broker and the admin url:

Get broker and admin urls

final String pulsarBrokerUrl = pulsar.getPulsarBrokerUrl();
final String httpServiceUrl = pulsar.getHttpServiceUrl();

Options

Configuration

If you need to set Pulsar configuration variables you can use the native APIs and set each variable with PULSAR_PREFIX_ as prefix.

For example, if you want to enable brokerDeduplicationEnabled:

Set configuration variables

PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)
    .withEnv("PULSAR_PREFIX_brokerDeduplicationEnabled", "true");

Pulsar IO

If you need to test Pulsar IO framework you can enable the Pulsar Functions Worker:

Create a Pulsar container with functions worker

PulsarContainer pulsar = new PulsarContainer(DockerImageName.parse("apachepulsar/pulsar:3.0.0"))
    .withFunctionsWorker();

Pulsar Transactions

If you need to test Pulsar Transactions you can enable the transactions feature:

Create a Pulsar container with transactions

PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE).withTransactions();

Adding this module to your project dependencies

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

GradleMaven

testImplementation "org.testcontainers:testcontainers-pulsar:2.0.5"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-pulsar</artifactId>
    <version>2.0.5</version>
    <scope>test</scope>
</dependency>

评论

登录后参与评论

正在加载评论…