`bootstrap_connected` is returning false even though connection is still there
I was trying to write a module to reconnect to Kafka after connection failure and i was using this kafka_producer.bootstrap_connected() to check if the connection is still there or not.
It is returning faulty value.
Libraries used
Python: 3.9.15
kafka-python: 2.0.2
Kafka: confluentinc/cp-kafka:7.0.1
Zookeeper: confluentinc/cp-zookeeper:7.0.1
Sample code
from kafka import KafkaProducer
import json
producer = KafkaProducer(bootstrap_servers=["localhost:9092"], value_serializer=lambda payload: payload.encode("utf-8"), key_serializer=lambda key: key.encode("utf-8"))
producer.bootstrap_connected() # returns True
producer.send(topic="test-topic", value='{"x": 1, "y": 2}',key="") # working
producer.bootstrap_connected() # returns False??
producer.flush()
producer.bootstrap_connected() # returns False
producer.send(topic="test-topic", value='{"key":"value"}',key="") # this is working although it just said bootstrap is not connected
producer.bootstrap_connected()
producer.flush()
Sample Screenshot
-
IPython

-
Broker

Have you found any solution?, I have a same problem with kafka-consumer module
Can confirm this is still happening.
Python: 3.10.9
kafka-python: 2.0.2
Kafka: Docker apache/kafka:3.7.2 (using KRaft)
This is expected. The "bootstrap" connections are exactly that: bootstraps. They are disconnected once the normal cluster connections are established. You can see this in the logs you posted. node_id=1 connects, node_id=bootstrap-0 disconnects...