Class ConsumerInterceptors<T>
- java.lang.Object
-
- org.apache.pulsar.client.impl.ConsumerInterceptors<T>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ConsumerInterceptors<T> extends java.lang.Object implements java.io.CloseableA container that hold the listConsumerInterceptorand wraps calls to the chain of custom interceptors.
-
-
Constructor Summary
Constructors Constructor Description ConsumerInterceptors(java.util.List<org.apache.pulsar.client.api.ConsumerInterceptor<T>> interceptors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.pulsar.client.api.Message<T>beforeConsume(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.Message<T> message)This is called just before the message is returned byConsumer.receive(),MessageListener.received(Consumer, Message)or theCompletableFuturereturned byConsumer.receiveAsync()completes.voidclose()voidonAcknowledge(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.MessageId messageId, java.lang.Throwable exception)This is called when acknowledge request return from the broker.voidonAcknowledgeCumulative(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.MessageId messageId, java.lang.Throwable exception)This is called when acknowledge cumulative request return from the broker.voidonAckTimeoutSend(org.apache.pulsar.client.api.Consumer<T> consumer, java.util.Set<org.apache.pulsar.client.api.MessageId> messageIds)This is called when a redelivery from an acknowledge timeout occurs.voidonNegativeAcksSend(org.apache.pulsar.client.api.Consumer<T> consumer, java.util.Set<org.apache.pulsar.client.api.MessageId> messageIds)This is called when a redelivery from a negative acknowledge occurs.voidonPartitionsChange(java.lang.String topicName, int partitions)
-
-
-
Constructor Detail
-
ConsumerInterceptors
public ConsumerInterceptors(java.util.List<org.apache.pulsar.client.api.ConsumerInterceptor<T>> interceptors)
-
-
Method Detail
-
beforeConsume
public org.apache.pulsar.client.api.Message<T> beforeConsume(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.Message<T> message)
This is called just before the message is returned byConsumer.receive(),MessageListener.received(Consumer, Message)or theCompletableFuturereturned byConsumer.receiveAsync()completes.This method calls
ConsumerInterceptor.beforeConsume(Consumer, Message)for each interceptor. Messages returned from each interceptor get passed to beforeConsume() of the next interceptor in the chain of interceptors.This method does not throw exceptions. If any of the interceptors in the chain throws an exception, it gets caught and logged, and next interceptor in int the chain is called with 'messages' returned by the previous successful interceptor beforeConsume call.
- Parameters:
consumer- the consumer which contains the interceptorsmessage- message to be consume by the client.- Returns:
- messages that are either modified by interceptors or same as messages passed to this method.
-
onAcknowledge
public void onAcknowledge(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.MessageId messageId, java.lang.Throwable exception)
This is called when acknowledge request return from the broker.This method calls
ConsumerInterceptor.onAcknowledge(Consumer, MessageId, Throwable)method for each interceptor.This method does not throw exceptions. Exceptions thrown by any of interceptors in the chain are logged, but not propagated.
- Parameters:
consumer- the consumer which contains the interceptorsmessageId- message to acknowledge.exception- exception returned by broker.
-
onAcknowledgeCumulative
public void onAcknowledgeCumulative(org.apache.pulsar.client.api.Consumer<T> consumer, org.apache.pulsar.client.api.MessageId messageId, java.lang.Throwable exception)
This is called when acknowledge cumulative request return from the broker.This method calls
ConsumerInterceptor.onAcknowledgeCumulative(Consumer, MessageId, Throwable)(Message, Throwable)} method for each interceptor.This method does not throw exceptions. Exceptions thrown by any of interceptors in the chain are logged, but not propagated.
- Parameters:
consumer- the consumer which contains the interceptorsmessageId- messages to acknowledge.exception- exception returned by broker.
-
onNegativeAcksSend
public void onNegativeAcksSend(org.apache.pulsar.client.api.Consumer<T> consumer, java.util.Set<org.apache.pulsar.client.api.MessageId> messageIds)
This is called when a redelivery from a negative acknowledge occurs.This method calls
onNegativeAcksSend(Consumer, Set<MessageId>)method for each interceptor.This method does not throw exceptions. Exceptions thrown by any of interceptors in the chain are logged, but not propagated.
- Parameters:
consumer- the consumer which contains the interceptors.messageIds- set of message IDs being redelivery due a negative acknowledge.
-
onAckTimeoutSend
public void onAckTimeoutSend(org.apache.pulsar.client.api.Consumer<T> consumer, java.util.Set<org.apache.pulsar.client.api.MessageId> messageIds)
This is called when a redelivery from an acknowledge timeout occurs.This method calls
onAckTimeoutSend(Consumer, Set<MessageId>)method for each interceptor.This method does not throw exceptions. Exceptions thrown by any of interceptors in the chain are logged, but not propagated.
- Parameters:
consumer- the consumer which contains the interceptors.messageIds- set of message IDs being redelivery due an acknowledge timeout.
-
onPartitionsChange
public void onPartitionsChange(java.lang.String topicName, int partitions)
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-