babboon
babboon

Reputation: 793

KafkaListener ConsumerConfig AUTO_OFFSET_RESET_DOC earliest for multiple listeners

I have 3 listeners in my spring boot application. Only one listener should read topic from beginning. If I add to the yml file: spring.kafka.consumer.auto-offset-reset: earliest then it works for all listeners, but I need it only for one. I have added:

import static org.apache.kafka.clients.consumer.ConsumerConfig.AUTO_OFFSET_RESET_DOC;
......
@KafkaListener(groupId = "${random.uuid}",
            properties = {AUTO_OFFSET_RESET_DOC + ":earliest"})

But it did not work, settings was not picked up as I see printed settings on a launch:

ConsumerConfig values: 
    auto.commit.interval.ms = 5000
    auto.offset.reset = latest

Any ideas how to do that?

Upvotes: 1

Views: 2165

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 40048

Your are providing wrong config it should be AUTO_OFFSET_RESET_CONFIG not AUTO_OFFSET_RESET_DOC

@KafkaListener(groupId = "${random.uuid}",
        properties = {AUTO_OFFSET_RESET_CONFIG + ":earliest"})

or you can specify the property directly

@KafkaListener(groupId = "${random.uuid}",
        properties = {"auto.offset.reset = earliest"})

From doc @KafkaListener annotation there is a field called properties which accepts String array

Kafka consumer properties; they will supersede any properties with the same name defined in the consumer factory (if the consumer factory supports property overrides).

Supported Syntax

The supported syntax for key-value pairs is the same as the syntax defined for entries in a Java properties file:

key=value
key:value
key value

group.id and client.id are ignored.

Upvotes: 3

Related Questions