简体   繁体   English

Kafka多个消费者正在收听多个主题

[英]Kafka multiple Consumers listening for multiple topics

We are working on an application where we want to listen for more than one topics in Kafka. 我们正在开发一个应用程序,我们希望在Kafka中收听多个主题。 All the topics have a single partition. 所有主题都有一个分区。 All the topic names will have a common prefix eg "test-x", "test-y" so we can use spring topicPattern for it. 所有主题名称都将具有公共前缀,例如“ test-x”,“ test-y”,因此我们可以对其使用spring topicPattern

We wanted to write a java spring consumer which listens to all the topics using regexp pattern. 我们想编写一个java spring使用者,它使用regexp模式来监听所有主题。 Our idea was, we can run multiple instances of the same consumer(belonging to the same group) and Kafka will distribute messages from different topics for different consumers. 我们的想法是,我们可以运行同一个使用者(属于同一组)的多个实例,Kafka将为不同的使用者分发来自不同主题的消息。

However, This seems to be not working. 但是,这似乎不起作用。 Even if we are running multiple instances of the consumer only one consumer is getting messages from all the topics. 即使我们正在运行使用者的多个实例,也只有一个使用者从所有主题中获取消息。 If we create more than one partition in the topic then it works but that's something we won't have. 如果我们在主题中创建多个分区,则该分区可以工作,但这是我们所没有的。

Is there anything which we have not understood here? 这里有我们不了解的东西吗? Thanks in advance. 提前致谢。

Kafka distributes partitions within a topic among a consumer group(consumers with same group.id). Kafka将主题内的分区分配到一个消费者组(具有相同group.id的消费者)中。 Since your topic has only partition, only one of the consumer in a consumer group would receive the message. 由于您的主题只有分区,因此使用者组中只有一个使用者会收到此消息。

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

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