Enum Class OffsetStrategy
- All Implemented Interfaces:
Serializable
,Comparable<OffsetStrategy>
,Constable
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.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionAsynchronously commit offsets usingConsumer.commitAsync()
after each batch of messages is processed.Asynchronously commit offsets usingConsumer.commitSync()
after eachConsumerRecord
is processed.Automatically commit offsets with theConsumer.poll(java.time.Duration)
loop.Do not commit offsets.Only applicable for transactional processing in combination withSendTo
.Synchronously commit offsets usingConsumer.commitSync()
after each batch of messages is processed.Synchronously commit offsets usingConsumer.commitSync()
after eachConsumerRecord
is processed. -
Method Summary
Modifier and TypeMethodDescriptionstatic OffsetStrategy
Returns the enum constant of this class with the specified name.static OffsetStrategy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
AUTO
Automatically commit offsets with theConsumer.poll(java.time.Duration)
loop. -
DISABLED
Do not commit offsets. In this case the consumer method should accept an argument that is theKafkaConsumer
itself and callKafkaConsumer.commitSync()
. -
SYNC
Synchronously commit offsets usingConsumer.commitSync()
after each batch of messages is processed. -
ASYNC
Asynchronously commit offsets usingConsumer.commitAsync()
after each batch of messages is processed. -
SYNC_PER_RECORD
Synchronously commit offsets usingConsumer.commitSync()
after eachConsumerRecord
is processed. -
ASYNC_PER_RECORD
Asynchronously commit offsets usingConsumer.commitSync()
after eachConsumerRecord
is processed. -
SEND_TO_TRANSACTION
Only applicable for transactional processing in combination withSendTo
. Sends offsets to transaction usingProducer.sendOffsetsToTransaction(java.util.Map, org.apache.kafka.clients.consumer.ConsumerGroupMetadata)
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-