Failed to connect to seed broker with kafkajs
Asked Answered
D

1

7

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?

Dormitory answered 31/10, 2019 at 13:22 Comment(0)
D
16

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"
      ]
})
Dormitory answered 31/10, 2019 at 13:57 Comment(5)
What is the clientId here? I have started kafka on my console and want my react code to consume a message.Cofferdam
@DhirajGandhi This is just a meaningful name you choose for the client applicationDoublecross
If you enabled ssl, don't you also need certs?Shied
SSL requires certificate and key. This answer seems to be incomplete without info about certs and keysClapp
@ParzhfromUkraine I think you meant TLSTransmit

© 2022 - 2025 — McMap. All rights reserved.