Skip to main content

Pulsar Java client

You can use a Pulsar Java client to create Pulsar producers, consumers, and readers in Java and perform administrative tasks. All the methods in Java clients are thread-safe. The current Java client LTS version is 4.0.11 and the latest version is 4.2.2.

Java client SDKs

Pulsar provides two Java client SDKs:

Current SDKV5 SDK
Packageorg.apache.pulsar.client.apiorg.apache.pulsar.client.api.v5
Maven artifactpulsar-clientpulsar-client-v5
TopicsPartitioned and non-partitionedScalable topics (and existing topics)
ConsumptionExclusive / Failover / Shared / Key_Shared subscriptionsStream / Queue / Checkpoint consumers
Minimum Java817

The current SDK is the stable, full-featured client used by most applications. It is documented in the Get started and Advanced use sections below.

The V5 SDK is a newer client purpose-built for scalable topics; it also works against existing topics. See Java client (V5).

Both SDKs are fully supported and can be used side by side in the same application.

Get started

  1. Set up Java client library
  2. Initialize a Java client
  3. Use a Java client
note

Please refer to Java client Performance considerations for more information on how to improve the performance of the Java client and tune the Java JVM options to avoid java.lang.OutOfMemoryError: Direct buffer memory errors in high-throughput applications.

What's next?

Reference doc

API reference

The following table outlines the API packages and reference docs for Pulsar Java clients.

PackageDescriptionMaven Artifact
org.apache.pulsar.client.apiJava client API.
See Client API overview for more reference.
org.apache.pulsar:pulsar-client:4.0.11
org.apache.pulsar.client.adminJava admin API.
See Admin API overview for more reference.
org.apache.pulsar:pulsar-client-admin:4.0.11
org.apache.pulsar.client.allInclude both pulsar-client and pulsar-client-admin.
Both pulsar-client and pulsar-client-admin are independently shaded packages. Consequently, the applications using both pulsar-client and pulsar-client-admin have redundant shaded classes. It would be troublesome if you introduce new dependencies but forget to update shading rules.
In this case, you can use pulsar-client-all, which shades dependencies only one time and reduces the size of dependencies.
org.apache.pulsar:pulsar-client-all:4.0.11

More reference