Package org.apache.pulsar.client.impl
Class ProducerInterceptors
- java.lang.Object
-
- org.apache.pulsar.client.impl.ProducerInterceptors
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ProducerInterceptors extends java.lang.Object implements java.io.CloseableA container that holds the listProducerInterceptorand wraps calls to the chain of custom interceptors.
-
-
Constructor Summary
Constructors Constructor Description ProducerInterceptors(java.util.List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.pulsar.client.api.MessagebeforeSend(org.apache.pulsar.client.api.Producer producer, org.apache.pulsar.client.api.Message message)This is called when client sends message to pulsar broker, before key and value gets serialized.voidclose()voidonPartitionsChange(java.lang.String topicName, int partitions)voidonSendAcknowledgement(org.apache.pulsar.client.api.Producer producer, org.apache.pulsar.client.api.Message message, org.apache.pulsar.client.api.MessageId msgId, java.lang.Throwable exception)This method is called when the message send to the broker has been acknowledged, or when sending the record fails before it gets send to the broker.
-
-
-
Method Detail
-
beforeSend
public org.apache.pulsar.client.api.Message beforeSend(org.apache.pulsar.client.api.Producer producer, org.apache.pulsar.client.api.Message message)This is called when client sends message to pulsar broker, before key and value gets serialized. The method callsProducerInterceptor.beforeSend(Producer,Message)method. Message returned from first interceptor's beforeSend() is passed to the second interceptor beforeSend(), and so on in the interceptor chain. The message returned from the last interceptor is returned from this method. This method does not throw exceptions. Exceptions thrown by any interceptor methods are caught and ignored. If a interceptor in the middle of the chain, that normally modifies the message, throws an exception, the next interceptor in the chain will be called with a message returned by the previous interceptor that did not throw an exception.- Parameters:
producer- the producer which contains the interceptor.message- the message from client- Returns:
- the message to send to topic/partition
-
onSendAcknowledgement
public void onSendAcknowledgement(org.apache.pulsar.client.api.Producer producer, org.apache.pulsar.client.api.Message message, org.apache.pulsar.client.api.MessageId msgId, java.lang.Throwable exception)This method is called when the message send to the broker has been acknowledged, or when sending the record fails before it gets send to the broker. This method callsProducerInterceptor.onSendAcknowledgement(Producer, Message, MessageId, Throwable)method for each interceptor. This method does not throw exceptions. Exceptions thrown by any of interceptor methods are caught and ignored.- Parameters:
producer- the producer which contains the interceptor.message- The message returned from the last interceptor is returned fromProducerInterceptor.beforeSend(Producer, Message)msgId- The message id that broker returned. Null if has error occurred.exception- The exception thrown during processing of this message. Null if no error occurred.
-
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
-
-