接口 ProducerInterceptor<T>
-
- 所有超级接口:
java.lang.AutoCloseable
@Public @Stable @Deprecated public interface ProducerInterceptor<T> extends java.lang.AutoCloseable
已过时。A plugin interface that allows you to intercept (and possibly mutate) the messages received by the producer before they are published to the Pulsar brokers.Exceptions thrown by ProducerInterceptor methods will be caught, logged, but not propagated further.
ProducerInterceptor callbacks may be called from multiple threads. Interceptor implementation must ensure thread-safety, if needed.
-
-
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 Message<T>beforeSend(Producer<T> producer, Message<T> message)已过时。This is called fromProducer.send(Object)andProducer.sendAsync(Object)methods, before send the message to the brokers.voidclose()已过时。Close the interceptor.voidonSendAcknowledgement(Producer<T> producer, Message<T> message, MessageId msgId, java.lang.Throwable exception)已过时。This method is called when the message sent to the broker has been acknowledged, or when sending the message fails.
-
-
-
方法详细资料
-
close
void close()
已过时。Close the interceptor.- 指定者:
close在接口中java.lang.AutoCloseable
-
beforeSend
Message<T> beforeSend(Producer<T> producer, Message<T> message)
已过时。This is called fromProducer.send(Object)andProducer.sendAsync(Object)methods, before send the message to the brokers. This method is allowed to modify the record, in which case, the new record will be returned.Any exception thrown by this method will be caught by the caller and logged, but not propagated further.
Since the producer may run multiple interceptors, a particular interceptor's
beforeSend(Producer, Message)callback will be called in the order specified byProducerBuilder.intercept(ProducerInterceptor[]).The first interceptor in the list gets the message passed from the client, the following interceptor will be passed the message returned by the previous interceptor, and so on. Since interceptors are allowed to modify messages, interceptors may potentially get the message 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 the interceptors in the list throws an exception from
#beforeSend(Message), 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 client.- 参数:
producer- the producer which contains the interceptor.message- message to send- 返回:
- the intercepted message
-
onSendAcknowledgement
void onSendAcknowledgement(Producer<T> producer, Message<T> message, MessageId msgId, java.lang.Throwable exception)
已过时。This method is called when the message sent to the broker has been acknowledged, or when sending the message fails. This method is generally called just before the user callback is called, and in additional cases when an exception on the producer side.Any exception thrown by this method will be ignored by the caller.
This method will generally execute in the background I/O thread, so the implementation should be reasonably fast. Otherwise, sending of messages from other threads could be delayed.
- 参数:
producer- the producer which contains the interceptor.message- the message that application sendsmsgId- the message id that assigned by the broker; null if send failed.exception- the exception on sending messages, null indicates send has succeed.
-
-