Initialize a Java client

You can instantiate a PulsarClient object using just a URL for the target Pulsar cluster like this:

  1. PulsarClient client = PulsarClient.builder()
  2. .serviceUrl("pulsar://localhost:6650")
  3. .build();

If you have multiple brokers, you can initiate a PulsarClient like this:

  1. PulsarClient client = PulsarClient.builder()
  2. .serviceUrl("pulsar://localhost:6650,localhost:6651,localhost:6652")
  3. .build();

Initialize - 图1note

If you run a cluster in standalone mode, the broker is available at the pulsar://localhost:6650 URL by default.

For detailed client configurations, see the reference doc.