如何在同一个消费者组中运行两个控制台消费者? [英] How to run two console consumers in the same consumer group?

查看:27
本文介绍了如何在同一个消费者组中运行两个控制台消费者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行具有完全相同属性的两个 Kafka-console-consumers 实例(使用默认的一个 config/consumer.properties)时,我在两个实例上都收到相同的消息.

When I run two instances of Kafka-console-consumers with the exact same properties (using the default one config/consumer.properties), I get same messages on both the instances.

./bin/kafka-console-consumer.sh --bootstrap-server :9092 --topic test1

如果两个实例具有相同的消费者组 ID,那么 Kafka 不应该只向其中一个消费者发送给定的消息吗?如何将它们作为一个消费者群体运行?

If both the instances have the same consumer group id, shouldn't Kafka send a given message to only one of the consumers? How to run them as one consumer group?

推荐答案

我从 kafka 文档中找到了这个

From kafka docs i found this

当没有提供 group.id 时,控制台使用者的 enable.auto.commit 属性的默认值现在设置为 false.这是为了避免污染消费者协调器缓存,因为其他消费者不太可能使用自动生成的组.

The default for console consumer's enable.auto.commit property when no group.id is provided is now set to false. This is to avoid polluting the consumer coordinator cache as the auto-generated group is not likely to be used by other consumers.

但这里有诀窍,使用此命令列出所有主题的所有消费者组,正如您所说,我已经打开了四个控制台消费者,我想检查从该主题消费的消费者组列表

But here is the trick, use this command to list all consumer groups across all topics, as you said i have opened four console consumers and i want to check list of consumer groups consuming from that topic

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list

每个控制台消费者都以不同的组ID开始,这就是总是从开始添加这个属性开始消费的原因(--from-beginning)

Every console consumer start with different group id, this is the reason always consuming from beginning addition of this property (--from-beginning)

ups.sh --bootstrap-server localhost:9092 --list
Note: This will not show information about old Zookeeper-based consumers.
console-consumer-66835
console-consumer-38647
console-consumer-18983
console-consumer-18365
console-consumer-96734

为控制台消费者设置 group.id 的最简单方法

Okay easiest way to set group.id for console consumer

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer-property group.id=test1

阅读管理消费者组.

这篇关于如何在同一个消费者组中运行两个控制台消费者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆