简体   繁体   English

kafka nodejs-使用SASL身份验证创建生产者和使用者的问题

[英]kafka nodejs - Issue in creating producer and consumer with SASL authentication

I am trying to create Kafka producer and consumer with SASL authentication using nodejs but it seems to be not available in any of the nodejs kafka packages which I have tried almost all of them (node-rdkafka, kafka-node, no-kafka....) 我正在尝试使用nodejs通过SASL身份验证创建Kafka生产者和消费者,但似乎在所有我尝试过的所有nodejs kafka软件包(node-rdkafka,kafka-node,no-kafka)中都不可用。 ..)

Tried below option with node-rdkafka but no luck in making publishing msgs with sasl 在node-rdkafka下尝试过以下选项,但是在使用sasl发布消息方面运气不佳

var Kafka = require('node-rdkafka');
var producer = Kafka.Producer({
  'debug': 'all',
  'metadata.broker.list': 'localhost:9092',
  'security.protocol': 'sasl_plaintext',
  'sasl.username': 'root',
  'sasl.password': 'admin!',
  'sasl.mechanisms': 'PLAIN',
});

// producer.connect();
producer.connect(null, (err, metadata) => {
   console.log(metadata);
   console.error(err);
   console.log('Connected')
});

producer.on('ready', function () {
  try {
    producer.produce('topic1', null, new Buffer('Awesome'), null, Date.now())
  } catch (err) {
    console.log('A error occured')
  }
});

// Any errors we encounter, including connection errors
producer.on('event.error', function(err) {
  console.log('Error from producer');
  console.log(err);
})

producer
  .on('event.log', function(event) {
      console.log(event)
      const loggedEvent = {
        severity: event.severity,
        fac: event.fac
      };

      if (event.severity >= 7) {
        console.log(loggedEvent, event.message);
      } else if (event.severity === 6 || event.severity === 5) {
        console.log(loggedEvent, event.message);
      } else if (event.severity === 4) {
        console.log(loggedEvent, event.message);
      } else if (event.severity > 0) {
        console.log(loggedEvent, event.message);
      } else {
        console.log(loggedEvent, event.message);
      }
})

On top of that facing issues with node-gyp and docker issues due to C++ wrapper for node-rdkafka 最重要的是由于node-rdkafka的C ++包装器而导致的node-gyp和docker问题

https://github.com/nodejs/node/issues/17732 https://github.com/nodejs/node/issues/17732
https://github.com/GaiamTV/kafka-node-topic-consumer/issues/3 https://github.com/GaiamTV/kafka-node-topic-consumer/issues/3
https://github.com/Blizzard/node-rdkafka/issues/323 https://github.com/Blizzard/node-rdkafka/issues/323

Even created jar file with producer and consumer standalone java classes and tried to run those java classes using nodejs child process which didnt throw any errors and at the sametime no output 甚至使用生产者和消费者独立的Java类创建了jar文件,并尝试使用nodejs子进程运行那些Java类,该子进程没有引发任何错误,并且同时没有输出

var cmd    = require('child_process').spawn('java', ['-cp', 'NodeKafka-0.0.1-SNAPSHOT.jar', 'node/kafka/NodeKafka/nodeKafkaConsumer.class']);

//console.log(spawn);
setInterval(function() {
cmd.stdout.on('data', function (data) {
  console.log('stdout: ' + data); // This will print string returned by Main class.
});

},3000);

Lot of dependencies and errors for Kafka nodejs compared to Java and python 与Java和python相比,Kafka nodejs的依赖和错误很多

Could you please help in using node-rdkafka or any other pacakge that supports SASL authentication(without using SSL) for creating kafka producer and consumer 您能否在使用node-rdkafka或任何其他支持SASL身份验证(不使用SSL)的pacakge上帮助创建kafka生产者和使用者

If you want to use Nodejs with Kafka and SASL you don't have many options. 如果要将Nodejs与Kafka和SASL结合使用,则没有太多选择。 As far as I know, only node-rdkafka officially supports it. 据我所知,只有node-rdkafka正式支持它。 That said, I've been using it for over a year now (with SASL) and it's a pretty good client. 就是说,我已经使用它一年多了(与SASL一起使用),它是一个很好的客户。

I don't know your configuration or use case but note that when using SASL Plain over a plaintext connection, credentials will be sent over the network in plaintext. 我不知道您的配置或用例,但请注意,通过明文连接使用SASL Plain时,凭据将以明文形式通过网络发送。

When installing node-rdkafka you need to make sure it successfully builds and has all the required features enabled (SASL). 在安装node-rdkafka时,您需要确保它能够成功构建并启用所有必需的功能(SASL)。 Depending on your OS the exact dependencies you need to have installed vary slightly. 根据您的操作系统,您需要安装的确切依赖项会略有不同。

Looking at the log you pasted in the node-rdkafka issue, you are missing all dependencies including a C compiler ! 查看您在node-rdkafka问题中粘贴的日志,您缺少所有依赖项,包括C编译器! The required libraries are listed on https://github.com/edenhill/librdkafka#requirements 所需的库在https://github.com/edenhill/librdkafka#requirements上列出

Regarding the SASL dependencies, in the npm output, you want to see: 关于SASL依赖性,在npm输出中,您希望看到:

checking for libsasl2 (by pkg-config)... ok
checking for libsasl2 (by compile)... ok (cached)
...
ENABLE_SASL              y
...
LIBS                     ... -lsasl2 ...

Finally your Nodejs client logic looks fine, so once you get your dependencies sorted, it should work. 最终,您的Node.js客户端逻辑看起来不错,所以一旦您对依赖项进行排序,它就应该可以工作了。

For kafka with node their is good package https://kafka.js.org/ 对于带有节点的kafka来说,它们是一个很好的包https://kafka.js.org/

they have SASL https://kafka.js.org/docs/configuration#a-name-sasl-a-sasl 他们有SASL https://kafka.js.org/docs/configuration#a-name-sasl-a-sasl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在令牌过期之前,如何使用 kafkajs 使用 sasl 和 oauthbearer 为 kafka 生产者和消费者定期获取新的 access_token? - How can I periodically get new access_token using sasl with oauthbearer for kafka producer and consumer using kafkajs before the token expires? 试图在卡夫卡建立消费者和生产者 - Trying to setup consumer and producer in Kafka Rabbitmq 生产者(symfony 3)和消费者错误(NodeJs) - Rabbitmq producer (symfony 3 ) and error with consumer ( NodeJs ) Node.js Kafka使用者无限循环 - Nodejs kafka consumer infinite loop Kafka 消费者/生产者与 Kafka Stream 的设计问题 - Design Question Kafka Consumer/Producer vs Kafka Stream 使用kafkaJS库的NodeJS kafka生产者无法正常工作 - NodeJS kafka producer using kafkaJS library not working Apache Kafka 2.3 + Node.js 10.15 + 消费者 + 生产者 - Apache Kafka 2.3 + Node.js 10.15 + Consumer + Producer 具有pm2集群的Nodejs Kafka使用者 - Nodejs Kafka consumer with pm2 cluster 为什么我的 Kafka Consumer 无法读取来自我的 Kafka Producer 的消息? - Why can my Kafka Consumer not read the message from my Kafka Producer? 使用 kafka-node 创建的消费者和生产者无法连接到 kafka 的工作实例 - consumer and producer created with kafka-node are unable to connect to working instance of kafka
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM