Interface BrokerInterceptor

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
BrokerInterceptors, BrokerInterceptorWithClassLoader

@LimitedPrivate @Evolving public interface BrokerInterceptor extends AutoCloseable
A plugin interface that allows you to intercept the client requests to the Pulsar brokers.

BrokerInterceptor callbacks may be called from multiple threads. Interceptor implementation must ensure thread-safety, if needed.

  • Method Details

    • beforeSendMessage

      @Deprecated default void beforeSendMessage(Subscription subscription, Entry entry, long[] ackSet, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata)
      Deprecated.
      Intercept messages before sending them to the consumers. Deprecated, use beforeSendMessage(Subscription, Entry, long[], MessageMetadata, Consumer) instead.
      Parameters:
      subscription - pulsar subscription
      entry - entry
      ackSet - entry ack bitset. it is either null or an array of long-based bitsets.
      msgMetadata - message metadata. The message metadata will be recycled after this call.
    • beforeSendMessage

      default void beforeSendMessage(Subscription subscription, Entry entry, long[] ackSet, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, Consumer consumer)
      Intercept messages before sending them to the consumers.
      Parameters:
      subscription - pulsar subscription
      entry - entry
      ackSet - entry ack bitset. it is either null or an array of long-based bitsets.
      msgMetadata - message metadata. The message metadata will be recycled after this call.
      consumer - consumer. Consumer which entry are sent to.
    • onConnectionCreated

      default void onConnectionCreated(ServerCnx cnx)
      Called by the broker when a new connection is created.
    • producerCreated

      default void producerCreated(ServerCnx cnx, Producer producer, Map<String,String> metadata)
      Called by the broker when a new connection is created.
    • producerClosed

      default void producerClosed(ServerCnx cnx, Producer producer, Map<String,String> metadata)
      Called by the broker when a producer is closed.
      Parameters:
      cnx - client Connection
      producer - Producer object
      metadata - A map of metadata
    • consumerCreated

      default void consumerCreated(ServerCnx cnx, Consumer consumer, Map<String,String> metadata)
      Intercept after a consumer is created.
      Parameters:
      cnx - client Connection
      consumer - Consumer object
      metadata - A map of metadata
    • consumerClosed

      default void consumerClosed(ServerCnx cnx, Consumer consumer, Map<String,String> metadata)
      Called by the broker when a consumer is closed.
      Parameters:
      cnx - client Connection
      consumer - Consumer object
      metadata - A map of metadata
    • onMessagePublish

      default void onMessagePublish(Producer producer, io.netty.buffer.ByteBuf headersAndPayload, Topic.PublishContext publishContext)
      Intercept message when broker receive a send request.
      Parameters:
      headersAndPayload - entry's header and payload
      publishContext - Publish Context
    • messageProduced

      default void messageProduced(ServerCnx cnx, Producer producer, long startTimeNs, long ledgerId, long entryId, Topic.PublishContext publishContext)
      Intercept after a message is produced.
      Parameters:
      cnx - client Connection
      producer - Producer object
      publishContext - Publish Context
    • messageDispatched

      default void messageDispatched(ServerCnx cnx, Consumer consumer, long ledgerId, long entryId, io.netty.buffer.ByteBuf headersAndPayload)
      Intercept after a message is dispatched to consumer.
      Parameters:
      cnx - client Connection
      consumer - Consumer object
      ledgerId - Ledger ID
      entryId - Entry ID
      headersAndPayload - Data
    • messageAcked

      default void messageAcked(ServerCnx cnx, Consumer consumer, org.apache.pulsar.common.api.proto.CommandAck ackCmd)
      Intercept after a message ack is processed.
      Parameters:
      cnx - client Connection
      ackCmd - Command object
    • txnOpened

      default void txnOpened(long tcId, String txnID)
      Intercept when a transaction begins.
      Parameters:
      tcId - Transaction Coordinator Id
      txnID - Transaction ID
    • txnEnded

      default void txnEnded(String txnID, long txnAction)
      Intercept when a transaction ends.
      Parameters:
      txnID - Transaction ID
      txnAction - Transaction Action
    • onPulsarCommand

      void onPulsarCommand(org.apache.pulsar.common.api.proto.BaseCommand command, ServerCnx cnx) throws org.apache.pulsar.common.intercept.InterceptException
      Called by the broker while new command incoming.
      Throws:
      org.apache.pulsar.common.intercept.InterceptException
    • onConnectionClosed

      void onConnectionClosed(ServerCnx cnx)
      Called by the broker while connection closed.
    • onWebserviceRequest

      void onWebserviceRequest(javax.servlet.ServletRequest request) throws IOException, javax.servlet.ServletException, org.apache.pulsar.common.intercept.InterceptException
      Called by the web service while new request incoming.
      Throws:
      IOException
      javax.servlet.ServletException
      org.apache.pulsar.common.intercept.InterceptException
    • onWebserviceResponse

      void onWebserviceResponse(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws IOException, javax.servlet.ServletException
      Intercept the webservice response before send to client.
      Throws:
      IOException
      javax.servlet.ServletException
    • onFilter

      default void onFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
      The interception of web processing, as same as `Filter.onFilter`. So In this method, we must call `chain.doFilter` to continue the chain.
      Throws:
      IOException
      javax.servlet.ServletException
    • initialize

      void initialize(PulsarService pulsarService) throws Exception
      Initialize the broker interceptor.
      Throws:
      Exception - when fail to initialize the broker interceptor.
    • close

      void close()
      Close this broker interceptor.
      Specified by:
      close in interface AutoCloseable