0

I am trying to set up a simple producer using confluent-kafka-python[1]. I copied the code 1:1, just changing the host and the topic. The code looks like this:

producer.py

from confluent_kafka import Producer
import socket

KAFKA_HOST = 'localhost:9092'
KAFKA_TOPIC = 'kafka-test'

conf = {'bootstrap.servers': KAFKA_HOST,
        'client.id': socket.gethostname()}

producer = Producer(conf)

def acked(err, msg):
    if err is not None:
        print("Failed to deliver message: %s: %s" % (str(msg), str(err)))
    else:
        print("Message produced: %s" % (str(msg)))

producer.produce(KAFKA_TOPIC, key="key", value="value", callback=acked)
producer.flush()
producer.poll(1)

It doesn't seem to understand the hostname, any idea why?

%3|1678057601.754|FAIL|rdkafka#producer-1| [thrd:ef6588a6e8f4:9092/1001]: ef6588a6e8f4:9092/1001: Failed to resolve 'ef6588a6e8f4:9092': nodename nor servname provided, or not known (after 3ms in state CONNECT)

[1] https://docs.confluent.io/kafka-clients/python/current/overview.html#ak-python

kev
  • 8,928
  • 14
  • 61
  • 103

0 Answers0