0

I am not being able to connect to Kafka using kafka.js. I am thinking that I am using the wrong kafka.js configuration.

Following are the items that are given to me :-


Host: kafka-xxx-xx.cloudclusters.net
Port: xxxxx
IP: xx.xx.xxx.xxx
Security Type: SCRAM-SHA-256
Trustore: kafka.truststore.jks (attached)
Trustore PW: xxxxx
Keystore: kafka.keystore.jks (attached)
Keystore PW: xxx

I am using the SSL configuration here :-

import { Kafka } from 'kafkajs';
import { Partitioners } from 'kafkajs';
import jks from 'jks-js';


const keystore = jks.toPem(fs.readFileSync('./kafka.keystore.jks'), 'my-password');

const trustore = jks.toPem(
  fs.readFileSync('./kafka.truststore.jks'),
  'my-password'
);

const {
  // caroot: { ca },
  localhost: { key, cert },
} = keystore;

const {
  caroot: { ca },
} = trustore;


// setting up kafka
const kafka = new Kafka({
  clientId: 'qa-topic',
  brokers: ['kafka-xxx-xx.cloudclusters.net:${port}'],

  ssl: {
    rejectUnauthorized: false,
    ca: ca,
    key: key,
    cert: cert,
    host: 'kafka-xxx-xx.cloudclusters.net',
  },
});

const producer = kafka.producer({
  createPartitioner: Partitioners.LegacyPartitioner,
});

await producer.connect().catch((e) => {
  console.log('ERROR happened ==>', e);
});


At the moment, I am getting the following error :-

cause: KafkaJSConnectionError: Connection timeout
      at Timeout.onTimeout [as _onTimeout] (/home/abdullah/web-socket-tradehat/node_modules/kafkajs/src/network/connection.js:223:23)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7) {
    retriable: true,
    helpUrl: undefined,
    cause: undefined,
    broker: 'kafka-xxx-xx.cloudclusters.net:${port}',
    code: undefined
  },
Abdullah Ch
  • 1,678
  • 1
  • 13
  • 31

0 Answers0