Class ConsumerV1Impl

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

public class ConsumerV1Impl extends Object implements Consumer
  • Constructor Details

    • ConsumerV1Impl

      public ConsumerV1Impl(org.apache.pulsar.shade.client.api.v2.Consumer<byte[]> consumer)
  • Method Details

    • acknowledge

      public void acknowledge(org.apache.pulsar.client.api.Message<?> arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Acknowledge the consumption of a single message.
      Specified by:
      acknowledge in interface Consumer
      Parameters:
      arg0 - The Message to be acknowledged
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException
    • acknowledge

      public void acknowledge(org.apache.pulsar.client.api.MessageId arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Acknowledge the consumption of a single message, identified by its MessageId.
      Specified by:
      acknowledge in interface Consumer
      Parameters:
      arg0 - The MessageId to be acknowledged
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException
    • acknowledgeAsync

      public CompletableFuture<Void> acknowledgeAsync(org.apache.pulsar.client.api.Message<?> arg0)
      Description copied from interface: Consumer
      Asynchronously acknowledge the consumption of a single message.
      Specified by:
      acknowledgeAsync in interface Consumer
      Parameters:
      arg0 - The Message to be acknowledged
      Returns:
      a future that can be used to track the completion of the operation
    • acknowledgeAsync

      public CompletableFuture<Void> acknowledgeAsync(org.apache.pulsar.client.api.MessageId arg0)
      Description copied from interface: Consumer
      Asynchronously acknowledge the consumption of a single message.
      Specified by:
      acknowledgeAsync in interface Consumer
      Parameters:
      arg0 - The MessageId to be acknowledged
      Returns:
      a future that can be used to track the completion of the operation
    • acknowledgeCumulative

      public void acknowledgeCumulative(org.apache.pulsar.client.api.Message<?> arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Acknowledge the reception of all the messages in the stream up to (and including) the provided message. This method will block until the acknowledge has been sent to the broker. After that, the messages will not be re-delivered to this consumer. Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared. It's equivalent to calling asyncAcknowledgeCumulative(Message) and waiting for the callback to be triggered.
      Specified by:
      acknowledgeCumulative in interface Consumer
      Parameters:
      arg0 - The Message to be cumulatively acknowledged
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException
    • acknowledgeCumulative

      public void acknowledgeCumulative(org.apache.pulsar.client.api.MessageId arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Acknowledge the reception of all the messages in the stream up to (and including) the provided message. This method will block until the acknowledge has been sent to the broker. After that, the messages will not be re-delivered to this consumer. Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared. It's equivalent to calling asyncAcknowledgeCumulative(MessageId) and waiting for the callback to be triggered.
      Specified by:
      acknowledgeCumulative in interface Consumer
      Parameters:
      arg0 - The MessageId to be cumulatively acknowledged
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException
    • acknowledgeCumulativeAsync

      public CompletableFuture<Void> acknowledgeCumulativeAsync(org.apache.pulsar.client.api.Message<?> arg0)
      Description copied from interface: Consumer
      Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided message. Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared.
      Specified by:
      acknowledgeCumulativeAsync in interface Consumer
      Parameters:
      arg0 - The Message to be cumulatively acknowledged
      Returns:
      a future that can be used to track the completion of the operation
    • acknowledgeCumulativeAsync

      public CompletableFuture<Void> acknowledgeCumulativeAsync(org.apache.pulsar.client.api.MessageId arg0)
      Description copied from interface: Consumer
      Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided message. Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared.
      Specified by:
      acknowledgeCumulativeAsync in interface Consumer
      Parameters:
      arg0 - The MessageId to be cumulatively acknowledged
      Returns:
      a future that can be used to track the completion of the operation
    • close

      public void close() throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Close the consumer and stop the broker to push more messages.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Consumer
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: Consumer
      Asynchronously close the consumer and stop the broker to push more messages.
      Specified by:
      closeAsync in interface Consumer
      Returns:
      a future that can be used to track the completion of the operation
    • getConsumerName

      public String getConsumerName()
      Description copied from interface: Consumer
      Get the name of consumer.
      Specified by:
      getConsumerName in interface Consumer
      Returns:
      consumer name.
    • getStats

      public org.apache.pulsar.client.api.ConsumerStats getStats()
      Description copied from interface: Consumer
      Get statistics for the consumer.
      • numMsgsReceived : Number of messages received in the current interval
      • numBytesReceived : Number of bytes received in the current interval
      • numReceiveFailed : Number of messages failed to receive in the current interval
      • numAcksSent : Number of acks sent in the current interval
      • numAcksFailed : Number of acks failed to send in the current interval
      • totalMsgsReceived : Total number of messages received
      • totalBytesReceived : Total number of bytes received
      • totalReceiveFailed : Total number of messages failed to receive
      • totalAcksSent : Total number of acks sent
      • totalAcksFailed : Total number of acks failed to sent
      Specified by:
      getStats in interface Consumer
      Returns:
      statistic for the consumer
    • getSubscription

      public String getSubscription()
      Description copied from interface: Consumer
      Get a subscription for the consumer.
      Specified by:
      getSubscription in interface Consumer
      Returns:
      subscription for the consumer
    • getTopic

      public String getTopic()
      Description copied from interface: Consumer
      Get a topic for the consumer.
      Specified by:
      getTopic in interface Consumer
      Returns:
      topic for the consumer
    • hasReachedEndOfTopic

      public boolean hasReachedEndOfTopic()
      Description copied from interface: Consumer
      Return true if the topic was terminated and this consumer has already consumed all the messages in the topic. Please note that this does not simply mean that the consumer is caught up with the last message published by producers, rather the topic needs to be explicitly "terminated".
      Specified by:
      hasReachedEndOfTopic in interface Consumer
    • isConnected

      public boolean isConnected()
      Specified by:
      isConnected in interface Consumer
      Returns:
      Whether the consumer is connected to the broker
    • pause

      public void pause()
      Description copied from interface: Consumer
      Stop requesting new messages from the broker until Consumer.resume() is called. Note that this might cause Consumer.receive() to block until Consumer.resume() is called and new messages are pushed by the broker.
      Specified by:
      pause in interface Consumer
    • receive

      public org.apache.pulsar.client.api.Message<byte[]> receive() throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Receives a single message.

      This calls blocks until a message is available.

      Specified by:
      receive in interface Consumer
      Returns:
      the received message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException.InvalidConfigurationException - if a message listener was defined in the configuration
      org.apache.pulsar.client.api.PulsarClientException
    • receive

      public org.apache.pulsar.client.api.Message<byte[]> receive(int arg0, TimeUnit arg1) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Receive a single message

      Retrieves a message, waiting up to the specified wait time if necessary.

      Specified by:
      receive in interface Consumer
      Parameters:
      arg0 - 0 or less means immediate rather than infinite
      Returns:
      the received Message or null if no message available before timeout
      Throws:
      org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException - if the consumer was already closed
      org.apache.pulsar.client.api.PulsarClientException.InvalidConfigurationException - if a message listener was defined in the configuration
      org.apache.pulsar.client.api.PulsarClientException
    • receiveAsync

      public CompletableFuture<org.apache.pulsar.client.api.Message<byte[]>> receiveAsync()
      Description copied from interface: Consumer
      Receive a single message

      Retrieves a message when it will be available and completes CompletableFuture with received message.

      receiveAsync() should be called subsequently once returned CompletableFuture gets complete with received message. Else it creates backlog of receive requests in the application.

      Specified by:
      receiveAsync in interface Consumer
      Returns:
      CompletableFuture<Message> will be completed when message is available
    • redeliverUnacknowledgedMessages

      public void redeliverUnacknowledgedMessages()
      Description copied from interface: Consumer
      Redelivers all the unacknowledged messages. In Failover mode, the request is ignored if the consumer is not active for the given topic. In Shared mode, the consumers messages to be redelivered are distributed across all the connected consumers. This is a non blocking call and doesn't throw an exception. In case the connection breaks, the messages are redelivered after reconnect.
      Specified by:
      redeliverUnacknowledgedMessages in interface Consumer
    • resume

      public void resume()
      Description copied from interface: Consumer
      Resume requesting messages from the broker.
      Specified by:
      resume in interface Consumer
    • seek

      public void seek(org.apache.pulsar.client.api.MessageId arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Reset the subscription associated with this consumer to a specific message id.

      The message id can either be a specific message or represent the first or last messages in the topic.

      • MessageId.earliest : Reset the subscription on the earliest message available in the topic
      • MessageId.latest : Reset the subscription on the latest message in the topic
      Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
      Specified by:
      seek in interface Consumer
      Parameters:
      arg0 - the message id where to reposition the subscription
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • seek

      public void seek(long arg0) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Reset the subscription associated with this consumer to a specific message publish time. Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
      Specified by:
      seek in interface Consumer
      Parameters:
      arg0 - the message publish time where to reposition the subscription
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • seek

      public void seek(Function<String,Object> function) throws org.apache.pulsar.client.api.PulsarClientException
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • seekAsync

      public CompletableFuture<Void> seekAsync(long arg0)
      Description copied from interface: Consumer
      Reset the subscription associated with this consumer to a specific message publish time. Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
      Specified by:
      seekAsync in interface Consumer
      Parameters:
      arg0 - the message publish time where to reposition the subscription
      Returns:
      a future to track the completion of the seek operation
    • seekAsync

      public CompletableFuture<Void> seekAsync(org.apache.pulsar.client.api.MessageId arg0)
      Description copied from interface: Consumer
      Reset the subscription associated with this consumer to a specific message id.

      The message id can either be a specific message or represent the first or last messages in the topic.

      • MessageId.earliest : Reset the subscription on the earliest message available in the topic
      • MessageId.latest : Reset the subscription on the latest message in the topic
      Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on the individual partitions.
      Specified by:
      seekAsync in interface Consumer
      Parameters:
      arg0 - the message id where to reposition the subscription
      Returns:
      a future to track the completion of the seek operation
    • seekAsync

      public CompletableFuture<Void> seekAsync(Function<String,Object> function)
    • unsubscribe

      public void unsubscribe() throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: Consumer
      Unsubscribe the consumer

      This call blocks until the consumer is unsubscribed.

      Specified by:
      unsubscribe in interface Consumer
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • unsubscribeAsync

      public CompletableFuture<Void> unsubscribeAsync()
      Description copied from interface: Consumer
      Asynchronously unsubscribe the consumer.
      Specified by:
      unsubscribeAsync in interface Consumer
      Returns:
      CompletableFuture for this operation
    • getLastMessageId

      public org.apache.pulsar.client.api.MessageId getLastMessageId() throws org.apache.pulsar.client.api.PulsarClientException
      Throws:
      org.apache.pulsar.client.api.PulsarClientException
    • getLastMessageIdAsync

      public CompletableFuture<org.apache.pulsar.client.api.MessageId> getLastMessageIdAsync()