我正在尝试使用kafkajs
来创建一个kafka消费者。然而,当连接到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"
]
})
有人知道为什么会发生这种错误或如何解决吗?
最后是缺少的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"
]
})