Package org.apache.pulsar.client.impl
Class ProducerInterceptors
java.lang.Object
org.apache.pulsar.client.impl.ProducerInterceptors
- All Implemented Interfaces:
Closeable,AutoCloseable
A container that holds the list
ProducerInterceptor
and wraps calls to the chain of custom interceptors.-
Constructor Summary
ConstructorsConstructorDescriptionProducerInterceptors(List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors) -
Method Summary
Modifier and TypeMethodDescriptionorg.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(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, 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.
-
Constructor Details
-
ProducerInterceptors
public ProducerInterceptors(List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors)
-
-
Method Details
-
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, 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
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-