public abstract class ConsumerBase<T> extends Object implements Consumer<T>
| Modifier and Type | Field and Description |
|---|---|
protected PulsarClientImpl |
client |
protected ConsumerConfigurationData<T> |
conf |
protected ConsumerEventListener |
consumerEventListener |
protected String |
consumerName |
protected ConsumerInterceptors<T> |
interceptors |
protected MessageListener<T> |
listener |
protected ExecutorService |
listenerExecutor |
protected int |
maxReceiverQueueSize |
protected ConcurrentLinkedQueue<CompletableFuture<Message<T>>> |
pendingReceives |
protected Schema<T> |
schema |
protected CompletableFuture<Consumer<T>> |
subscribeFuture |
protected String |
subscription |
protected String |
topic |
| Modifier | Constructor and Description |
|---|---|
protected |
ConsumerBase(PulsarClientImpl client,
String topic,
ConsumerConfigurationData<T> conf,
int receiverQueueSize,
ExecutorService listenerExecutor,
CompletableFuture<Consumer<T>> subscribeFuture,
Schema<T> schema,
ConsumerInterceptors interceptors) |
| 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.
|
protected Message<T> |
beforeConsume(Message<T> message) |
protected boolean |
changeToReadyState() |
void |
close()
Close the consumer and stop the broker to push more messages.
|
abstract CompletableFuture<Void> |
closeAsync()
Asynchronously close the consumer and stop the broker to push more messages
|
protected abstract CompletableFuture<Void> |
doAcknowledge(MessageId messageId,
PulsarApi.CommandAck.AckType ackType,
Map<String,Long> properties) |
protected org.apache.pulsar.client.impl.HandlerState.State |
getAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) |
abstract int |
getAvailablePermits() |
PulsarClientImpl |
getClient() |
String |
getConsumerName()
Get the name of consumer.
|
protected org.apache.pulsar.client.impl.HandlerState.State |
getState() |
String |
getSubscription()
Get a subscription for the consumer
|
protected PulsarApi.CommandSubscribe.SubType |
getSubType() |
String |
getTopic()
Get a topic for the consumer
|
protected abstract Message<T> |
internalReceive() |
protected abstract Message<T> |
internalReceive(int timeout,
TimeUnit unit) |
protected abstract CompletableFuture<Message<T>> |
internalReceiveAsync() |
abstract int |
numMessagesInQueue() |
protected void |
onAcknowledge(MessageId messageId,
Throwable exception) |
protected void |
onAcknowledgeCumulative(MessageId messageId,
Throwable exception) |
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
|
protected abstract void |
redeliverUnacknowledgedMessages(Set<MessageId> messageIds)
Redelivers the given unacknowledged messages.
|
protected void |
setMaxReceiverQueueSize(int newSize) |
protected void |
setState(org.apache.pulsar.client.impl.HandlerState.State s) |
CompletableFuture<Consumer<T>> |
subscribeFuture() |
String |
toString() |
void |
unsubscribe()
Unsubscribe the consumer
|
abstract CompletableFuture<Void> |
unsubscribeAsync()
Asynchronously unsubscribe the consumer
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetStats, hasReachedEndOfTopic, isConnected, redeliverUnacknowledgedMessages, seek, seekAsyncprotected final String subscription
protected final ConsumerConfigurationData<T> conf
protected final String consumerName
protected final CompletableFuture<Consumer<T>> subscribeFuture
protected final MessageListener<T> listener
protected final ConsumerEventListener consumerEventListener
protected final ExecutorService listenerExecutor
protected final ConcurrentLinkedQueue<CompletableFuture<Message<T>>> pendingReceives
protected int maxReceiverQueueSize
protected final ConsumerInterceptors<T> interceptors
protected final PulsarClientImpl client
protected final String topic
protected ConsumerBase(PulsarClientImpl client, String topic, ConsumerConfigurationData<T> conf, int receiverQueueSize, ExecutorService listenerExecutor, CompletableFuture<Consumer<T>> subscribeFuture, Schema<T> schema, ConsumerInterceptors interceptors)
public Message<T> receive() throws PulsarClientException
ConsumerThis calls blocks until a message is available.
receive in interface Consumer<T>PulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientException.InvalidConfigurationException - if a message listener was defined in the configurationPulsarClientExceptionpublic CompletableFuture<Message<T>> receiveAsync()
Consumer
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.
receiveAsync in interface Consumer<T>CompletableFuture<Message> will be completed when message is availableprotected abstract Message<T> internalReceive() throws PulsarClientException
PulsarClientExceptionprotected abstract CompletableFuture<Message<T>> internalReceiveAsync()
public Message<T> receive(int timeout, TimeUnit unit) throws PulsarClientException
ConsumerRetrieves a message, waiting up to the specified wait time if necessary.
receive in interface Consumer<T>timeout - 0 or less means immediate rather than infiniteMessage or null if no message available before timeoutPulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientException.InvalidConfigurationException - if a message listener was defined in the configurationPulsarClientExceptionprotected abstract Message<T> internalReceive(int timeout, TimeUnit unit) throws PulsarClientException
PulsarClientExceptionpublic void acknowledge(Message<?> message) throws PulsarClientException
Consumeracknowledge in interface Consumer<T>message - The Message to be acknowledgedPulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientExceptionpublic void acknowledge(MessageId messageId) throws PulsarClientException
Consumeracknowledge in interface Consumer<T>messageId - The MessageId to be acknowledgedPulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientExceptionpublic void acknowledgeCumulative(Message<?> message) throws PulsarClientException
ConsumeracknowledgeCumulative in interface Consumer<T>message - The Message to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientExceptionpublic void acknowledgeCumulative(MessageId messageId) throws PulsarClientException
ConsumeracknowledgeCumulative in interface Consumer<T>messageId - The MessageId to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException - if the consumer was already closedPulsarClientExceptionpublic CompletableFuture<Void> acknowledgeAsync(Message<?> message)
ConsumeracknowledgeAsync in interface Consumer<T>message - The Message to be acknowledgedpublic CompletableFuture<Void> acknowledgeCumulativeAsync(Message<?> message)
ConsumeracknowledgeCumulativeAsync in interface Consumer<T>message - The Message to be cumulatively acknowledgedpublic CompletableFuture<Void> acknowledgeAsync(MessageId messageId)
ConsumeracknowledgeAsync in interface Consumer<T>messageId - The MessageId to be acknowledgedpublic CompletableFuture<Void> acknowledgeCumulativeAsync(MessageId messageId)
ConsumeracknowledgeCumulativeAsync in interface Consumer<T>messageId - The MessageId to be cumulatively acknowledgedprotected abstract CompletableFuture<Void> doAcknowledge(MessageId messageId, PulsarApi.CommandAck.AckType ackType, Map<String,Long> properties)
public void unsubscribe()
throws PulsarClientException
ConsumerThis call blocks until the consumer is unsubscribed.
unsubscribe in interface Consumer<T>PulsarClientExceptionpublic abstract CompletableFuture<Void> unsubscribeAsync()
ConsumerunsubscribeAsync in interface Consumer<T>CompletableFuture for this operationpublic void close()
throws PulsarClientException
Consumerclose in interface Closeableclose in interface AutoCloseableclose in interface Consumer<T>PulsarClientExceptionpublic abstract CompletableFuture<Void> closeAsync()
ConsumercloseAsync in interface Consumer<T>protected PulsarApi.CommandSubscribe.SubType getSubType()
public abstract int getAvailablePermits()
public abstract int numMessagesInQueue()
public CompletableFuture<Consumer<T>> subscribeFuture()
public String getTopic()
Consumerpublic String getSubscription()
ConsumergetSubscription in interface Consumer<T>public String getConsumerName()
ConsumergetConsumerName in interface Consumer<T>protected abstract void redeliverUnacknowledgedMessages(Set<MessageId> messageIds)
protected void setMaxReceiverQueueSize(int newSize)
protected void onAcknowledgeCumulative(MessageId messageId, Throwable exception)
protected boolean changeToReadyState()
protected org.apache.pulsar.client.impl.HandlerState.State getState()
protected void setState(org.apache.pulsar.client.impl.HandlerState.State s)
protected org.apache.pulsar.client.impl.HandlerState.State getAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater)
public PulsarClientImpl getClient()
Copyright © 2017–2018 Apache Software Foundation. All rights reserved.