0

我已经建立了一个 3 节点 kafka 集群并使用 python 作为生产者,如下所示:

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

当“n0”和“n1”可用但“n2”不可用(broker故障或网络错误)时,producer无法正常工作,发送到“n0n1”但抛出错误:

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?
4

1 回答 1

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
于 2017-01-10T05:23:37.387 回答