Failed to connect to seed broker with kafkajs

Rene B. picture Rene B. · Oct 31, 2019 · Viewed 10.6k times · Source

I am trying to use kafkajs in order to create a kafka consumer. However, I get already an error when connecting to kafka:

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

This is the code I am using:

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"
      ]
})

Does anyone has an idea why this error happens or how to solve it?

Answer

Rene B. picture Rene B. · Oct 31, 2019

In the end it was the missing ssl: true parameter. The solution was as follows:

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"
      ]
})