Package org.apache.pulsar.client.api.v5
Interface QueueConsumer<T>
- Type Parameters:
T- the type of message values
- All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptionvoidacknowledge(MessageId messageId) Acknowledge a single message by its ID.voidacknowledge(MessageId messageId, Transaction txn) Acknowledge within a transaction.async()Return the asynchronous view of this consumer.voidclose()Close the consumer and release all resources.The consumer name (system-assigned or user-specified).voidnegativeAcknowledge(MessageId messageId) Signal that the message with this ID could not be processed.receive()Receive a single message, blocking indefinitely.Receive a single message, blocking up to the given timeout.The subscription name.topic()The topic this consumer is subscribed to.
-
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
Receive a single message, blocking indefinitely.- Returns:
- the received
Message - Throws:
PulsarClientException- if the consumer is closed or a connection error occurs
-
receive
Receive a single message, blocking up to the given timeout. Returnsnullif the timeout elapses without a message.- Parameters:
timeout- the maximum time to wait for a message- Returns:
- the received
Message, ornullif the timeout elapses - Throws:
PulsarClientException- if the consumer is closed or a connection error occurs
-
acknowledge
Acknowledge a single message by its ID.- Parameters:
messageId- the ID of the message to acknowledge
-
acknowledge
Acknowledge within a transaction. The acknowledgment becomes effective when the transaction is committed.- Parameters:
messageId- the ID of the message to acknowledgetxn- the transaction to associate the acknowledgment with
-
negativeAcknowledge
Signal that the message with this ID could not be processed.- Parameters:
messageId- the ID of the message to negatively acknowledge
-
async
AsyncQueueConsumer<T> async()Return the asynchronous view of this consumer.- Returns:
- the
AsyncQueueConsumercounterpart of this consumer
-
close
Close the consumer and release all resources.- Specified by:
closein interfaceAutoCloseable- Throws:
PulsarClientException- if an error occurs while closing the consumer
-