In this post , we will try to find How to Fix Kafka Python Error - "NoBrokersAvailable". While using Kafka with python, at times at gives the below error -
raise Errors.NoBrokersAvailable()
kafka.errors.NoBrokersAvailable: NoBrokersAvailable
It can occur in Any of the below instances while using the "kafka" package in python
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['<KAFKA_BROKER_HOST>:<KAFKA_BROKER_IP>'], <OTHER_CONFIG_PARMS>)
Case-2
from kafka import KafkaConsumer
consumer = KafkaConsumer(bootstrap_servers='<KAFKA_BROKER_HOST>:<KAFKA_BROKER_IP>', <OTHER_CONFIG_PARMS>)
First thing first, you need to check if the Kafka Broker Host & Ip used in the "bootstrap_servers" are correct . Many a times , due to changing network , the Host & Ip might be different (case of a Public or Static IP thing) every time you boot your application.
config. listeners=PLAINTEXT://<Broker_ip:<Port>
advertised.listeners=PLAINTEXT://<Broker_ip:<Port>
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['localhost:ip'],
api_version=(0, 10, 1) , <OTHER_CONFIG_PARMS>)
from kafka import KafkaConsumer
producer = KafkaConsumer(bootstrap_servers=['localhost:ip'],
api_version=(0, 10, 1) , <OTHER_CONFIG_PARMS>)
Hope this helps to solve the issue.
Other Interesting Reads -
kafka nobrokersavailable , nobrokersavailable kafka python , kafka python nobrokersavailable