Skip to content

AckCount is invalid when ackMode is Count and ackCount is less than maxPollRecords  #2731

Closed
@wapkch

Description

@wapkch

Expected Behavior

Assume we have following settings:

application.properties

spring.kafka.listener.ack-mode=count
spring.kafka.listener.ack-count=100
logging.level.org.springframework.kafka=debug

Expect to commit offset every 100 messages processed

SpringBoot Application:

@RestController
@SpringBootApplication
public class SpringKafkaDemo2Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringKafkaDemo2Application.class, args);
    }

    @KafkaListener(id = "fooGroup", topics = "topic")
    public void listen(ConsumerRecord<String, String> record) throws Exception {
    }

    @Autowired
    private KafkaTemplate<Object, Object> template;

    @PostMapping(path = "/send/{what}")
    public void sendFoo(@PathVariable String what) {
        for (int i = 0; i < 500; i++) {
            this.template.send("topic", "message" + i);
        }
    }

}

Current Behavior

Committing the offset every time after 500 records processed:

2023-07-06T18:07:36.680+08:00 DEBUG 26195 --- [ fooGroup-0-C-1] o.s.k.l.KafkaMessageListenerContainer    : Committing in COUNT because count 500 exceeds configured limit of 100
2023-07-06T18:07:36.680+08:00 DEBUG 26195 --- [ fooGroup-0-C-1] o.s.k.l.KafkaMessageListenerContainer    : Commit list: {topic-0=OffsetAndMetadata{offset=560, leaderEpoch=null, metadata=''}}
2023-07-06T18:07:36.680+08:00 DEBUG 26195 --- [ fooGroup-0-C-1] o.s.k.l.KafkaMessageListenerContainer    : Committing: {topic-0=OffsetAndMetadata{offset=560, leaderEpoch=null, metadata=''}}

Context
Although the larger the ackCount, the better the performance, but it will increase the chance of retransmission, so sometimes it is useful for the ackCount to be smaller than maxPollRecords

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions