Kafka节点-BrokerNotAvailableError

时间:2018-06-21 20:46:50

标签: node.js apache-kafka apache-zookeeper

我有一个kafka节点("kafka-node": "^2.6.1",)客户端,当我在localhost中运行节点应用程序并与remote_address:2181连接时,该客户端成功生成消息。但是,相同的代码在部署到测试服务器时会产生以下错误。

BrokerNotAvailableError: Broker not available
0|www      |     at new BrokerNotAvailableError (/var/www/backend/node_modules/kafka-node/lib/errors/BrokerNotAvailableError.js:11:9)
0|www      |     at Client.loadMetadataForTopics (/var/www/backend/node_modules/kafka-node/lib/client.js:371:15)
0|www      |     at Client.send (/var/www/backend/node_modules/kafka-node/lib/client.js:542:10)
0|www      |     at /var/www/backend/node_modules/kafka-node/lib/client.js:240:10
0|www      |     at /var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:473:16
0|www      |     at iteratorCallback (/var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:1064:13)
0|www      |     at /var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:969:16
0|www      |     at buildRequest (/var/www/backend/node_modules/kafka-node/lib/client.js:256:24)
0|www      |     at /var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:3110:16
0|www      |     at eachOfArrayLike (/var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:1069:9)
0|www      |     at eachOf (/var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:1117:5)
0|www      |     at Object.eachLimit (/var/www/backend/node_modules/kafka-node/node_modules/async/dist/async.js:3172:5)
0|www      |     at Client.sendProduceRequest (/var/www/backend/node_modules/kafka-node/lib/client.js:238:9)
0|www      |     at HighLevelProducer.BaseProducer.send (/var/www/backend/node_modules/kafka-node/lib/baseProducer.js:120:10)
0|www      |     at /var/www/backend/clients/3rdparty/kafka.js:104:16

可能的原因可能是remoteServer在端口2181处阻止了传入请求,但我能够在remote_address:2181进行telnet。这是我的代码:

const clientConfig = {
connectionString: process.env.KAFKA_HOST,
clientId: process.env.KAFKA_CLIENTID || 'nodejs-kafka-client'
}
client = new kafka.Client(clientConfig.connectionString, 
clientConfig.clientId)

producer = new kafka.HighLevelProducer(client, {})
bindListeners()

我了解到有关kafka-node回购的similar issue问题。提出此问题的人似乎使用某些zookeeper配置来解决。我使用zookeeper的默认配置。我不确定这是否是原因之一,因为我能够连接到本地主机。

2 个答案:

答案 0 :(得分:0)

对于你们所有人,尝试kafka-node。

尝试使用kafka.KafkaClient()而不是kafka.client()。它直接使用Kafka-broker,而不是通过zookeeper连接。

尽管如此,我确信zookeeper配置也可以更新为支持kafka.client()方式。但是我不确定实际的配置是什么。

答案 1 :(得分:0)

我在 /etc/hosts 中添加了 kafka IP

之后我就解决了这个问题