简体   繁体   English

在 Camel-Kafka 中创建并发 Kafka 消费者

[英]Create concurrent Kafka consumers in Camel-Kafka

I'm using camel-kafka version 2.14.3 .我正在使用 camel-kafka 版本2.14.3 Below is the kafka URI:以下是kafka URI:

<from uri="kafka:{brokerlist}?topic={topic-name}&amp;zookeeperHost={zookeeperHost}&amp;zookeeperPort={zookeeperPort}&amp;groupId={groupId-name}&amp;consumerStreams=2" />

note that I have used consumerStream=2 in URI options.请注意,我在 URI 选项中使用了consumerStream=2 But when I publish multiple messages to the topic topic-name at once (all to the same partition), the kafka consumer receives those messages sequentially.但是当我一次向主题topic-name发布多条消息(全部到同一个分区)时,kafka 消费者会按顺序接收这些消息。 How can receives those messages parallely?如何并行接收这些消息?

I'm looking for a solution like below:我正在寻找如下解决方案:

<from uri="ibm_bean_name:queue_name?concurrentConsumers=2" /> 

is what I use to read concurrently from an ibm MQ是我用来从 ibm MQ 并发读取的内容

The partition is Kafka's unit of parallelism.分区是 Kafka 的并行单位。 Each partition will be assigned to a single consumer in a given consumer-group.每个分区将分配给给定消费者组中的单个消费者。 You said you are producing to a single partition.您说您正在生产单个分区。 That means all the messages will go to a single consumer, regardless of how many consumers you have in the group.这意味着所有消息都将 go 发送给单个消费者,无论组中有多少消费者。 If you want the messages to go to different consumers, you need to produce to different partitions.如果要将 go 的消息发送给不同的消费者,则需要生产到不同的分区。

If you have N partitions, then you can have up to N consumers within the same consumer group each of which reading from a single partition.如果你有 N 个分区,那么在同一个消费者组中最多可以有 N 个消费者,每个消费者都从一个分区中读取。 When you have less consumers than partitions, then some of the consumers will read from more than one partition.当您的消费者少于分区时,一些消费者将从多个分区中读取。 Also, if you have more consumers than partitions then some of the consumers will be inactive and will receive no messages at all.此外,如果您的消费者多于分区,那么一些消费者将处于非活动状态并且根本不会收到任何消息。

If you have one consumer per partition, then some of the partitions might receive more messages and this is why some of your consumers might be idle while some others might still processing some messages.如果每个分区有一个消费者,那么某些分区可能会收到更多消息,这就是为什么您的一些消费者可能处于空闲状态而另一些可能仍在处理一些消息的原因。 Note that messages are not always inserted into topic partitions in a round-robin fashion as messages with the same key are placed into the same partition.请注意,消息并不总是以循环方式插入到主题分区中,因为具有相同键的消息被放置到同一个分区中。

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

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