我试图在我的Raspberry上安装Kafka。并在“ hello-kafka”主题上对其进行测试:
~ $ /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic hello-kafka
>Test message 1
>Test message 2
>Test message 3
>^Z
[4]+ Stopped /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic hello-kafka
$ /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic hello-kafka --from-beginning
Test message 1
Test message 2
Test message 3
^CProcessed a total of 3 messages
然后,我尝试检查服务器是否在另一台计算机上正常工作。 检查动物园管理员:
(venv)$ telnet 192.168.1.10 2181
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
srvr
Zookeeper version: 3.6.0--b4c89dc7f6083829e18fae6e446907ae0b1f22d7, built on 02/25/2020 14:38 GMT
Latency min/avg/max: 0/0.8736/59
Received: 10146
Sent: 10149
Connections: 2
Outstanding: 0
Zxid: 0x96
Mode: standalone
Node count: 139
Connection closed by foreign host.
还有卡夫卡:
(venv) $ telnet 192.168.1.10 9092
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
tets
Connection closed by foreign host.
然后我写了一个Python脚本:
# -*- coding: utf-8 -*-
from confluent_kafka import Producer
def callback(err, msg):
if err is not None:
print(f'Failed to deliver message: {str(msg)}: {str(err)}')
else:
print(f'Message produced: {str(msg)}')
config = {
'bootstrap.servers': '192.168.1.10:9092'
}
producer = Producer(config)
producer.produce('hello-kafka', value=b"Hello from Python", callback=callback)
producer.poll(5)
有脚本输出(没有任何打印):
(venv) $ python kafka-producer.py
(venv) $ python kafka-producer.py
(venv) $
Kafka中没有新消息:
$ /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic hello-kafka --from-beginning
Test message 1
Test message 2
Test message 3
^CProcessed a total of 3 messages
$ ^C
有人可以告诉我我做错了什么吗?
答案 0 :(得分:1)
正确的解决方法是更新server.properties
中的代理配置,以正确设置播发的侦听器。如果您的客户端无法解析raspberrypi
,则将播发的侦听器更改为客户端 可以访问的地址,即IP地址:
advertised.listeners=PLAINTEXT://192.168.1.10:9092
在客户端上更改/etc/hosts
文件是一种解决方法,对于使用Raspberry Pi的测试项目来说可以,但是建议不要采用一般的最佳做法(因为客户端一旦移至没有的另一台具有/etc/hosts
骇客的计算机)
答案 1 :(得分:0)
我打开日志并看到下一条消息:
WARNING:kafka.conn:DNS lookup failed for raspberrypi:9092, exception was [Errno 8] nodename nor servname provided, or not known. Is your advertised.listeners (called advertised.host.name before Kafka 9) correct and resolvable?
ERROR:kafka.conn:DNS lookup failed for raspberrypi:9092 (AddressFamily.AF_UNSPEC)
然后我在客户端计算机上的/ etc / hosts中添加了下一个字符串:
192.168.1.10 raspberrypi
它完全解决了这种情况。