public enum OffsetStrategy extends java.lang.Enum<OffsetStrategy>
An enum representing different strategies for committing offsets to Kafka when using KafkaListener
.
To track records that have been consumed Kafka allows committing offsets at a frequency desired by the developer. This tracking is done by committing offsets for a given partition back to Kafka.
Depending on requirements you may wish the commit more or less frequently and you may not care whether the commit was successful or not. This enum allows configuring a range of policies for a Kafka consumer from leaving it down to the Kafka client (with {code AUTO}) to synchronously committing offsets after each consumer record is consumed.
Enum Constant and Description |
---|
ASYNC
Asynchronously commit offsets using
Consumer.commitAsync() after each batch of messages is processed. |
ASYNC_PER_RECORD
Asynchronously commit offsets using
Consumer.commitSync() after each ConsumerRecord is consumed. |
AUTO
Automatically commit offsets with the
Consumer.poll(long) loop. |
DISABLED
Do not commit offsets.
|
SYNC
Synchronously commit offsets using
Consumer.commitSync() after each batch of messages is processed. |
SYNC_PER_RECORD
Synchronously commit offsets using
Consumer.commitSync() after each ConsumerRecord is consumed. |
Modifier and Type | Method and Description |
---|---|
static OffsetStrategy |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static OffsetStrategy[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final OffsetStrategy AUTO
Consumer.poll(long)
loop.public static final OffsetStrategy DISABLED
KafkaConsumer
itself and call KafkaConsumer.commitSync()
.public static final OffsetStrategy SYNC
Consumer.commitSync()
after each batch of messages is processed.public static final OffsetStrategy ASYNC
Consumer.commitAsync()
after each batch of messages is processed.public static final OffsetStrategy SYNC_PER_RECORD
Consumer.commitSync()
after each ConsumerRecord
is consumed.public static final OffsetStrategy ASYNC_PER_RECORD
Consumer.commitSync()
after each ConsumerRecord
is consumed.public static OffsetStrategy[] values()
for (OffsetStrategy c : OffsetStrategy.values()) System.out.println(c);
public static OffsetStrategy valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null