【发布时间】:2018-08-29 15:34:21
【问题描述】:
我在使用引导服务器(即 Kafka 服务器)使用消息时遇到问题。知道为什么没有 zookeeper 就不能消费消息吗?
- 卡夫卡版本:kafka_2.11-1.0.0
- 动物园管理员版本:kafka_2.11-1.0.0
- Zookeeper 主机和端口:zkp02.mp.com:2181
- Kafka 主机和端口:kfk03.mp.com:9092
产生一些信息:
[kfk03.mp.com ~]$ /bnsf/kafka/bin/kafka-console-producer.sh --broker-list kfk03.mp.com:9092 --topic test
>hi
>hi
如果我给–-bootstrap-server,消费者将无法消费消息:
[kfk03.mp.com ~]$
/bnsf/kafka/bin/kafka-console-consumer.sh --bootstrap-server kfk03.mp.com:9092 --topic test --from-beginning
当给定--zookeeper 服务器而不是--bootstrap-server 时,消费者可以消费消息 -:
[kfk03.mp.com ~]$ /bnsf/kafka/bin/kafka-console-consumer.sh --zookeeper zkp02.mp.com:2181 --topic test --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
hi
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
{"properties": {"messageType": "test", "sentDateTime": "2018-02-25T21:46:00.000+0000"}, "name": "Uttam Anand", "age": 29}
hi
hi
uttam
hi
hi
hi
hello
hi
^CProcessed a total of 17 messages
【问题讨论】:
-
server.properties broker.id=0 listeners=PLAINTEXT://:9092 port=9092 host.name=kfk03.mp.com advertised.host.name=kfk03.mp.com Advertisementd.port =9092 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/bnsf/ kafka-logs num.partitions=1 num.recovery.threads.per.data.dir=1 log.retention.hours=1440 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 zookeeper.connect= zkp02.mp.com:2181 zookeeper.connection.timeout.ms=60000
-
较新版本的 Kafka 将一些进程从 zookeeper 转移到 Kafka 代理中。这使他们能够保护 zookeeper 免受意外中断的影响。虽然在 zookeeper 中保留了主要的操作功能。这就是为什么当 --zookeeper 没有给出 --bootstrap-server 时,你的消费者能够消费消息
标签: apache-kafka producer-consumer