@InterfaceAudience.Private @InterfaceStability.Stable public class ProducerInterceptorWrapper extends Object implements ProducerInterceptor
Constructor and Description |
---|
ProducerInterceptorWrapper(ProducerInterceptor<?> innerInterceptor) |
Modifier and Type | Method and Description |
---|---|
Message |
beforeSend(Producer producer,
Message message)
This is called from
Producer.send(Object) and Producer.sendAsync(Object) methods, before
send the message to the brokers. |
void |
close()
Close the interceptor.
|
boolean |
eligible(Message message)
Check whether the interceptor is eligible for this message.
|
void |
onSendAcknowledgement(Producer producer,
Message message,
MessageId msgId,
Throwable exception)
This method is called when the message sent to the broker has been
acknowledged, or when sending the message fails.
|
public ProducerInterceptorWrapper(ProducerInterceptor<?> innerInterceptor)
public void close()
ProducerInterceptor
close
in interface AutoCloseable
close
in interface ProducerInterceptor
public boolean eligible(Message message)
ProducerInterceptor
eligible
in interface ProducerInterceptor
message
- message to sendpublic Message beforeSend(Producer producer, Message message)
ProducerInterceptor
Producer.send(Object)
and Producer.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.
Each interceptor will be passed the message returned by the last successful executed interceptor or the original message if it is the first one. 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.
beforeSend
in interface ProducerInterceptor
producer
- the producer which contains the interceptor.message
- message to sendpublic void onSendAcknowledgement(Producer producer, Message message, MessageId msgId, Throwable exception)
ProducerInterceptor
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.
onSendAcknowledgement
in interface ProducerInterceptor
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.Copyright © 2017–2021 Apache Software Foundation. All rights reserved.