gpt4 book ai didi

python - LEADER_NOT_AVAILABLE - docker 容器

转载 作者:行者123 更新时间:2023-12-02 18:38:11 25 4
gpt4 key购买 nike

设置 docker 容器(kafka,zookeeper)并尝试从另一个容器(发布和)消费,收到以下错误:
KafkaError{code=LEADER_NOT_AVAILABLE,val=5,str="经纪人:领导者不可用"}
发布或消费时没有额外的错误提示。使用 telnet 172.18.0.3 9092 测试连接性时,我收到了预期的结果。

In [2]: c.list_topics()
Out[2]: ClusterMetadata(9ToJF8nPQC-rCTXGxuUalw)
In [3]: l = c.list_topics()
In [4]: l.brokers
Out[4]: {1010: BrokerMetadata(1010, 172.18.0.3:9092)}
In [7]: l.orig_broker_name
Out[7]: u'172.18.0.3:9092/1010'
In [8]: l.topics
Out[8]:
{'__consumer_offsets': TopicMetadata(__consumer_offsets, 50 partitions),
'item': TopicMetadata(item, 1 partitions),
'mytopic': TopicMetadata(mytopic, 1 partitions)}
In [9]: i =l.topics['item']
In [10]: i.partitions
Out[10]: {0: PartitionMetadata(-1, KafkaError{code=LEADER_NOT_AVAILABLE,val=5,str="Broker: Leader not available"})}

docker-compose.yml:
version: '2'
services:
zookeeper:
restart: always
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
restart: always
depends_on:
- zookeeper
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: "172.18.0.3"
KAFKA_ADVERTISED_PORT: "9092"
KAFKA_CREATE_TOPICS: "item:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock

ubuntu@STAGE:~/docker/kafka# sudo docker network inspect kafka_default
[
{
"Name": "kafka_default",
"Id": "fc8afcde4318599b66f540ebd6221cffe57382a70b43ed1d58eda7fe059e7a18",
"Created": "2018-07-25T13:29:56.034567548Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Containers": {
"7776db25d1ca9a3ec98775ff0dabe356409dda9f782a771c9b1f7ae4e04f3453": {
"Name": "test",
"EndpointID": "204158f6f167b12c06b2dcdda856992c5ea75adc80b06ac00f9abebb4f0179ba",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"b4869e44cf136a129701413c5a5dd371d15d6158bfaf577d30aeb6ad66b63263": {
"Name": "kafka_zookeeper_1", DEPTH_PRIORITY = 1
"EndpointID": "229b2587d92c8593d933d2583e09e669aa6f9a9c04e5b94ebf5a25be57aad27f",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"f682fd27ef52a40abf501348b5b16e59b48440041d1e4827ddb15a0ef8dbdd14": {
"Name": "kafka_kafka_1",
"EndpointID": "b17874d64c699635c471a1bcb515cb1441d22b2896e98a113115a4239caed460",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
} ]

最佳答案

始终尝试在 KAFKA_ADVERTISED_HOST_NAME 中使用公共(public) ip,您可以使用 KAFKA_HOST_NAME 指定实例的主机名。

此外,如果您使用的是最新的 kafka 版本,请使用 listeners 和 Advertisementd.listeners 而不是使用 host.name 和 Advertisementd.host.name。

关于python - LEADER_NOT_AVAILABLE - docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51577963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com