Pulsar Java client
You can use a Pulsar Java client to create the Java producer, consumer, and readers of messages and to perform administrative tasks. The current Java client version is 2.9.5.
All the methods in producer, consumer, and reader of a Java client are thread-safe.
Javadoc for the Pulsar client is divided into two domains by package as follows.
| Package | Description | Maven Artifact | 
|---|---|---|
| org.apache.pulsar.client.api | The producer and consumer API | org.apache.pulsar:pulsar-client:2.9.5 | 
| org.apache.pulsar.client.admin | The Java admin API | org.apache.pulsar:pulsar-client-admin:2.9.5 | 
| org.apache.pulsar.client.all | Include both pulsar-clientandpulsar-client-adminBoth pulsar-clientandpulsar-client-adminare shaded packages and they shade dependencies independently. Consequently, the applications using bothpulsar-clientandpulsar-client-adminhave 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:2.9.5 | 
This document focuses only on the client API for producing and consuming messages on Pulsar topics. For how to use the Java admin client, see Pulsar admin interface.
Installation
The latest version of the Pulsar Java client library is available via Maven Central. To use the latest version, add the pulsar-client library to your build configuration.
Maven
If you use Maven, add the following information to the pom.xml file.
<!-- in your <properties> block -->
<pulsar.version>2.9.5</pulsar.version>
<!-- in your <dependencies> block -->
<dependency>
  <groupId>org.apache.pulsar</groupId>
  <artifactId>pulsar-client</artifactId>
  <version>${pulsar.version}</version>
</dependency>
Gradle
If you use Gradle, add the following information to the build.gradle file.
def pulsarVersion = '2.9.5'
dependencies {
    compile group: 'org.apache.pulsar', name: 'pulsar-client', version: pulsarVersion
}
Connection URLs
To connect to Pulsar using client libraries, you need to specify a Pulsar protocol URL.
You can assign Pulsar protocol URLs to specific clusters and use the pulsar scheme. The default port is 6650. The following is an example of localhost.
pulsar://localhost:6650
If you have multiple brokers, the URL is as follows.
pulsar://localhost:6550,localhost:6651,localhost:6652
A URL for a production Pulsar cluster is as follows.
pulsar://pulsar.us-west.example.com:6650
If you use TLS authentication, the URL is as follows.
pulsar+ssl://pulsar.us-west.example.com:6651