Skip to main content
Version: Next

Set up Java client

To set up Java client in Pulsar, complete the following steps.

Step 1: Install Java client library

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.

tip

Maven

If you use Maven, add the following information to the pom.xml file.

<!-- in your <properties> block -->
<pulsar.version>3.2.3</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 = '3.2.3'

dependencies {
implementation "org.apache.pulsar:pulsar-client:${pulsarVersion}"
}

Pulsar BOM

While the above dependencies are sufficient to obtain the Pulsar Java client, it is recommended to also use the Pulsar BOM to ensure that all Pulsar dependencies (both direct and transitive) are at the same expected version. In order to use the BOM, the previous directions are modified slightly as follows:

Maven

If you use Maven, add the following information to the pom.xml file.

<!-- in your <properties> block -->
<pulsar.version>3.2.3</pulsar.version>

<!-- in your <dependencyManagement>/<dependencies> block -->
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-bom</artifactId>
<version>${pulsar.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- in your <dependencies> block -->
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
</dependency>

Gradle

If you use Gradle, add the following information to the build.gradle file.

def pulsarVersion = '3.2.3'

dependencies {
implementation enforcedPlatform("org.apache.pulsar:pulsar-bom:${pulsarVersion}")
implementation 'org.apache.pulsar:pulsar-client'
}

Note that the version is number for the pulsar-client dependency is now omitted as the Pulsar BOM dictates which version is used.

Step 2: Connect to Pulsar cluster

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 following is an example of localhost with the default port 6650:

pulsar://localhost:6650

If you have multiple brokers, separate IP:port by commas:

pulsar://localhost:6550,localhost:6651,localhost:6652

If you use mTLS authentication, add +ssl in the scheme:

pulsar+ssl://pulsar.us-west.example.com:6651