具有新 API 的 Kafka 消费者不起作用 [英] Kafka consumer with new API not working

查看:23
本文介绍了具有新 API 的 Kafka 消费者不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 Kafka 有一些很奇怪的东西.

I found something very weird with Kafka.

我有一个有 3 个经纪人的制作人:

I have a producer with 3 brokers :

bin/kafka-console-producer.sh --broker-list localhost:9093, localhost:9094, localhost:9095 --topic topic

然后我尝试使用新 API 运行消费者:

Then I try to run a consumer with the new API :

bin/kafka-console-consumer.sh --bootstrap-server localhost:9093,localhost:9094,localhost:9095 --topic topic --from-beginning

我什么都没有!但是如果我使用旧的 API :

I got nothing ! BUT if I use the old API :

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic topic

我收到了我的消息!

我怎么了?

PS:我使用的是 Kafka 10

PS : I am using Kafka 10

推荐答案

由于这篇类似的帖子,我最终解决了我的问题:Kafka bootstrap-servers 与 kafka-console-consumer 中的 zookeeper

I eventually resolved my problem thanks to this similar post : Kafka bootstrap-servers vs zookeeper in kafka-console-consumer

我认为这是我的错误/错误配置导致zookeeper和kafka出现问题.

I believe it is a bug / wrong configuration of mine leading to a problem with zookeeper and kafka.

解决方案:

首先确保在您的经纪人的 server.properties 文件中启用主题删除:

First be sure to have enable topic deleting in server.properties files of your brokers :

# Switch to enable topic deletion or not, default value is false
delete.topic.enable=true

然后删除主题:

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic myTopic

删除您的经纪人的所有 /tmp/log.dir 目录.

Remove all the /tmp/log.dir directories of your brokers.

EDIT :我再次遇到了这个问题,我不得不删除 /tmp/zookeeper/version-2/ 中的 zookeeper 日志文件.

EDIT : I faced again the problem and I had to remove also the log files of zookeeper in /tmp/zookeeper/version-2/.

最后在zookeeper中删除/brokers/topics中的topic如下:

Finally delete the topic in /brokers/topics in zookeeper as follow :

$ kafka/bin/zookeeper-shell.sh localhost:2181
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is disabled

rmr /broker/topics/mytopic

然后重新启动您的代理并再次创建您的主题.

And restart your brokers and create your topic again.

这篇关于具有新 API 的 Kafka 消费者不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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