1

I am writing a Python application which connects to a Kafka queue and sends a message to the queue. I have the following working code:

def send_msg(self, topic, msg):
    self.producer = KafkaProducer(bootstrap_servers=['XX.XXX.XX.XXX:XXXX'])
    future = self.producer.send(topic, msg)
    self.producer.flush()

I want to add the standard try-catch expressions in this code so that I can catch any kind of exceptions that I might face. What are the various exceptions like connection, timeout, NoBrokersAvailable and how should I properly handle them?

Thanks in advance!

activelearner
  • 7,055
  • 20
  • 53
  • 94

1 Answers1

0

Set advertised.listeners=PLAINTEXT://<broker_ip>:9092 in server.properties. Restart your kafka-server and consumer and try again.

Please find my answer given in another thread, same problem as yours. NoBrokersAvailable: NoBrokersAvailable-Kafka Error

somnathchakrabarti
  • 3,026
  • 10
  • 69
  • 92