kafka-python: producer is not able to connect

后端 未结 7 2129
你的背包
你的背包 2020-12-16 00:29

kafka-python (1.0.0) throws error while connecting to the broker. At the same time /usr/bin/kafka-console-producer and /usr/bin/kafka-console-consumer work fine.

Pyt

7条回答
  •  执笔经年
    2020-12-16 01:17

    I had the same problem.

    I solved the problem with hint of user3503929.

    The kafka server was installed on windows.

    server.properties

    ...
    host.name = 0.0.0.0
    ...
    

    .

    producer = KafkaProducer(bootstrap_servers='192.168.1.3:9092',         
                                             value_serializer=str.encode)
    producer.send('test', value='aaa')
    producer.close()
    print("DONE.")
    

    There was no problem with the processing in the windows kafka client. However, when I send a message to topic using kafka-python in ubuntu, a NoBrokersAvailable exception is raised.

    Add the following settings to server.properties.

    ...
    advertised.host.name = 192.168.1.3
    ...
    

    It runs successfully in the same code. I spent three hours because of this.

    Thanks

提交回复
热议问题