简体   繁体   English

Spring 卡夫卡监听器

[英]Spring Kafka Listener

I am using KafkaListener to listen multiple topics and each topic has 20 partitions and below is my configuration.我正在使用 KafkaListener 监听多个主题,每个主题有 20 个分区,以下是我的配置。 So here Does each topic will share same 20 threads (OR) each topic will get its own 20 threads?那么这里每个主题将共享相同的 20 个线程(或)每个主题将获得自己的 20 个线程吗?

import org.springframework.kafka.annotation.KafkaListener;导入 org.springframework.kafka.annotation.KafkaListener;

KafkaListener(topics = { "topic1", "topic2","topic3"},
        concurrency = "20",
        clientIdPrefix = "client1",
        groupId = "group1")

There will be 20 threads, each consuming from one partition of each topic.将有 20 个线程,每个线程从每个主题的一个分区消费。

If you want separate threads, you can add 3 @KafkaListener annotations to the method, each configured with 1 topic, or set the concurrency to 60 and use a custom partition assignor to make sure each consumer only gets one partition.如果你想要单独的线程,你可以在方法中添加 3 个@KafkaListener注解,每个配置有 1 个主题,或者将并发设置为 60 并使用自定义分区分配器来确保每个消费者只获得一个分区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM