DevOps | Cloud | Analytics | Open Source | Programming





How To Fix - Leader Not Available in Kafka Console Producer



This post explains How To Fix - Leader Not Available in Kafka Console Producer

Issue :


  • While producing message from CLI console , Kafka Gives below error -

LEADER\_NOT\_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

Reason :


  • Possibly the Kafka producer is trying to identify the leader for a given partition . In this process it tries to access below two property flags and tries to connect to them . However if these settings are not configured correctly it then may think that the leader is unavailable.

advertised.host.name 

advertised.port

  • Please note - if advertised.host.name is not configured , Kafka will use host.name. And the host.name is configured in server.properties file.
 

Fix 1 - For Local Set-up :


  • Make below changes to the server.properties file

port = 9092
advertised.host.name = localhost or 127.0.0.1
advertised.listeners=PLAINTEXT://YOUR\_IP:9092
listeners = PLAINTEXT://0.0.0.0:9092

 

Fix 2: Multi Node Setup :



advertised.listeners=PLAINTEXT://Kafka\_IP:9092
listeners = PLAINTEXT://0.0.0.0:9092

  Hope this helps - to Fix - Leader Not Available in Kafka Console Producer.   Additional Read -

 

leader not available kafka in console consumer, kafkacat broker: leader not available, leader not available kafka consumer, kafka producer error unknown_topic_or_partition, error while fetching metadata with correlation id leader_not_available consumer, failed to find leader in broker response giving up, embedded kafka leader_not_available, 1 partitions have leader brokers without a matching listener,