接口 ConsumerInterceptor<T>
-
- 所有超级接口:
java.lang.AutoCloseable
@Public @Stable public interface ConsumerInterceptor<T> extends java.lang.AutoCloseable
A plugin interface that allows you to intercept (and possibly mutate) messages received by the consumer.A primary use case is to hook into consumer applications for custom monitoring, logging, etc.
Exceptions thrown by interceptor methods will be caught, logged, but not propagated further.
-
-
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 Message<T>beforeConsume(Consumer<T> consumer, Message<T> message)This is called just before the message is returned byConsumer.receive(),MessageListener.received(Consumer, Message)or theCompletableFuturereturned byConsumer.receiveAsync()completes.voidclose()Close the interceptor.voidonAcknowledge(Consumer<T> consumer, MessageId messageId, java.lang.Throwable exception)This is called consumer sends the acknowledgment to the broker.voidonAcknowledgeCumulative(Consumer<T> consumer, MessageId messageId, java.lang.Throwable exception)This is called consumer send the cumulative acknowledgment to the broker.voidonAckTimeoutSend(Consumer<T> consumer, java.util.Set<MessageId> messageIds)This method will be called when a redelivery from an acknowledge timeout occurs.voidonNegativeAcksSend(Consumer<T> consumer, java.util.Set<MessageId> messageIds)This method will be called when a redelivery from a negative acknowledge occurs.
-
-
-
方法详细资料
-
close
void close()
Close the interceptor.- 指定者:
close在接口中java.lang.AutoCloseable
-
beforeConsume
Message<T> beforeConsume(Consumer<T> consumer, 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 is allowed to modify message, in which case the new message will be returned.
Any exception thrown by this method will be caught by the caller, logged, but not propagated to client.
Since the consumer may run multiple interceptors, a particular interceptor's beforeConsume callback will be called in the order specified by
ConsumerBuilder.intercept(ConsumerInterceptor[]). The first interceptor in the list gets the consumed message, the following interceptor will be passed the message returned by the previous interceptor, and so on. Since interceptors are allowed to modify message, interceptors may potentially get the messages already modified by other interceptors. However building a pipeline of mutable interceptors that depend on the output of the previous interceptor is discouraged, because of potential side-effects caused by interceptors potentially failing to modify the message and throwing an exception. if one of interceptors in the list throws an exception from beforeConsume, the exception is caught, logged, and the next interceptor is called with the message returned by the last successful interceptor in the list, or otherwise the original consumed message.- 参数:
consumer- the consumer which contains the interceptormessage- the message to be consumed by the client.- 返回:
- message that is either modified by the interceptor or same message passed into the method.
-
onAcknowledge
void onAcknowledge(Consumer<T> consumer, MessageId messageId, java.lang.Throwable exception)
This is called consumer sends the acknowledgment to the broker.Any exception thrown by this method will be ignored by the caller.
- 参数:
consumer- the consumer which contains the interceptormessageId- message to ack, null if acknowledge fail.exception- the exception on acknowledge.
-
onAcknowledgeCumulative
void onAcknowledgeCumulative(Consumer<T> consumer, MessageId messageId, java.lang.Throwable exception)
This is called consumer send the cumulative acknowledgment to the broker.Any exception thrown by this method will be ignored by the caller.
- 参数:
consumer- the consumer which contains the interceptormessageId- message to ack, null if acknowledge fail.exception- the exception on acknowledge.
-
onNegativeAcksSend
void onNegativeAcksSend(Consumer<T> consumer, java.util.Set<MessageId> messageIds)
This method will be called when a redelivery from a negative acknowledge occurs.Any exception thrown by this method will be ignored by the caller.
- 参数:
consumer- the consumer which contains the interceptormessageIds- message to ack, null if acknowledge fail.
-
onAckTimeoutSend
void onAckTimeoutSend(Consumer<T> consumer, java.util.Set<MessageId> messageIds)
This method will be called when a redelivery from an acknowledge timeout occurs.Any exception thrown by this method will be ignored by the caller.
- 参数:
consumer- the consumer which contains the interceptormessageIds- message to ack, null if acknowledge fail.
-
-