Search code examples
apache-kafkakafka-producer-apipykafka

Cant send message by using pykafka


I am using pykafka, I can get topic names but I cant send message. My code is shown below

client = KafkaClient(hosts='xx.xx.xx.xx:9092')
topic = client.topics['test']
producer = topic.get_sync_producer()
producer.produce(b"message") 

And I get this error message

raise ProduceFailureError("Delivery report not received after timeout")
pykafka.exceptions.ProduceFailureError: Delivery report not received after timeout 

Solution

  •     broker.id=1
        listeners=PLAINTEXT://localhost:9092 
    

    I am sending to an external IP message

    If you are setting hosts=some.external.IP:9092, then you need to edit Kafka properties with advertised.listeners=PLAINTEXT://some.external.IP:9092 and make listeners=PLAINTEXT://:9092 to listen on external interfaces.

    Listing the topics uses a different protocol, which is why it works fine.