Enum Class OffsetStrategy

java.lang.Object
java.lang.Enum<OffsetStrategy>
io.micronaut.configuration.kafka.annotation.OffsetStrategy
All Implemented Interfaces:
Serializable, Comparable<OffsetStrategy>, Constable

public enum OffsetStrategy extends 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.

Since:
1.0
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Asynchronously commit offsets using Consumer.commitAsync() after each batch of messages is processed.
    Asynchronously commit offsets using Consumer.commitSync() after each ConsumerRecord is processed.
    Automatically commit offsets with the Consumer.poll(java.time.Duration) loop.
    Do not commit offsets.
    Only applicable for transactional processing in combination with SendTo.
    Synchronously commit offsets using Consumer.commitSync() after each batch of messages is processed.
    Synchronously commit offsets using Consumer.commitSync() after each ConsumerRecord is processed.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • AUTO

      public static final OffsetStrategy AUTO
      Automatically commit offsets with the Consumer.poll(java.time.Duration) loop.
    • DISABLED

      public static final OffsetStrategy DISABLED
      Do not commit offsets. In this case the consumer method should accept an argument that is the KafkaConsumer itself and call KafkaConsumer.commitSync().
    • SYNC

      public static final OffsetStrategy SYNC
      Synchronously commit offsets using Consumer.commitSync() after each batch of messages is processed.
    • ASYNC

      public static final OffsetStrategy ASYNC
      Asynchronously commit offsets using Consumer.commitAsync() after each batch of messages is processed.
    • SYNC_PER_RECORD

      public static final OffsetStrategy SYNC_PER_RECORD
      Synchronously commit offsets using Consumer.commitSync() after each ConsumerRecord is processed.
    • ASYNC_PER_RECORD

      public static final OffsetStrategy ASYNC_PER_RECORD
      Asynchronously commit offsets using Consumer.commitSync() after each ConsumerRecord is processed.
    • SEND_TO_TRANSACTION

      public static final OffsetStrategy SEND_TO_TRANSACTION
      Only applicable for transactional processing in combination with SendTo. Sends offsets to transaction using Producer.sendOffsetsToTransaction(java.util.Map, org.apache.kafka.clients.consumer.ConsumerGroupMetadata)
  • Method Details

    • values

      public static OffsetStrategy[] 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

      public static OffsetStrategy valueOf(String name)
      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 name
      NullPointerException - if the argument is null