My snippet looks like this, and the logic is if the brokers are available then the producer is not None.
try:
self.producer = KafkaProducer(bootstrap_servers=broker_list)
except kafka.errors.NoBrokersAvailable:
self.producer = None
But, in this way, there will be a lot of logs printed if the brokers are not available. How can I avoid this?
2020-03-12 13:42:01 INFO <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]>: connecting to device2:9092 [('192.168.0.102', 9092) IPv4]
2020-03-12 13:42:01 INFO Probing node bootstrap-1 broker version
2020-03-12 13:42:01 ERROR Connect attempt to <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]> returned error 111. Disconnecting.
2020-03-12 13:42:01 INFO <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]>: Closing connection. KafkaConnectionError: 111 ECONNREFUSED
2020-03-12 13:42:01 INFO <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]>: connecting to device2:9092 [('192.168.0.102', 9092) IPv4]
2020-03-12 13:42:01 ERROR Connect attempt to <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]> returned error 111. Disconnecting.
2020-03-12 13:42:01 INFO <BrokerConnection node_id=bootstrap-1 host=device2:9092 <connecting> [IPv4 ('192.168.0.102', 9092)]>: Closing connection. KafkaConnectionError: 111 ECONNREFUSED
2020-03-12 13:42:01 INFO <BrokerConnection node_id=bootstrap-0 host=device1:9092 <connecting> [IPv4 ('192.168.0.101', 9092)]>: connecting to device1:9092 [('192.168.0.101', 9092) IPv4]