Interface RecordInterceptor<K,​V>

  • Type Parameters:
    K - the key type.
    V - the value type.
    All Superinterfaces:
    ThreadStateProcessor
    All Known Subinterfaces:
    ConsumerAwareRecordInterceptor<K,​V>
    All Known Implementing Classes:
    CompositeRecordInterceptor
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface RecordInterceptor<K,​V>
    extends ThreadStateProcessor
    An interceptor for ConsumerRecord invoked by the listener container before and after invoking the listener.
    Since:
    2.2.7
    Author:
    Gary Russell
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default void afterRecord​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record, org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
      Called when processing the record is complete either success(ConsumerRecord, Consumer) or failure(ConsumerRecord, Exception, Consumer).
      default void failure​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record, java.lang.Exception exception, org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
      Called after the listener throws an exception.
      org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> intercept​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record)
      Deprecated.
      in favor of intercept(ConsumerRecord, Consumer) which will become the required method in a future release.
      default org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> intercept​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record, org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
      Perform some action on the record or return a different one.
      default void success​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record, org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
      Called after the listener exits normally.
    • Method Detail

      • intercept

        @Deprecated
        @Nullable
        org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> intercept​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record)
        Deprecated.
        in favor of intercept(ConsumerRecord, Consumer) which will become the required method in a future release.
        Perform some action on the record or return a different one. If null is returned the record will be skipped. Invoked before the listener. IMPORTANT; if this method returns a different record, the topic, partition and offset must not be changed to avoid undesirable side-effects.
        Parameters:
        record - the record.
        Returns:
        the record or null.
      • intercept

        @Nullable
        default org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> intercept​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record,
                                                                                      org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
        Perform some action on the record or return a different one. If null is returned the record will be skipped. Invoked before the listener.
        Parameters:
        record - the record.
        consumer - the consumer.
        Returns:
        the record or null.
        Since:
        2.7
      • success

        default void success​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record,
                             org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
        Called after the listener exits normally.
        Parameters:
        record - the record.
        consumer - the consumer.
        Since:
        2.7
      • failure

        default void failure​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record,
                             java.lang.Exception exception,
                             org.apache.kafka.clients.consumer.Consumer<K,​V> consumer)
        Called after the listener throws an exception.
        Parameters:
        record - the record.
        exception - the exception.
        consumer - the consumer.
        Since:
        2.7