简体   繁体   English

可以在消费者或生产者中使用kafka broker ip?

[英]can use kafka broker ip in consumer or producer?

I have two machines localhost and 192.168.1.110 to run two independent single machine kafka. 我有两台机器localhost和192.168.1.110来运行两个独立的单机kafka。

(1)At localhost, I run: (1)在本地主机上,我运行:

➜ kafka_2.11-0.10.0.0 bin/kafka-console-producer.sh --broker-list 192.168.1.110:9092 --topic test this is a message [2016-08-24 18:15:27,441] ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback) org.apache.kafka.common.errors.TimeoutException: Batch containing 1 record(s) expired due to timeout while requesting metadata from brokers for test-0 ➜kafka_2.11-0.10.0.0 bin / kafka-console-producer.sh --broker-list 192.168.1.110:9092 --topic test这是一条消息[2016-08-24 18:15:27,441]错误发送消息到主题测试,键为:空,值:2个字节,错误为:(org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)org.apache.kafka.common.errors.TimeoutException:包含1条记录的批处理)由于超时而过期,同时从代理请求test-0的元数据

Why message can't be sent to broker at 192.168.1.110? 为什么无法将邮件发送到192.168.1.110的代理? could I use broker ip directly in consumer or producer? 我可以直接在消费者或生产者中使用Broker ip吗? If I could only use hostname, does this relate to advertised.host.name? 如果我只能使用主机名,这与advertised.host.name有关吗? then how to set up advertised.host.name? 那么如何设置advertised.host.name? does this host name should be globally resolvable(could I use /etc/hosts to resolve the host name?) 该主机名是否应该是全局可解析的(我可以使用/ etc / hosts来解析主机名吗?)

(2) I edited /etc/hosts to let localhost point to 192.168.1.110, then I run: ➜ kafka_2.11-0.10.0.0 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test (2)我编辑/ etc / hosts以使localhost指向192.168.1.110,然后运行:➜kafka_2.11-0.10.0.0 bin / kafka-console-producer.sh --broker-list localhost:9092 --topic测试

and I could successfully sent messages to 192.168.1.110 and consumed the messages there. 这样我就可以成功地将邮件发送到192.168.1.110并在其中使用了邮件。

(3)I edited /etc/hosts to let rrlocalhost point to 192.168.1.110, then I run: ➜ kafka_2.11-0.10.0.0 bin/kafka-console-producer.sh --broker-list rrlocalhost:9092 --topic test (3)我编辑了/ etc / hosts以使rrlocalhost指向192.168.1.110,然后运行:➜kafka_2.11-0.10.0.0 bin / kafka-console-producer.sh --broker-list rrlocalhost:9092 --topic测试

then I sent messages to rrlocalhost, there is the same error as in (1). 然后我将消息发送到rrlocalhost,与(1)中存在相同的错误。

Definitely you can use ip address directly. 绝对可以直接使用ip地址。

broker config advertised.host.name will be registered in zookeeper, and producer and consumer will fetch them as cluster metadata. 代理配置advertised.host.name将在zookeeper中注册,生产者和消费者将以集群元数据的形式获取它们。 If you config it using local nick name, producer and consumer will be trouble to communicate with it. 如果使用本地昵称配置它,则生产者和使用者将很难与它进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM