简体   繁体   English

kafka 应用程序的多个使用者可以在同一个线程上工作吗?

[英]Can multiple consumers of kafka application work on the same thread?

On the below diagram from the Confluent site we can see that multiple consumer tasks can work on the same thread.在下图来自Confluent 站点,我们可以看到多个消费者任务可以在同一个线程上工作。 My question is that if an application consists of multiple consumers (that can read from different topics) can it happen that some of those consumers would work on a single thread.我的问题是,如果一个应用程序由多个消费者(可以从不同的主题读取)组成,其中一些消费者会在单个线程上工作吗?

I am asking this because I also read that:我问这个是因为我也读到了:

You can't have multiple consumers that belong to the same group in one thread (...)您不能在一个线程中拥有多个属于同一组的消费者 (...)

which would suggest that in general, it is possible for consumers to share a thread, and that if we tried to set the same group to multiple consumers from a single application, it could sometimes not work.这表明一般来说,消费者可以共享一个线程,并且如果我们尝试从单个应用程序将同一组设置为多个消费者,则有时可能无法正常工作。 And I did observe behaviour that would match it: when I set the same group for all application consumers, only a part of them did work.我确实观察到了与之匹配的行为:当我为所有应用程序使用者设置相同的组时,只有其中的一部分起作用。

The second question is why when I set num.stream.threads to a number greater to the number of consumers it didn't help.第二个问题是为什么当我将 num.stream.threads 设置为大于消费者数量的数字时,它没有帮助。

can it happen that some of those consumers would work on a single thread这些消费者中的一些会在单个线程上工作吗?

No. Kafka Streams create threads based on num.stream.threads config and will create a single KafkaConsumer per thread.num.stream.threads Streams 基于num.stream.threads配置创建线程,并将为每个线程创建一个KafkaConsumer

The second question is why when I set num.stream.threads to a number greater to the number of consumers it didn't help.第二个问题是为什么当我将 num.stream.threads 设置为大于消费者数量的数字时,它没有帮助。

What do you mean by "great to the number of consumers".你所说的“对消费者的数量很大”是什么意思。 There is no "number-of-consumer" config.没有“消费者数量”配置。

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

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