Class ConsumerInterceptors<K,V>

java.lang.Object
org.apache.kafka.clients.consumer.internals.ConsumerInterceptors<K,V>
All Implemented Interfaces:
Closeable, AutoCloseable

public class ConsumerInterceptors<K,V> extends Object implements Closeable
A container that holds the list ConsumerInterceptor and wraps calls to the chain of custom interceptors.
  • Constructor Details

  • Method Details

    • onConsume

      public ConsumerRecords<K,V> onConsume(ConsumerRecords<K,V> records)
      This is called when the records are about to be returned to the user.

      This method calls ConsumerInterceptor.onConsume(ConsumerRecords) for each interceptor. Records returned from each interceptor get passed to onConsume() of the next interceptor in the chain of interceptors.

      This method does not throw exceptions. If any of the interceptors in the chain throws an exception, it gets caught and logged, and next interceptor in the chain is called with 'records' returned by the previous successful interceptor onConsume call.

      Parameters:
      records - records to be consumed by the client.
      Returns:
      records that are either modified by interceptors or same as records passed to this method.
    • onCommit

      public void onCommit(Map<org.apache.kafka.common.TopicPartition,OffsetAndMetadata> offsets)
      This is called when commit request returns successfully from the broker.

      This method calls ConsumerInterceptor.onCommit(Map) method for each interceptor.

      This method does not throw exceptions. Exceptions thrown by any of the interceptors in the chain are logged, but not propagated.

      Parameters:
      offsets - A map of offsets by partition with associated metadata
    • close

      public void close()
      Closes every interceptor in a container.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable