Spring-Kafka Concurrency Property

后端 未结 2 1770
忘掉有多难
忘掉有多难 2021-01-02 12:23

I am progressing on writing my first Kafka Consumer by using Spring-Kafka. Had a look at the different options provided by framework, and have few doubts on the same. Can so

2条回答
  •  渐次进展
    2021-01-02 13:01

    1. @KafkaListener is a message-driven "POJO" it adds stuff like payload conversion, argument matching, etc. If you implement MessageListener you can only get the raw ConsumerRecord from Kafka. See @KafkaListener Annotation.

    2. Yes, the concurrency represents the number of threads; each thread creates a Consumer; they run in parallel; in your example, each would get 2 partitions.

    Also should we consider anything if we are consuming in parallel.

    Your listener must be thread-safe (no shared state or any such state needs to be protected by locks.

    1. It's not clear what you mean by "handle rebalance events". When a rebalance occurs, the framework will commit any pending offsets.

    2. It doesn't make a difference; message listener Vs. batch listener is just a preference. Even with a message listener, with MANUAL ackmode, the offsets are committed when all the results from the poll have been processed. With MANUAL_IMMEDIATE mode, the offsets are committed one-by-one.

提交回复
热议问题