Class CompositeRecordInterceptor<K,V>
- java.lang.Object
-
- org.springframework.kafka.listener.CompositeRecordInterceptor<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
ConsumerAwareRecordInterceptor<K,V>
,RecordInterceptor<K,V>
,ThreadStateProcessor
public class CompositeRecordInterceptor<K,V> extends java.lang.Object implements ConsumerAwareRecordInterceptor<K,V>
ARecordInterceptor
that delegates to one or moreRecordInterceptor
s in order.- Since:
- 2.3
- Author:
- Artem Bilan, Gary Russell
-
-
Constructor Summary
Constructors Constructor Description CompositeRecordInterceptor(RecordInterceptor<K,V>... delegates)
Construct an instance with the provided delegates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 eitherRecordInterceptor.success(ConsumerRecord, Consumer)
orRecordInterceptor.failure(ConsumerRecord, Exception, Consumer)
.void
clearThreadState(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
Call to clear thread-bound resources which were set up inThreadStateProcessor.setupThreadState(Consumer)
.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, org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Perform some action on the record or return a different one.void
setupThreadState(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
Call to set up thread-bound resources which will be available for the entire duration of enclosed operation involving aConsumer
.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.listener.ConsumerAwareRecordInterceptor
intercept
-
-
-
-
Constructor Detail
-
CompositeRecordInterceptor
@SafeVarargs public CompositeRecordInterceptor(RecordInterceptor<K,V>... delegates)
Construct an instance with the provided delegates.- Parameters:
delegates
- the delegates.
-
-
Method Detail
-
intercept
@Nullable public 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)
Description copied from interface:RecordInterceptor
Perform some action on the record or return a different one. If null is returned the record will be skipped. Invoked before the listener.- Specified by:
intercept
in interfaceConsumerAwareRecordInterceptor<K,V>
- Specified by:
intercept
in interfaceRecordInterceptor<K,V>
- Parameters:
record
- the record.consumer
- the consumer.- Returns:
- the record or null.
-
success
public void success(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record, org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Description copied from interface:RecordInterceptor
Called after the listener exits normally.- Specified by:
success
in interfaceRecordInterceptor<K,V>
- Parameters:
record
- the record.consumer
- the consumer.
-
failure
public void failure(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record, java.lang.Exception exception, org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Description copied from interface:RecordInterceptor
Called after the listener throws an exception.- Specified by:
failure
in interfaceRecordInterceptor<K,V>
- Parameters:
record
- the record.exception
- the exception.consumer
- the consumer.
-
setupThreadState
public void setupThreadState(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
Description copied from interface:ThreadStateProcessor
Call to set up thread-bound resources which will be available for the entire duration of enclosed operation involving aConsumer
.- Specified by:
setupThreadState
in interfaceThreadStateProcessor
- Parameters:
consumer
- the consumer.
-
clearThreadState
public void clearThreadState(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
Description copied from interface:ThreadStateProcessor
Call to clear thread-bound resources which were set up inThreadStateProcessor.setupThreadState(Consumer)
.- Specified by:
clearThreadState
in interfaceThreadStateProcessor
- Parameters:
consumer
- the consumer.
-
afterRecord
public void afterRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record, org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
Description copied from interface:RecordInterceptor
Called when processing the record is complete eitherRecordInterceptor.success(ConsumerRecord, Consumer)
orRecordInterceptor.failure(ConsumerRecord, Exception, Consumer)
.- Specified by:
afterRecord
in interfaceRecordInterceptor<K,V>
- Parameters:
record
- the record.consumer
- the consumer.
-
-