4

我正在尝试使用kafkajs以创建卡夫卡消费者。但是,连接到 kafka 时我已经收到错误:

"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Closed connection"

这是我正在使用的代码:

const { Kafka } = require('kafkajs')

const kafka = new Kafka({
  clientId: 'my-app',
  brokers: [
      "abc123f.xyz.cde.net:9094",
      "abc123h.xyz.cde.net:9094",
      "abc123k.xyz.cde.net:9094"
      ]
})

有谁知道为什么会发生此错误或如何解决它?

4

1 回答 1

12

最后是缺少的ssl: true参数。解决方案如下:

const { Kafka } = require('kafkajs')

const kafka = new Kafka({
  clientId: 'my-app',
  ssl: true,
  brokers: [
      "abc123f.xyz.cde.net:9094",
      "abc123h.xyz.cde.net:9094",
      "abc123k.xyz.cde.net:9094"
      ]
})
于 2019-10-31T13:57:26.547 回答