0

I've set up an instance of Apache Kafka via the Bitnami Kafka Image, localhost:9092, and created a topic ('testtopic'). I'm trying to write events to the topic from Python by creating a producer. The console producer and console consumer I'm using in the terminal appear to be working (i.e., I can write an event in the terminal with a console terminal and read those events with a console consumer), but I can't get the console consumer to read anything I try to write in via my python-initiated producer. Help is appreciated!

from kafka import KafkaProducer

producer = KafkaProducer(linger_ms=10)
TOPIC = 'testtopic'

msg = "Test message"
b_msg = bytearray(msg.encode("utf-8"))
producer.send(TOPIC, b_msg )
producer.flush()

I've tried editing some of the arguments I pass into the KafkaProducer, but I continue to get no response. I can print the messages I want to send, and if I loop through a series of messages, calling the send and flush methods on the producer class object, I can get all the messages to print, but none of them seem to write to the topic, but also no exceptions are raised.

2
  • if you did not create the topic beforehand, the first message will create the topic, and NOT be published Commented Feb 6, 2024 at 23:48
  • I did already create the topic Commented Feb 8, 2024 at 4:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.