[英]Kafka consumer console subscribing to multiple topics
I use Ubuntu server 16.04 to try using Kafka. 我使用Ubuntu服务器16.04尝试使用Kafka。 For the command to start a producer and a consumer console I use the following.
对于启动生产者和消费者控制台的命令,我使用以下命令。
producer console : 制片人控制台
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic hello-topic
consumer console : 消费控制台:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic hello-topic
but the command above only subscribes to one topic. 但上面的命令只订阅了一个主题。 How can I subscribe to multiple topics?
我如何订阅多个主题?
First you should connect with the option bootstrap-server to the Kafka server itself not the zookeeper server. 首先,您应该将选项bootstrap-server连接到Kafka服务器本身而不是zookeeper服务器。
For multiple topics you use the whitelist option. 对于多个主题,您可以使用白名单选项。 This will get interpreted as a regular expression and has to get quoted, see Kafka documentation .
这将被解释为正则表达式并且必须引用,请参阅Kafka文档 。 So a correct command would be:
所以正确的命令是:
kafka-console-consumer.sh --bootstrap-server localhost:9092 --whitelist 'hello-topic|world-topic|another-topic'
Other expressions are also possible, like 其他表达也是可能的,比如
kafka-console-consumer.sh --bootstrap-server localhost:9092 --whitelist '.*'
BE AWARE 意识到
For convenience we allow the use of ',' instead of '|'
为方便起见,我们允许使用','而不是'|' to specify a list of topics.
指定主题列表。
Does not work with Kafka 2.0, perhaps only when mirroring, which I did not try yet. 不适用于Kafka 2.0,也许只有在镜像时,我还没有尝试过。
正如Harald所述,使用白名单/黑名单选项来包含/排除一组主题以供消费。
sh kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --whitelist Hello,World
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.