1

The credentials that I am provided with :- (I also have kafka.keystore.jks and kafka.truststore.jks)

host: xxxxx-xxxxx-x.cloudclusters.net
port: xxxxx
ip: xxx.xxx.xxx.xx
trustore pw: xxxxxxxx
keystore pw: xxxxxxxx
import WebSocket from 'ws';
import express from 'express'
import { Kafka } from 'kafkajs';
import { Partitioners } from 'kafkajs';
import jks from 'jks-js';
import fs from 'fs';

const keystore = jks.toPem(
    fs.readFileSync('./kafka.keystore.jks'),
    'mypassword'
);

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

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

console.log("**************** kafka.keystore.jks ****************");
// console.log(keystore)

console.log("ca ===>", ca); // getting the keys
console.log("key ===>", key);
console.log("cert ===>", cert);

console.log("**************** kafka.truststore.jks ****************");
// console.log(trustore)
// console.log("ca ===>", ca);


// setting up kafka
const kafka = new Kafka({
  clientId: 'qa-topic',
  brokers: ['xxxx.cloudclusters.net:xxxx'], // HOST:PORT
  ssl: {
    rejectUnauthorized: false,
    ca: ca,
    key: key,
    cert: cert
  },
 
})

const producer = kafka.producer({ createPartitioner: Partitioners.DefaultPartitioner })

producer.on('producer.connect', () => {
  console.log(`KafkaProvider: connected`);
});
producer.on('producer.disconnect', () => {
  console.log(`KafkaProvider: could not connect`);
});
producer.on('producer.network.request_timeout', (payload) => {
  console.log(`KafkaProvider: request timeout ${payload.clientId}`);
});

await producer.connect().catch((e) => {
  console.log("ERROR happened ==>",e) // Getting Connection Timeout Error
})


const port = process.env.PORT || 5000;
app.listen(port, () => {
  console.log(`I am listening at ${port}`);
});

I am currently using SSL Configuration, following the Kafka.js Documentation. I have gotten ca,key,cert as strings from my kafka.keystore.jks. I am passing them in the SSL Object but when I try to connect my producer, I get the following error :-

 cause: KafkaJSConnectionError: Connection timeout
      at Timeout.onTimeout [as _onTimeout]
Abdullah Ch
  • 1,678
  • 1
  • 13
  • 31
  • How is this different from your previous question? https://stackoverflow.com/questions/74577599/client-network-socket-disconnected-before-secure-tls-connection-was-established – OneCricketeer Nov 26 '22 at 16:14
  • Different Error Messages. This one is about connection time out. – Abdullah Ch Nov 26 '22 at 16:24

0 Answers0