我已经设置了一个3节点kafka集群,并使用python作为生产者:
mysql-connector-java-5.1.39.jar
当“n0”和“n1”可用但“n2”不可用时(代理商故障或网络错误),生产者无法正常工作,发送到“n0n1”但抛出错误:
kafka_addr = "n0.xxx.com:9092,n1.xxx.com:9092,n2.xxx.com:9092"
producer = KafkaProducer(bootstrap_servers=kafka_addr)
答案 0 :(得分:1)
我试图找到一个可用的经纪人并发送给它:
kafka_addr = ["n0.xxx.com:9092","n1.xxx.com:9092",n2.xxx.com:9092"]
producer = None
for broker in kafka_addr:
try:
producer = KafkaProducer(bootstrap_servers=broker)
break
except:
pass
if producer is not None:
#do something