使用python连接kafka集群做producer,如何保证部分broker不可用时仍然正常发送?

producer的代码:

kafka_addr = "n0.xxx.com:9092,n1.xxx.com:9092,n2.xxx.com:9092"
producer = KafkaProducer(bootstrap_servers=kafka_addr)

问题:
当部分broker挂掉或者网络不通(比如n2)而至少有一个broker可用时,producer报错:

getaddrinfo failed for n2.xxx.com:9092, exception was [Errno 8] nodename nor servname provided, or not known. Is your advertised.host.name correct and resolvable?

如何保证这种情况下也能正常工作?

查看回复

相关问答