// 如果我说它不好,应该会有大佬走出来告诉我它应该怎么用,嗯!
我通过 docker 在本地部署 kafka,之后在容器内部用 console-producer 和 console-consumer 脚本试了一下,功能是正常的,但容器外使用 golang 程序( sarama )连接却无法成功
zookeeper 中的注册信息是这样的:
get /brokers/ids/1001
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://localhost:9092"],"jmx_port":-1,"host":"localhost","timestamp":"1585138788130","port":9092,"version":4}
docker 部署时使用的参数是:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_CREATE_TOPICS: "test:1:2"
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka 版本 2.4.0, zookeeper 版本 3.4.13
sarama 反馈信息:“kafka: client has run out of available brokers to talk to (Is your cluster reachable?)”
sarama log:
[sarama] 2020/03/25 20:41:02 client/metadata fetching metadata for all topics from broker 127.0.0.1:9092
[sarama] 2020/03/25 20:41:02 Connected to broker at 127.0.0.1:9092 (unregistered)
[sarama] 2020/03/25 20:41:02 client/metadata got error from broker -1 while fetching metadata: read tcp 127.0.0.1:52260->127.0.0.1:9092: read: connection reset by peer
[sarama] 2020/03/25 20:41:02 Closed connection to broker 127.0.0.1:9092
[sarama] 2020/03/25 20:41:02 client/metadata no available broker to send metadata request to
[sarama] 2020/03/25 20:41:02 client/brokers resurrecting 1 dead seed brokers
[sarama] 2020/03/25 20:41:02 Closing Client
kafka: client has run out of available brokers to talk to (Is your cluster reachable?)