Set up Java client

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.

Set up - 图1tip

Maven

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

  1. <!-- in your <properties> block -->
  2. <pulsar.version>3.1.1</pulsar.version>
  3. <!-- in your <dependencies> block -->
  4. <dependency>
  5. <groupId>org.apache.pulsar</groupId>
  6. <artifactId>pulsar-client</artifactId>
  7. <version>${pulsar.version}</version>
  8. </dependency>

Gradle

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

  1. def pulsarVersion = '3.1.1'
  2. dependencies {
  3. compile group: 'org.apache.pulsar', name: 'pulsar-client', version: pulsarVersion
  4. }

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:

  1. pulsar://localhost:6650

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

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

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

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