node.jsapache-kafkaoauth-2.0librdkafka

I need to convert below python code into nodejs but I couldn't find any equivalent code for "sasl_oauth_token_provider" this property


I've this code working in python, I need to convert this into nodejs but I couldn't find any equivalent code for sasl_oauth_token_provider this property.

import time
from kafka import *
from kafka.errors import KafkaTimeoutError
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

producer = KafkaProducer(bootstrap_servers='xxx',
                         security_protocol='SASL_SSL',
                         ssl_check_hostname=True,
                         sasl_mechanism='OAUTHBEARER',
                         sasl_plain_username=client_id,
                         sasl_plain_password=client_secret,
                         sasl_oauth_token_provider="xxx",
                         )

For nodejs I'm using node-rdkafka library and closest equivalent code I've got is -

const kafka = require('node-rdkafka');

const producer = new kafka.Producer({
'metadata.broker.list': 'xxx',
'security.protocol': 'sasl_ssl',
'sasl.mechanism': 'OAUTHBEARER',
'sasl.username': 'xxx',
'sasl.password': 'xxx',
});

Solution

  • What I've found node-rdkafka has no way to sasl_oauth_token_provider use this configuration property, so I had to abandon it and use KafkaJS which supports this.