问题是这样的,
我在服务器上跑了一个 Kafka,是跑的 wurstmeister/kafka 镜像,使用的默认网络。配置:
kafka:
image: wurstmeister/kafka
container_name: kafka
environment:
- KAFKA_ADVERTISED_PORT=port
- KAFKA_ADVERTISED_HOST_NAME=公网 ip
- KAFKA_ZOOKEEPER_CONNECT=本机内网 ip:zookeeper port
- KAFKA_LOG_RETENTION_HOURS=4
- KAFKA_LOG_RETENTION_BYTES=1000000000
ports:
- port:9092
然后在同一台服务器,使用 docker run 命令,启动了另外一个容器,使用的是 node-alpine 镜像,内部通过 kafka-node 库连接 kafka,怎么都连不上。
启动 node 容器后,进入容器,telnet 命令可以连上 Kafka 容器的端口。
在本机,不在容器内部,同一个连接(公网 ip:port )可以正常连上 Kafka。
我在本机装了 Conduktor 这个 Kafka 客户端,也能连上 Kafka,可以正常收发消息。
有什么思路吗?谢谢!
启动 kafka,然后启动 node,看 node 镜像的日志就会卡住。然后 stop Kafka,node 这边就会报错:
events.js:174
throw er; // Unhandled 'error' event
^
NestedError: refreshBrokerMetadata failed
at async.waterfall (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:378:35)
at /app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:473:16
at next (/app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:5329:29)
at /app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:969:16
at KafkaClient.getAvailableBroker (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:330:12)
at async.waterfall.callback (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:373:23)
at nextTask (/app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:5324:14)
at Object.waterfall (/app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:5334:5)
at KafkaClient.refreshBrokerMetadata (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:372:9)
at Immediate._onImmediate (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:782:20)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
Caused By: Error: Unable to find available brokers to try
at KafkaClient.getAvailableBroker (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:330:21)
at async.waterfall.callback (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:373:23)
at nextTask (/app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:5324:14)
at Object.waterfall (/app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:5334:5)
at KafkaClient.refreshBrokerMetadata (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:372:9)
at Immediate._onImmediate (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:782:20)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
Emitted 'error' event at:
at KafkaClient.<anonymous> (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/baseProducer.js:101:10)
at KafkaClient.emit (events.js:198:13)
at async.waterfall (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:378:21)
at /app/node_modules/daoqun-core/node_modules/kafka-node/node_modules/async/dist/async.js:473:16
[... lines matching original stack trace ...]
at KafkaClient.refreshBrokerMetadata (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:372:9)
at Immediate.<anonymous> (/app/node_modules/daoqun-core/node_modules/kafka-node/lib/kafkaClient.js:782:20)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.