Class ProducerV1Impl

java.lang.Object
org.apache.pulsar.client.impl.v1.ProducerV1Impl
All Implemented Interfaces:
Closeable, AutoCloseable, Producer

public class ProducerV1Impl extends Object implements Producer
  • Constructor Details

    • ProducerV1Impl

      public ProducerV1Impl(org.apache.pulsar.client.impl.ProducerImpl<byte[]> producer)
  • Method Details

    • close

      public void close() throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Producer
      Close the producer and releases resources allocated. No more writes will be accepted from this producer. Waits until all pending write request are persisted. In case of errors, pending writes will not be retried.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Producer
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: Producer
      Close the producer and releases resources allocated. No more writes will be accepted from this producer. Waits until all pending write request are persisted. In case of errors, pending writes will not be retried.
      Specified by:
      closeAsync in interface Producer
      Returns:
      a future that can used to track when the producer has been closed
    • flush

      public void flush() throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Producer
      Flush all the messages buffered in the client and wait until all messages have been successfully persisted.
      Specified by:
      flush in interface Producer
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
      See Also:
    • flushAsync

      public CompletableFuture<Void> flushAsync()
      Description copied from interface: Producer
      Flush all the messages buffered in the client asynchronously.
      Specified by:
      flushAsync in interface Producer
      Returns:
      a future that can be used to track when all the messages have been safely persisted.
      See Also:
    • getLastSequenceId

      public long getLastSequenceId()
      Description copied from interface: Producer
      Get the last sequence id that was published by this producer.

      This represent either the automatically assigned or custom sequence id (set on the MessageBuilder) that was published and acknowledged by the broker.

      After recreating a producer with the same producer name, this will return the last message that was published in the previous producer session, or -1 if there no message was ever published.

      Specified by:
      getLastSequenceId in interface Producer
      Returns:
      the last sequence id published by this producer
    • getStats

      public org.apache.pulsar.client.api.ProducerStats getStats()
      Description copied from interface: Producer
      Get statistics for the producer.
      • numMsgsSent : Number of messages sent in the current interval
      • numBytesSent : Number of bytes sent in the current interval
      • numSendFailed : Number of messages failed to send in the current interval
      • numAcksReceived : Number of acks received in the current interval
      • totalMsgsSent : Total number of messages sent
      • totalBytesSent : Total number of bytes sent
      • totalSendFailed : Total number of messages failed to send
      • totalAcksReceived: Total number of acks received
      Specified by:
      getStats in interface Producer
      Returns:
      statistic for the producer or null if ProducerStatsRecorderImpl is disabled.
    • isConnected

      public boolean isConnected()
      Specified by:
      isConnected in interface Producer
      Returns:
      Whether the producer is connected to the broker
    • send

      public org.apache.pulsar.client.api.MessageId send(byte[] value) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Producer
      Sends a message.

      This call will be blocking until is successfully acknowledged by the Pulsar broker.

      Use #newMessage() to specify more properties than just the value on the message to be sent.

      Specified by:
      send in interface Producer
      Parameters:
      value - a message
      Returns:
      the message id assigned to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.TimeoutException - if the message was not correctly received by the system within the timeout period
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the producer was already closed
      org.apache.pulsar.client.api.PulsarClientException
    • send

      public org.apache.pulsar.client.api.MessageId send(org.apache.pulsar.client.api.Message<byte[]> value) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Producer
      Send a message.
      Specified by:
      send in interface Producer
      Parameters:
      value - a message
      Returns:
      the message id assigned to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.TimeoutException - if the message was not correctly received by the system within the timeout period
      org.apache.pulsar.client.api.PulsarClientException
    • sendAsync

      public CompletableFuture<org.apache.pulsar.client.api.MessageId> sendAsync(byte[] arg0)
      Description copied from interface: Producer
      Send a message asynchronously

      When the producer queue is full, by default this method will complete the future with an exception PulsarClientException.ProducerQueueIsFullError

      See ProducerBuilder.maxPendingMessages(int) to configure the producer queue size and ProducerBuilder.blockIfQueueFull(boolean) to change the blocking behavior.

      Use #newMessage() to specify more properties than just the value on the message to be sent.

      Specified by:
      sendAsync in interface Producer
      Parameters:
      arg0 - a byte array with the payload of the message
      Returns:
      a future that can be used to track when the message will have been safely persisted
    • sendAsync

      public CompletableFuture<org.apache.pulsar.client.api.MessageId> sendAsync(org.apache.pulsar.client.api.Message<byte[]> arg0)
      Description copied from interface: Producer
      Send a message asynchronously.

      When the returned CompletableFuture is marked as completed successfully, the provided message will contain the MessageId assigned by the broker to the published message.

      Example:

       Message msg = MessageBuilder.create().setContent(myContent).build();
       producer.sendAsync(msg).thenRun(v -> {
          System.out.println("Published message: " + msg.getMessageId());
       }).exceptionally(e -> {
          // Failed to publish
       });
       

      When the producer queue is full, by default this method will complete the future with an exception PulsarClientException.ProducerQueueIsFullError

      See ProducerBuilder.maxPendingMessages(int) to configure the producer queue size and ProducerBuilder.blockIfQueueFull(boolean) to change the blocking behavior.

      Specified by:
      sendAsync in interface Producer
      Parameters:
      arg0 - a message
      Returns:
      a future that can be used to track when the message will have been safely persisted
    • getTopic

      public String getTopic()
      Specified by:
      getTopic in interface Producer
      Returns:
      the topic which producer is publishing to
    • getProducerName

      public String getProducerName()
      Specified by:
      getProducerName in interface Producer
      Returns:
      the producer name which could have been assigned by the system or specified by the client