public interface ConsumerListener<K,V>
Implement this interface to listen asynchronously to records using a Kafka consumer. By annotating the implementing
class with KafkaListener
, the underlying consumer will be automatically subscribed to the specified topics.
The underlying Kafka consumer will be automatically started and stopped with the application. A unhandled failure will gracefully stop the consumer and a later attempt will be rescheduled.
If the implementing class also implements ConsumerRebalanceListener
, it
will be used as the rebalance listener for the underlying consumer. If the implementing class also implements
OffsetCommitCallback
, it will be used as a callback during the
asynchronous commits.
Modifier and Type | Method and Description |
---|---|
default void |
onConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
This method is called when a
ConsumerRecords is available. |
default void |
onConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords<K,V> records)
This method is called when some
ConsumerRecords are available. |
default void |
onException(Exception e)
This method is called when an exception occurs during consumer polling or message processing in
onConsumerRecords(ConsumerRecords) . |
default void onConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
ConsumerRecords
is available.record
- the record.default void onConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords<K,V> records)
ConsumerRecords
are available.records
- the just-polled consumer records.default void onException(Exception e) throws Exception
onConsumerRecords(ConsumerRecords)
.e
- the exception that occurred.Exception
- rethrow an exception to trigger a graceful stop and a retry after the specified delay.Copyright © 2013-2018–2019 SeedStack. All rights reserved.