Python Confluent_kafka制作人不将消息发布到主题中

Python Confluent_kafka制作人不将消息发布到主题中,python,apache-kafka,confluent-platform,Python,Apache Kafka,Confluent Platform,我试图在我的树莓上安装卡夫卡。并在“你好,卡夫卡”主题上进行测试: ~ $ /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/k

我试图在我的树莓上安装卡夫卡。并在“你好,卡夫卡”主题上进行测试:

~ $ /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)
有脚本输出(无任何打印):

卡夫卡没有新的信息:

$ /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

有人能告诉我我做错了什么吗?

我打开日志,看到下一条消息:

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

它完全修复了这种情况。

正确的修复方法是在
server.properties
中更新代理配置,以正确设置播发的侦听器。如果您的客户端无法解析
raspberrypi
,请将播发的侦听器更改为客户端可以访问的内容,即IP地址:

advertised.listeners=PLAINTEXT://192.168.1.10:9092
在您的客户机上更改
/etc/hosts
文件是一种解决办法,对于使用树莓Pi的测试项目来说,这是一种不错的解决办法,但是作为一种一般的最佳实践,应该不鼓励这样做(因为客户机一旦移动到另一台没有
/etc/hosts
黑客攻击的机器上,它就会崩溃)

advertised.listeners=PLAINTEXT://192.168.1.10:9092