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, wait
getStats, hasReachedEndOfTopic, isConnected, redeliverUnacknowledgedMessages, seek, seekAsync
protected 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
Consumer
This 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 configurationPulsarClientException
public 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
PulsarClientException
protected abstract CompletableFuture<Message<T>> internalReceiveAsync()
public Message<T> receive(int timeout, TimeUnit unit) throws PulsarClientException
Consumer
Retrieves 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 configurationPulsarClientException
protected abstract Message<T> internalReceive(int timeout, TimeUnit unit) throws PulsarClientException
PulsarClientException
public void acknowledge(Message<?> message) throws PulsarClientException
Consumer
acknowledge
in interface Consumer<T>
message
- The Message
to be acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
public void acknowledge(MessageId messageId) throws PulsarClientException
Consumer
acknowledge
in interface Consumer<T>
messageId
- The MessageId
to be acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
public void acknowledgeCumulative(Message<?> message) throws PulsarClientException
Consumer
acknowledgeCumulative
in interface Consumer<T>
message
- The Message
to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
public void acknowledgeCumulative(MessageId messageId) throws PulsarClientException
Consumer
acknowledgeCumulative
in interface Consumer<T>
messageId
- The MessageId
to be cumulatively acknowledgedPulsarClientException.AlreadyClosedException
- if the consumer was already closedPulsarClientException
public CompletableFuture<Void> acknowledgeAsync(Message<?> message)
Consumer
acknowledgeAsync
in interface Consumer<T>
message
- The Message
to be acknowledgedpublic CompletableFuture<Void> acknowledgeCumulativeAsync(Message<?> message)
Consumer
acknowledgeCumulativeAsync
in interface Consumer<T>
message
- The Message
to be cumulatively acknowledgedpublic CompletableFuture<Void> acknowledgeAsync(MessageId messageId)
Consumer
acknowledgeAsync
in interface Consumer<T>
messageId
- The MessageId
to be acknowledgedpublic CompletableFuture<Void> acknowledgeCumulativeAsync(MessageId messageId)
Consumer
acknowledgeCumulativeAsync
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
Consumer
This call blocks until the consumer is unsubscribed.
unsubscribe
in interface Consumer<T>
PulsarClientException
public abstract CompletableFuture<Void> unsubscribeAsync()
Consumer
unsubscribeAsync
in interface Consumer<T>
CompletableFuture
for this operationpublic void close() throws PulsarClientException
Consumer
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Consumer<T>
PulsarClientException
public abstract CompletableFuture<Void> closeAsync()
Consumer
closeAsync
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()
Consumer
public String getSubscription()
Consumer
getSubscription
in interface Consumer<T>
public String getConsumerName()
Consumer
getConsumerName
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.