Class ProducerInterceptors

java.lang.Object
org.apache.pulsar.client.impl.ProducerInterceptors
All Implemented Interfaces:
Closeable, AutoCloseable

public class ProducerInterceptors extends Object implements Closeable
A container that holds the listProducerInterceptor and wraps calls to the chain of custom interceptors.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProducerInterceptors(List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    void
     
    void
    onPartitionsChange(String topicName, int partitions)
     
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 calls ProducerInterceptor.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 calls ProducerInterceptor.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 from ProducerInterceptor.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(String topicName, int partitions)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException