Options for auto.offset.reset in Kafka

The default value of the auto.offset.reset configuration in Apache Kafka depends on the context in which it is used. This configuration determines what the consumer should do when there is no initial offset in Kafka or if the current offset does not exist anymore (e.g., due to log cleanup).

Default Value

  • latest is the default value for auto.offset.reset.

Options for auto.offset.reset

  1. earliest:

    • The consumer starts reading from the beginning of the log (the earliest offset).
    • Useful for reprocessing data from the start.
  2. latest (default):

    • The consumer starts reading from the end of the log (the latest offset).
    • It reads only new messages produced after the consumer has started.
  3. none:

    • Throws an exception if no offset is found for the consumer's group.
    • Typically used when you want strict control over offsets.

Example Configuration

Java Code

Properties props = new Properties();
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

application.yml for Spring Kafka

spring:
  kafka:
    consumer:
      auto-offset-reset: earliest

Use Cases for Different Values

  • earliest:

    • Data recovery or reprocessing.
    • Analytics jobs where you want to process all available data.
  • latest (default):

    • Stream processing where only new data is relevant.
    • Reduces latency as it avoids reprocessing historical messages.
  • none:

    • Scenarios where offsets must be explicitly managed or restored.

If you'd like help configuring auto.offset.reset for your use case, let me know!

댓글

이 블로그의 인기 게시물

To switch to a specific tag in a Git repository

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Using the MinIO API via curl

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Chromium 개발 환경 세팅, 크로미움 개발 준비하기

Joining an additional control plane node to an existing Kubernetes cluster

urllib3 with proxy settings

CDPEvents in puppeteer

Avro + Grpc in python