Interface PulsarClient

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
PulsarClientV1Impl

public interface PulsarClient extends Closeable
Class that provides a client interface to Pulsar.

Client instances are thread-safe and can be reused for managing multiple Producer, Consumer and Reader instances.

  • Method Details

    • create

      @Deprecated static PulsarClient create(String serviceUrl) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      use #builder() to construct a client instance
      Create a new PulsarClient object using default client configuration.
      Parameters:
      serviceUrl - the url of the Pulsar endpoint to be used
      Returns:
      a new pulsar client object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.InvalidServiceURL - if the serviceUrl is invalid
      org.apache.pulsar.client.api.PulsarClientException
    • create

      @Deprecated static PulsarClient create(String serviceUrl, ClientConfiguration conf) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      use #builder() to construct a client instance
      Create a new PulsarClient object.
      Parameters:
      serviceUrl - the url of the Pulsar endpoint to be used
      conf - the client configuration
      Returns:
      a new pulsar client object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.InvalidServiceURL - if the serviceUrl is invalid
      org.apache.pulsar.client.api.PulsarClientException
    • createProducer

      @Deprecated Producer createProducer(String topic) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      use #newProducer() to build a new producer
      Create a producer with default ProducerConfiguration for publishing on a specific topic.
      Parameters:
      topic - The name of the topic where to produce
      Returns:
      The producer object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the client was already closed
      org.apache.pulsar.client.api.PulsarClientException.InvalidTopicNameException - if the topic name is not valid
      org.apache.pulsar.client.api.PulsarClientException.AuthenticationException - if there was an error with the supplied credentials
      org.apache.pulsar.client.api.PulsarClientException.AuthorizationException - if the authorization to publish on topic was denied
      org.apache.pulsar.client.api.PulsarClientException
    • createProducerAsync

      @Deprecated CompletableFuture<Producer> createProducerAsync(String topic)
      Deprecated.
      use #newProducer() to build a new producer
      Asynchronously create a producer with default ProducerConfiguration for publishing on a specific topic.
      Parameters:
      topic - The name of the topic where to produce
      Returns:
      Future of the asynchronously created producer object
    • createProducer

      @Deprecated Producer createProducer(String topic, ProducerConfiguration conf) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      use #newProducer() to build a new producer
      Create a producer with given ProducerConfiguration for publishing on a specific topic.
      Parameters:
      topic - The name of the topic where to produce
      conf - The ProducerConfiguration object
      Returns:
      The producer object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if it was not possible to create the producer
      InterruptedException
    • createProducerAsync

      Deprecated.
      use #newProducer() to build a new producer
      Asynchronously create a producer with given ProducerConfiguration for publishing on a specific topic.
      Parameters:
      topic - The name of the topic where to produce
      conf - The ProducerConfiguration object
      Returns:
      Future of the asynchronously created producer object
    • subscribe

      @Deprecated Consumer subscribe(String topic, String subscription) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      Use #newConsumer() to build a new consumer
      Subscribe to the given topic and subscription combination with default ConsumerConfiguration.
      Parameters:
      topic - The name of the topic
      subscription - The name of the subscription
      Returns:
      The Consumer object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
      InterruptedException
    • subscribeAsync

      @Deprecated CompletableFuture<Consumer> subscribeAsync(String topic, String subscription)
      Deprecated.
      Use #newConsumer() to build a new consumer
      Asynchronously subscribe to the given topic and subscription combination using default. ConsumerConfiguration
      Parameters:
      topic - The topic name
      subscription - The subscription name
      Returns:
      Future of the Consumer object
    • subscribe

      @Deprecated Consumer subscribe(String topic, String subscription, ConsumerConfiguration conf) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      Use #newConsumer() to build a new consumer
      Subscribe to the given topic and subscription combination with given ConsumerConfiguration.
      Parameters:
      topic - The name of the topic
      subscription - The name of the subscription
      conf - The ConsumerConfiguration object
      Returns:
      The Consumer object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • subscribeAsync

      @Deprecated CompletableFuture<Consumer> subscribeAsync(String topic, String subscription, ConsumerConfiguration conf)
      Deprecated.
      Use #newConsumer() to build a new consumer
      Asynchronously subscribe to the given topic and subscription combination using given. ConsumerConfiguration
      Parameters:
      topic - The name of the topic
      subscription - The name of the subscription
      conf - The ConsumerConfiguration object
      Returns:
      Future of the Consumer object
    • createReader

      @Deprecated Reader createReader(String topic, org.apache.pulsar.client.api.MessageId startMessageId, ReaderConfiguration conf) throws org.apache.pulsar.client.api.PulsarClientException
      Deprecated.
      Use #newReader() to build a new reader
      Create a topic reader with given ReaderConfiguration for reading messages from the specified topic.

      The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.

      The initial reader positioning is done by specifying a message id. The options are:

      • MessageId.earliest : Start reading from the earliest message available in the topic
      • MessageId.latest : Start reading from the end topic, only getting messages published after the reader was created
      • MessageId : When passing a particular message id, the reader will position itself on that specific position. The first message to be read will be the message next to the specified messageId.
      Parameters:
      topic - The name of the topic where to read
      startMessageId - The message id where the reader will position itself. The first message returned will be the one after the specified startMessageId
      conf - The ReaderConfiguration object
      Returns:
      The Reader object
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • createReaderAsync

      @Deprecated CompletableFuture<Reader> createReaderAsync(String topic, org.apache.pulsar.client.api.MessageId startMessageId, ReaderConfiguration conf)
      Deprecated.
      Use #newReader() to build a new reader
      Asynchronously create a topic reader with given ReaderConfiguration for reading messages from the specified topic.

      The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.

      The initial reader positioning is done by specifying a message id. The options are:

      • MessageId.earliest : Start reading from the earliest message available in the topic
      • MessageId.latest : Start reading from the end topic, only getting messages published after the reader was created
      • MessageId : When passing a particular message id, the reader will position itself on that specific position. The first message to be read will be the message next to the specified messageId.
      Parameters:
      topic - The name of the topic where to read
      startMessageId - The message id where the reader will position itself. The first message returned will be the one after the specified startMessageId
      conf - The ReaderConfiguration object
      Returns:
      Future of the asynchronously created producer object
    • close

      void close() throws org.apache.pulsar.client.api.PulsarClientException
      Close the PulsarClient and release all the resources. All the producers and consumers will be orderly closed. Waits until all pending write request are persisted.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if the close operation fails
    • closeAsync

      CompletableFuture<Void> closeAsync()
      Asynchronously close the PulsarClient and release all the resources. All the producers and consumers will be orderly closed. Waits until all pending write request are persisted.
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if the close operation fails
    • shutdown

      void shutdown() throws org.apache.pulsar.client.api.PulsarClientException
      Perform immediate shutdown of PulsarClient. Release all the resources and close all the producers without waiting for ongoing operations to complete.
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if the forceful shutdown fails