Class ProducerInterceptorWrapper
- java.lang.Object
-
- org.apache.pulsar.client.api.interceptor.ProducerInterceptorWrapper
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ProducerInterceptor
@Private @Stable public class ProducerInterceptorWrapper extends java.lang.Object implements ProducerInterceptor
A wrapper for old style producer interceptor.
-
-
Constructor Summary
Constructors Constructor Description ProducerInterceptorWrapper(ProducerInterceptor<?> innerInterceptor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessagebeforeSend(Producer producer, Message message)This is called fromProducer.send(Object)andProducer.sendAsync(Object)methods, before send the message to the brokers.voidclose()Close the interceptor.booleaneligible(Message message)Check whether the interceptor is eligible for this message.voidonPartitionsChange(java.lang.String topicName, int partitions)This method is called when partitions of the topic (partitioned-topic) changes.voidonSendAcknowledgement(Producer producer, Message 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.
-
-
-
Constructor Detail
-
ProducerInterceptorWrapper
public ProducerInterceptorWrapper(ProducerInterceptor<?> innerInterceptor)
-
-
Method Detail
-
close
public void close()
Description copied from interface:ProducerInterceptorClose the interceptor.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceProducerInterceptor
-
eligible
public boolean eligible(Message message)
Description copied from interface:ProducerInterceptorCheck whether the interceptor is eligible for this message.- Specified by:
eligiblein interfaceProducerInterceptor- Parameters:
message- message to send- Returns:
- whether the interceptor can be applied to this particular message.
-
beforeSend
public Message beforeSend(Producer producer, Message message)
Description copied from interface:ProducerInterceptorThis 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.
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.
- Specified by:
beforeSendin interfaceProducerInterceptor- Parameters:
producer- the producer which contains the interceptor.message- message to send- Returns:
- the intercepted message
-
onSendAcknowledgement
public void onSendAcknowledgement(Producer producer, Message message, MessageId msgId, java.lang.Throwable exception)
Description copied from interface:ProducerInterceptorThis 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.
- Specified by:
onSendAcknowledgementin interfaceProducerInterceptor- Parameters:
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.
-
onPartitionsChange
public void onPartitionsChange(java.lang.String topicName, int partitions)Description copied from interface:ProducerInterceptorThis method is called when partitions of the topic (partitioned-topic) changes.- Specified by:
onPartitionsChangein interfaceProducerInterceptor- Parameters:
topicName- topic namepartitions- new updated partitions
-
-