Interface QueueConsumer<T>

Type Parameters:
T - the type of message values
All Superinterfaces:
AutoCloseable

public interface QueueConsumer<T> extends AutoCloseable
A consumer for queue (unordered) consumption with broker-managed position tracking.

Messages are distributed to available consumers for parallel processing. Acknowledgment is individual: each message must be acknowledged separately.

This interface provides synchronous (blocking) operations. For non-blocking usage, obtain an AsyncQueueConsumer via async().

This maps to the Shared/Key_Shared subscription model in the Pulsar v4 API.

  • Method Details

    • topic

      String topic()
      The topic this consumer is subscribed to.
      Returns:
      the fully qualified topic name
    • subscription

      String subscription()
      The subscription name.
      Returns:
      the subscription name
    • consumerName

      String consumerName()
      The consumer name (system-assigned or user-specified).
      Returns:
      the consumer name, never null
    • receive

      Message<T> receive() throws PulsarClientException
      Receive a single message, blocking indefinitely.
      Returns:
      the received Message
      Throws:
      PulsarClientException - if the consumer is closed or a connection error occurs
    • receive

      Message<T> receive(Duration timeout) throws PulsarClientException
      Receive a single message, blocking up to the given timeout. Returns null if the timeout elapses without a message.
      Parameters:
      timeout - the maximum time to wait for a message
      Returns:
      the received Message, or null if the timeout elapses
      Throws:
      PulsarClientException - if the consumer is closed or a connection error occurs
    • acknowledge

      void acknowledge(MessageId messageId)
      Acknowledge a single message by its ID.
      Parameters:
      messageId - the ID of the message to acknowledge
    • acknowledge

      void acknowledge(MessageId messageId, Transaction txn)
      Acknowledge within a transaction. The acknowledgment becomes effective when the transaction is committed.
      Parameters:
      messageId - the ID of the message to acknowledge
      txn - the transaction to associate the acknowledgment with
    • negativeAcknowledge

      void negativeAcknowledge(MessageId messageId)
      Signal that the message with this ID could not be processed.
      Parameters:
      messageId - the ID of the message to negatively acknowledge
    • async

      Return the asynchronous view of this consumer.
      Returns:
      the AsyncQueueConsumer counterpart of this consumer
    • close

      void close() throws PulsarClientException
      Close the consumer and release all resources.
      Specified by:
      close in interface AutoCloseable
      Throws:
      PulsarClientException - if an error occurs while closing the consumer