public interface Consumer<T>
extends Closeable
Modifier and Type | Method and Description |
---|---|
void |
acknowledge(Message<?> message)
Acknowledge the consumption of a single message
|
void |
acknowledge(MessageId messageId)
Acknowledge the consumption of a single message, identified by its MessageId
|
CompletableFuture<Void> |
acknowledgeAsync(Message<?> message)
Asynchronously acknowledge the consumption of a single message
|
CompletableFuture<Void> |
acknowledgeAsync(MessageId messageId)
Asynchronously acknowledge the consumption of a single message
|
void |
acknowledgeCumulative(Message<?> message)
Acknowledge the reception of all the messages in the stream up to (and including) the provided message.
|
void |
acknowledgeCumulative(MessageId messageId)
Acknowledge the reception of all the messages in the stream up to (and including) the provided message.
|
CompletableFuture<Void> |
acknowledgeCumulativeAsync(Message<?> message)
Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided
message.
|
CompletableFuture<Void> |
acknowledgeCumulativeAsync(MessageId messageId)
Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided
message.
|
void |
close()
Close the consumer and stop the broker to push more messages.
|
CompletableFuture<Void> |
closeAsync()
Asynchronously close the consumer and stop the broker to push more messages
|
String |
getConsumerName()
Get the name of consumer.
|
ConsumerStats |
getStats()
Get statistics for the consumer.
|
String |
getSubscription()
Get a subscription for the consumer
|
String |
getTopic()
Get a topic for the consumer
|
boolean |
hasReachedEndOfTopic()
Return true if the topic was terminated and this consumer has already consumed all the messages in the topic.
|
boolean |
isConnected() |
void |
pause()
Stop requesting new messages from the broker until
resume() is called. |
Message<T> |
receive()
Receives a single message.
|
Message<T> |
receive(int timeout,
TimeUnit unit)
Receive a single message
|
CompletableFuture<Message<T>> |
receiveAsync()
Receive a single message
|
void |
redeliverUnacknowledgedMessages()
Redelivers all the unacknowledged messages.
|
void |
resume()
Resume requesting messages from the broker.
|
void |
seek(MessageId messageId)
Reset the subscription associated with this consumer to a specific message id.
|
CompletableFuture<Void> |
seekAsync(MessageId messageId)
Reset the subscription associated with this consumer to a specific message id.
|
void |
unsubscribe()
Unsubscribe the consumer
|
CompletableFuture<Void> |
unsubscribeAsync()
Asynchronously unsubscribe the consumer
|
String getTopic()
String getSubscription()
void unsubscribe() throws PulsarClientException
This call blocks until the consumer is unsubscribed.
PulsarClientException
CompletableFuture<Void> unsubscribeAsync()
CompletableFuture
for this operationMessage<T> receive() throws PulsarClientException
This calls blocks until a message is available.
PulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException.InvalidConfigurationException
- if a message listener was defined in the configurationPulsarClientException
CompletableFuture<Message<T>> receiveAsync()
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.
CompletableFuture
<Message
> will be completed when message is availableMessage<T> receive(int timeout, TimeUnit unit) throws PulsarClientException
Retrieves a message, waiting up to the specified wait time if necessary.
timeout
- 0 or less means immediate rather than infiniteunit
- Message
or null if no message available before timeoutPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException.InvalidConfigurationException
- if a message listener was defined in the configurationPulsarClientException
void acknowledge(Message<?> message) throws PulsarClientException
message
- The Message
to be acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
void acknowledge(MessageId messageId) throws PulsarClientException
messageId
- The MessageId
to be acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
void acknowledgeCumulative(Message<?> message) throws PulsarClientException
message
- The Message
to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
void acknowledgeCumulative(MessageId messageId) throws PulsarClientException
messageId
- The MessageId
to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
CompletableFuture<Void> acknowledgeAsync(Message<?> message)
message
- The Message
to be acknowledgedCompletableFuture<Void> acknowledgeAsync(MessageId messageId)
messageId
- The MessageId
to be acknowledgedCompletableFuture<Void> acknowledgeCumulativeAsync(Message<?> message)
message
- The Message
to be cumulatively acknowledgedCompletableFuture<Void> acknowledgeCumulativeAsync(MessageId messageId)
messageId
- The MessageId
to be cumulatively acknowledgedConsumerStats getStats()
void close() throws PulsarClientException
close
in interface AutoCloseable
close
in interface Closeable
PulsarClientException
CompletableFuture<Void> closeAsync()
boolean hasReachedEndOfTopic()
void redeliverUnacknowledgedMessages()
void seek(MessageId messageId) throws PulsarClientException
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
messageId
- the message id where to reposition the subscriptionPulsarClientException
CompletableFuture<Void> seekAsync(MessageId messageId)
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
messageId
- the message id where to reposition the subscriptionboolean isConnected()
String getConsumerName()
void pause()
void resume()