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

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

问题描述

当我运行两个具有完全相同属性的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天全站免登陆