Package org.apache.pulsar.client.impl.v1
Class ConsumerV1Impl
java.lang.Object
org.apache.pulsar.client.impl.v1.ConsumerV1Impl
- All Implemented Interfaces:
Closeable,AutoCloseable,Consumer
-
Constructor Summary
ConstructorsConstructorDescriptionConsumerV1Impl(org.apache.pulsar.shade.client.api.v2.Consumer<byte[]> consumer) -
Method Summary
Modifier and TypeMethodDescriptionvoidacknowledge(org.apache.pulsar.client.api.Message<?> arg0) Acknowledge the consumption of a single message.voidacknowledge(org.apache.pulsar.client.api.MessageId arg0) Acknowledge the consumption of a single message, identified by its MessageId.acknowledgeAsync(org.apache.pulsar.client.api.Message<?> arg0) Asynchronously acknowledge the consumption of a single message.acknowledgeAsync(org.apache.pulsar.client.api.MessageId arg0) Asynchronously acknowledge the consumption of a single message.voidacknowledgeCumulative(org.apache.pulsar.client.api.Message<?> arg0) Acknowledge the reception of all the messages in the stream up to (and including) the provided message.voidacknowledgeCumulative(org.apache.pulsar.client.api.MessageId arg0) Acknowledge the reception of all the messages in the stream up to (and including) the provided message.acknowledgeCumulativeAsync(org.apache.pulsar.client.api.Message<?> arg0) Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided message.acknowledgeCumulativeAsync(org.apache.pulsar.client.api.MessageId arg0) Asynchronously Acknowledge the reception of all the messages in the stream up to (and including) the provided message.voidclose()Close the consumer and stop the broker to push more messages.Asynchronously close the consumer and stop the broker to push more messages.Get the name of consumer.org.apache.pulsar.client.api.MessageIdCompletableFuture<org.apache.pulsar.client.api.MessageId>org.apache.pulsar.client.api.ConsumerStatsgetStats()Get statistics for the consumer.Get a subscription for the consumer.getTopic()Get a topic for the consumer.booleanReturn true if the topic was terminated and this consumer has already consumed all the messages in the topic.booleanvoidpause()Stop requesting new messages from the broker untilConsumer.resume()is called.org.apache.pulsar.client.api.Message<byte[]>receive()Receives a single message.org.apache.pulsar.client.api.Message<byte[]>Receive a single messageCompletableFuture<org.apache.pulsar.client.api.Message<byte[]>>Receive a single messagevoidRedelivers all the unacknowledged messages.voidresume()Resume requesting messages from the broker.voidseek(long arg0) Reset the subscription associated with this consumer to a specific message publish time.voidvoidseek(org.apache.pulsar.client.api.MessageId arg0) Reset the subscription associated with this consumer to a specific message id.seekAsync(long arg0) Reset the subscription associated with this consumer to a specific message publish time.seekAsync(org.apache.pulsar.client.api.MessageId arg0) Reset the subscription associated with this consumer to a specific message id.voidUnsubscribe the consumerAsynchronously unsubscribe the 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:ConsumerAcknowledge the consumption of a single message.- Specified by:
acknowledgein interfaceConsumer- Parameters:
arg0- TheMessageto be acknowledged- Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.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:ConsumerAcknowledge the consumption of a single message, identified by its MessageId.- Specified by:
acknowledgein interfaceConsumer- Parameters:
arg0- TheMessageIdto be acknowledged- Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.apache.pulsar.client.api.PulsarClientException
-
acknowledgeAsync
Description copied from interface:ConsumerAsynchronously acknowledge the consumption of a single message.- Specified by:
acknowledgeAsyncin interfaceConsumer- Parameters:
arg0- TheMessageto be acknowledged- Returns:
- a future that can be used to track the completion of the operation
-
acknowledgeAsync
Description copied from interface:ConsumerAsynchronously acknowledge the consumption of a single message.- Specified by:
acknowledgeAsyncin interfaceConsumer- Parameters:
arg0- TheMessageIdto 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:ConsumerAcknowledge 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:
acknowledgeCumulativein interfaceConsumer- Parameters:
arg0- TheMessageto be cumulatively acknowledged- Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.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:ConsumerAcknowledge 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:
acknowledgeCumulativein interfaceConsumer- Parameters:
arg0- TheMessageIdto be cumulatively acknowledged- Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.apache.pulsar.client.api.PulsarClientException
-
acknowledgeCumulativeAsync
public CompletableFuture<Void> acknowledgeCumulativeAsync(org.apache.pulsar.client.api.Message<?> arg0) Description copied from interface:ConsumerAsynchronously 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:
acknowledgeCumulativeAsyncin interfaceConsumer- Parameters:
arg0- TheMessageto 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:ConsumerAsynchronously 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:
acknowledgeCumulativeAsyncin interfaceConsumer- Parameters:
arg0- TheMessageIdto 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.PulsarClientExceptionDescription copied from interface:ConsumerClose the consumer and stop the broker to push more messages. -
closeAsync
Description copied from interface:ConsumerAsynchronously close the consumer and stop the broker to push more messages.- Specified by:
closeAsyncin interfaceConsumer- Returns:
- a future that can be used to track the completion of the operation
-
getConsumerName
Description copied from interface:ConsumerGet the name of consumer.- Specified by:
getConsumerNamein interfaceConsumer- Returns:
- consumer name.
-
getStats
public org.apache.pulsar.client.api.ConsumerStats getStats()Description copied from interface:ConsumerGet 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
-
getSubscription
Description copied from interface:ConsumerGet a subscription for the consumer.- Specified by:
getSubscriptionin interfaceConsumer- Returns:
- subscription for the consumer
-
getTopic
Description copied from interface:ConsumerGet a topic for the consumer. -
hasReachedEndOfTopic
public boolean hasReachedEndOfTopic()Description copied from interface:ConsumerReturn 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:
hasReachedEndOfTopicin interfaceConsumer
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceConsumer- Returns:
- Whether the consumer is connected to the broker
-
pause
public void pause()Description copied from interface:ConsumerStop requesting new messages from the broker untilConsumer.resume()is called. Note that this might causeConsumer.receive()to block untilConsumer.resume()is called and new messages are pushed by the broker. -
receive
public org.apache.pulsar.client.api.Message<byte[]> receive() throws org.apache.pulsar.client.api.PulsarClientExceptionDescription copied from interface:ConsumerReceives a single message.This calls blocks until a message is available.
- Specified by:
receivein interfaceConsumer- Returns:
- the received message
- Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.apache.pulsar.client.api.PulsarClientException.InvalidConfigurationException- if a message listener was defined in the configurationorg.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:ConsumerReceive a single messageRetrieves a message, waiting up to the specified wait time if necessary.
- Specified by:
receivein interfaceConsumer- Parameters:
arg0- 0 or less means immediate rather than infinite- Returns:
- the received
Messageor null if no message available before timeout - Throws:
org.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the consumer was already closedorg.apache.pulsar.client.api.PulsarClientException.InvalidConfigurationException- if a message listener was defined in the configurationorg.apache.pulsar.client.api.PulsarClientException
-
receiveAsync
Description copied from interface:ConsumerReceive a single messageRetrieves a message when it will be available and completes
CompletableFuturewith received message.receiveAsync()should be called subsequently once returnedCompletableFuturegets complete with received message. Else it creates backlog of receive requests in the application.- Specified by:
receiveAsyncin interfaceConsumer- Returns:
CompletableFuture<Message> will be completed when message is available
-
redeliverUnacknowledgedMessages
public void redeliverUnacknowledgedMessages()Description copied from interface:ConsumerRedelivers 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:
redeliverUnacknowledgedMessagesin interfaceConsumer
-
resume
public void resume()Description copied from interface:ConsumerResume requesting messages from the broker. -
seek
public void seek(org.apache.pulsar.client.api.MessageId arg0) throws org.apache.pulsar.client.api.PulsarClientException Description copied from interface:ConsumerReset 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 topicMessageId.latest: Reset the subscription on the latest message in the topic
-
seek
public void seek(long arg0) throws org.apache.pulsar.client.api.PulsarClientException Description copied from interface:ConsumerReset 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. -
seek
public void seek(Function<String, Object> function) throws org.apache.pulsar.client.api.PulsarClientException- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
seekAsync
Description copied from interface:ConsumerReset 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. -
seekAsync
Description copied from interface:ConsumerReset 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 topicMessageId.latest: Reset the subscription on the latest message in the topic
-
seekAsync
-
unsubscribe
public void unsubscribe() throws org.apache.pulsar.client.api.PulsarClientExceptionDescription copied from interface:ConsumerUnsubscribe the consumerThis call blocks until the consumer is unsubscribed.
- Specified by:
unsubscribein interfaceConsumer- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
unsubscribeAsync
Description copied from interface:ConsumerAsynchronously unsubscribe the consumer.- Specified by:
unsubscribeAsyncin interfaceConsumer- Returns:
CompletableFuturefor 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
-