Kafkajs: Not able to connect to Kafka consumer over TLS/SSL with KafkaJs node module

Created on 21 May 2019  路  1Comment  路  Source: tulios/kafkajs

Hello,

Want to connect Kafka consumer over TLS, tried the following getting "unknown error while connect"


var fs = require('fs');
var Kafka = require('kafkajs').Kafka;
var logLevel = require('kafkajs').logLevel;


var _kafka = new Kafka({
    clientId: 'my-app',
    brokers: ['broker:9093'],
    logLevel: logLevel.DEBUG,
    ssl: {
        rejectUnauthorized: false,
        ca: [fs.readFileSync('./cert/ca.trust.certificate.crt')],
        cert: fs.readFileSync('./cert/client-cert-signed.crt'),

    }
});


try {
    const consumer = _kafka.consumer({ groupId: 'test-group' }, { maxWaitTimeInMs: 3000 });

    consumer.connect();
    consumer.subscribe({ topic: 'external-events', fromBeginning: true });

    consumer.run({
        eachMessage: async({ topic, partition, message }) => {
            console.log({
                partition: 2,
                offset: message.offset,
                value: message.value.toString(),
            })
        },
    })
} catch (err) {
    console.log('Error while connect : ' + err);
}

Error what I am receiving for reference :

{"level":"ERROR","timestamp":"2019-05-21T09:32:47.581Z","logger":"kafkajs","message":"[BrokerPool] KafkaJSConnectionError: Connection error: 101057795:error:1408E0F4:SSL routines:ssl3_get_message:unexpected message:openssl\ssl\s3_both.c:408:\n","retryCount":0,"retryTime":249}

{"level":"ERROR","timestamp":"2019-05-21T09:32:47.582Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Connection error: 101057795:error:1408E0F4:SSL routines:ssl3_get_message:unexpected message:openssl\ssl\s3_both.c:408:\n","retryCount":0,"retryTime":249}

Could you please help me on this, struggling for 3 days no leads;

question

Most helpful comment

able to solve it, forgot to add key {private} in the sslOptions (ssl); after adding it works like a charm;

>All comments

able to solve it, forgot to add key {private} in the sslOptions (ssl); after adding it works like a charm;

Was this page helpful?
0 / 5 - 0 ratings