Package org.apache.pulsar.client.impl
Class ConsumerImpl<T>
java.lang.Object
org.apache.pulsar.client.impl.ConsumerBase<T>
org.apache.pulsar.client.impl.ConsumerImpl<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,Consumer<T>,MessageAcknowledger
- Direct Known Subclasses:
ZeroQueueConsumerImpl
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.pulsar.client.impl.ConsumerBase
ConsumerBase.OpBatchReceive<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConcurrentOpenHashMap<String,org.apache.pulsar.client.impl.ConsumerImpl.ChunkedMessageCtx> protected final PulsarClientImplprotected longprotected MessageIdprotected booleanprotected URIprotected final ConsumerStatsRecorderprotected final StringFields inherited from class org.apache.pulsar.client.impl.ConsumerBase
batchReceivePolicy, batchReceiveTimeout, conf, CONSUMER_EPOCH, consumerEpoch, consumerEventListener, consumerName, CURRENT_RECEIVER_QUEUE_SIZE_UPDATER, executorProvider, externalPinnedExecutor, incomingMessagesSize, incomingQueueLock, INITIAL_RECEIVER_QUEUE_SIZE, interceptors, internalPinnedExecutor, listener, maxReceiverQueueSize, MEMORY_THRESHOLD_FOR_RECEIVER_QUEUE_SIZE_EXPANSION, pendingBatchReceives, pendingReceives, scaleReceiverQueueHint, schema, subscribeFuture, subscription, unAckedChunkedMessageIdSequenceMap, unAckedMessageTracker -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConsumerImpl(PulsarClientImpl client, String topic, ConsumerConfigurationData<T> conf, ExecutorProvider executorProvider, int partitionIndex, boolean hasParentConsumer, boolean parentConsumerHasListener, CompletableFuture<Consumer<T>> subscribeFuture, MessageId startMessageId, long startMessageRollbackDurationInSec, Schema<T> schema, ConsumerInterceptors<T> interceptors, boolean createTopicIfDoesNotExist) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected booleanprotected booleanprotected voidvoidconnectionFailed(PulsarClientException exception) voidprotected voidconsumerIsReconnectedToBroker(ClientCnx cnx, int currentQueueSize) protected CompletableFuture<Void>doAcknowledge(List<MessageId> messageIdList, CommandAck.AckType ackType, Map<String, Long> properties, TransactionImpl txn) protected CompletableFuture<Void>doAcknowledge(MessageId messageId, CommandAck.AckType ackType, Map<String, Long> properties, TransactionImpl txn) protected CompletableFuture<Void>doReconsumeLater(Message<?> message, CommandAck.AckType ackType, Map<String, String> customProperties, long delayTime, TimeUnit unit) booleanprotected org.apache.pulsar.client.impl.HandlerState.StategetAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) intlongDeprecated.protected org.apache.pulsar.client.impl.HandlerState.StategetState()getStats()Deprecated.inthashCode()booleanbooleanvoidincreaseAvailablePermits(int delta) protected voidincreaseAvailablePermits(ClientCnx currentCnx, int delta) protected CompletableFuture<Messages<T>>CompletableFuture<org.apache.pulsar.client.impl.ConsumerImpl.GetLastMessageIdResponse>internalReceive(long timeout, TimeUnit unit) protected CompletableFuture<Message<T>>protected booleanisBatch(MessageMetadata messageMetadata) booleanbooleanisConnected(ClientCnx cnx) protected voidmessageProcessed(Message<?> msg) Record the event that one message has been processed by the application.intvoidnegativeAcknowledge(Message<?> message) voidnegativeAcknowledge(MessageId messageId) protected <V> MessageImpl<V>newMessage(MessageIdImpl messageId, BrokerEntryMetadata brokerEntryMetadata, MessageMetadata messageMetadata, io.netty.buffer.ByteBuf payload, Schema<V> schema, int redeliveryCount, long consumerEpoch) protected <V> MessageImpl<V>newSingleMessage(int index, int numMessages, BrokerEntryMetadata brokerEntryMetadata, MessageMetadata msgMetadata, SingleMessageMetadata singleMessageMetadata, io.netty.buffer.ByteBuf payload, MessageIdImpl messageId, Schema<V> schema, boolean containMetadata, BitSetRecyclable ackBitSet, BitSet ackSetInMessageId, int redeliveryCount, long consumerEpoch) intvoidpause()voidvoidredeliverUnacknowledgedMessages(Set<MessageId> messageIds) Redelivers the given unacknowledged messages.protected voidvoidresume()voidseek(long timestamp) voidvoidseekAsync(long timestamp) protected voidsetCurrentReceiverQueueSize(int newSize) Update the size of the consumer receive queue.protected voidsetRedirectedClusterURI(String serviceUrl, String serviceUrlTls) protected voidsetState(org.apache.pulsar.client.impl.HandlerState.State s) protected voidtrackMessage(Message<?> msg) protected voidtrackMessage(MessageId messageId) protected voidtrackMessage(MessageId messageId, int redeliveryCount) protected voidMethods inherited from class org.apache.pulsar.client.impl.ConsumerBase
acknowledge, acknowledge, acknowledge, acknowledge, acknowledgeAsync, acknowledgeAsync, acknowledgeAsync, acknowledgeAsync, acknowledgeAsync, acknowledgeAsync, acknowledgeAsync, acknowledgeCumulative, acknowledgeCumulative, acknowledgeCumulativeAsync, acknowledgeCumulativeAsync, acknowledgeCumulativeAsync, batchReceive, batchReceiveAsync, beforeConsume, callMessageListener, canEnqueueMessage, clearIncomingMessages, close, completePendingBatchReceive, completePendingReceive, decreaseIncomingMessageSize, doAcknowledgeWithTxn, doAcknowledgeWithTxn, enqueueMessageAndCheckBatchReceive, expectMoreIncomingMessages, failPendingReceive, getConsumerName, getCurrentReceiverQueueSize, getIncomingMessageSize, getLastMessageId, getLastMessageIds, getNewMessagesImpl, getSubscription, getSubType, getTopic, getTotalIncomingMessages, hasBatchReceiveTimeout, hasEnoughMessagesForBatchReceive, hasNextPendingReceive, hasPendingBatchReceive, initReceiverQueueSize, isValidConsumerEpoch, negativeAcknowledge, nextPendingReceive, notifyPendingBatchReceivedCallBack, notifyPendingBatchReceivedCallBack, onAcknowledge, onAcknowledge, onAcknowledgeCumulative, onAcknowledgeCumulative, onAckTimeoutSend, onNegativeAcksSend, onPartitionsChange, peekMessageKey, receive, receive, receiveAsync, reconsumeLater, reconsumeLater, reconsumeLater, reconsumeLaterAsync, reconsumeLaterAsync, reconsumeLaterAsync, reconsumeLaterCumulative, reconsumeLaterCumulativeAsync, reconsumeLaterCumulativeAsync, reduceCurrentReceiverQueueSize, resetIncomingMessageSize, subscribeFuture, toString, trackUnAckedMsgIfNoListener, triggerBatchReceiveTimeoutTask, tryTriggerListener, unsubscribe
-
Field Details
-
lastDequeuedMessageId
-
stats
-
paused
protected volatile boolean paused -
chunkedMessagesMap
protected ConcurrentOpenHashMap<String,org.apache.pulsar.client.impl.ConsumerImpl.ChunkedMessageCtx> chunkedMessagesMap -
expireTimeOfIncompleteChunkedMessageMillis
protected long expireTimeOfIncompleteChunkedMessageMillis -
client
-
topic
-
redirectedClusterURI
-
-
Constructor Details
-
ConsumerImpl
protected ConsumerImpl(PulsarClientImpl client, String topic, ConsumerConfigurationData<T> conf, ExecutorProvider executorProvider, int partitionIndex, boolean hasParentConsumer, boolean parentConsumerHasListener, CompletableFuture<Consumer<T>> subscribeFuture, MessageId startMessageId, long startMessageRollbackDurationInSec, Schema<T> schema, ConsumerInterceptors<T> interceptors, boolean createTopicIfDoesNotExist)
-
-
Method Details
-
getConnectionHandler
-
getUnAckedMessageTracker
-
unsubscribeAsync
- Specified by:
unsubscribeAsyncin interfaceConsumer<T>- Specified by:
unsubscribeAsyncin classConsumerBase<T>
-
minReceiverQueueSize
public int minReceiverQueueSize()- Specified by:
minReceiverQueueSizein classConsumerBase<T>
-
internalReceive
- Specified by:
internalReceivein classConsumerBase<T>- Throws:
PulsarClientException
-
internalReceiveAsync
- Specified by:
internalReceiveAsyncin classConsumerBase<T>
-
internalReceive
- Specified by:
internalReceivein classConsumerBase<T>- Throws:
PulsarClientException
-
internalBatchReceive
- Specified by:
internalBatchReceivein classConsumerBase<T>- Throws:
PulsarClientException
-
internalBatchReceiveAsync
- Specified by:
internalBatchReceiveAsyncin classConsumerBase<T>
-
doAcknowledge
protected CompletableFuture<Void> doAcknowledge(MessageId messageId, CommandAck.AckType ackType, Map<String, Long> properties, TransactionImpl txn) - Specified by:
doAcknowledgein classConsumerBase<T>
-
doAcknowledge
protected CompletableFuture<Void> doAcknowledge(List<MessageId> messageIdList, CommandAck.AckType ackType, Map<String, Long> properties, TransactionImpl txn) - Specified by:
doAcknowledgein classConsumerBase<T>
-
doReconsumeLater
protected CompletableFuture<Void> doReconsumeLater(Message<?> message, CommandAck.AckType ackType, Map<String, String> customProperties, long delayTime, TimeUnit unit) - Specified by:
doReconsumeLaterin classConsumerBase<T>
-
negativeAcknowledge
- Specified by:
negativeAcknowledgein interfaceConsumer<T>
-
negativeAcknowledge
- Specified by:
negativeAcknowledgein interfaceConsumer<T>- Overrides:
negativeAcknowledgein classConsumerBase<T>
-
connectionOpened
-
consumerIsReconnectedToBroker
-
connectionFailed
-
closeAsync
- Specified by:
closeAsyncin interfaceConsumer<T>- Specified by:
closeAsyncin classConsumerBase<T>
-
isBatch
-
newSingleMessage
protected <V> MessageImpl<V> newSingleMessage(int index, int numMessages, BrokerEntryMetadata brokerEntryMetadata, MessageMetadata msgMetadata, SingleMessageMetadata singleMessageMetadata, io.netty.buffer.ByteBuf payload, MessageIdImpl messageId, Schema<V> schema, boolean containMetadata, BitSetRecyclable ackBitSet, BitSet ackSetInMessageId, int redeliveryCount, long consumerEpoch) -
newMessage
protected <V> MessageImpl<V> newMessage(MessageIdImpl messageId, BrokerEntryMetadata brokerEntryMetadata, MessageMetadata messageMetadata, io.netty.buffer.ByteBuf payload, Schema<V> schema, int redeliveryCount, long consumerEpoch) -
messageProcessed
Record the event that one message has been processed by the application. Periodically, it sends a Flow command to notify the broker that it can push more messages- Specified by:
messageProcessedin classConsumerBase<T>
-
trackMessage
-
trackMessage
-
trackMessage
-
increaseAvailablePermits
-
increaseAvailablePermits
public void increaseAvailablePermits(int delta) -
setCurrentReceiverQueueSize
protected void setCurrentReceiverQueueSize(int newSize) Description copied from class:ConsumerBaseUpdate the size of the consumer receive queue. SeeConsumerBuilder.receiverQueueSize(int).- Specified by:
setCurrentReceiverQueueSizein classConsumerBase<T>- Parameters:
newSize- new size of the receiver queue.
-
pause
public void pause() -
resume
public void resume() -
getLastDisconnectedTimestamp
public long getLastDisconnectedTimestamp()- Specified by:
getLastDisconnectedTimestampin interfaceConsumer<T>
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceConsumer<T>
-
isConnected
-
getAvailablePermits
public int getAvailablePermits()- Specified by:
getAvailablePermitsin classConsumerBase<T>
-
numMessagesInQueue
public int numMessagesInQueue()- Specified by:
numMessagesInQueuein classConsumerBase<T>
-
redeliverUnacknowledgedMessages
public void redeliverUnacknowledgedMessages()- Specified by:
redeliverUnacknowledgedMessagesin interfaceConsumer<T>
-
redeliverUnacknowledgedMessages
Description copied from class:ConsumerBaseRedelivers the given 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 classConsumerBase<T>
-
updateAutoScaleReceiverQueueHint
protected void updateAutoScaleReceiverQueueHint()- Specified by:
updateAutoScaleReceiverQueueHintin classConsumerBase<T>
-
completeOpBatchReceive
- Specified by:
completeOpBatchReceivein classConsumerBase<T>
-
seek
- Specified by:
seekin interfaceConsumer<T>- Throws:
PulsarClientException
-
seek
- Specified by:
seekin interfaceConsumer<T>- Throws:
PulsarClientException
-
seek
- Specified by:
seekin interfaceConsumer<T>- Throws:
PulsarClientException
-
seekAsync
-
seekAsync
-
seekAsync
-
hasMessageAvailable
- Throws:
PulsarClientException
-
hasMessageAvailableAsync
-
getLastMessageIdAsync
Deprecated.- Specified by:
getLastMessageIdAsyncin interfaceConsumer<T>- Specified by:
getLastMessageIdAsyncin classConsumerBase<T>
-
getLastMessageIdsAsync
- Specified by:
getLastMessageIdsAsyncin interfaceConsumer<T>
-
internalGetLastMessageIdAsync
public CompletableFuture<org.apache.pulsar.client.impl.ConsumerImpl.GetLastMessageIdResponse> internalGetLastMessageIdAsync() -
getStats
-
hasReachedEndOfTopic
public boolean hasReachedEndOfTopic()- Specified by:
hasReachedEndOfTopicin interfaceConsumer<T>
-
hashCode
public int hashCode() -
equals
-
getClientCnx
-
getTopicNameWithoutPartition
Deprecated. -
removeExpireIncompleteChunkedMessages
protected void removeExpireIncompleteChunkedMessages() -
getPossibleSendToDeadLetterTopicMessages
-
setRedirectedClusterURI
protected void setRedirectedClusterURI(String serviceUrl, String serviceUrlTls) throws URISyntaxException - Throws:
URISyntaxException
-
changeToReadyState
protected boolean changeToReadyState() -
changeToRegisteringSchemaState
protected boolean changeToRegisteringSchemaState() -
getState
protected org.apache.pulsar.client.impl.HandlerState.State getState() -
changeToConnecting
protected boolean changeToConnecting() -
setState
protected void setState(org.apache.pulsar.client.impl.HandlerState.State s) -
getAndUpdateState
protected org.apache.pulsar.client.impl.HandlerState.State getAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) -
getClient
-