Мой фрагмент выглядит следующим образом, и логика c - это если брокеры доступны, тогда производитель не None.
try:
self.producer = KafkaProducer(bootstrap_servers=broker_list)
except kafka.errors.NoBrokersAvailable:
self.producer = None
Но, таким образом, будет много логов печатается, если брокеры не доступны. Как я могу избежать этого?
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]