有没有办法将融合模式注册表与 kafka-node 模块一起使用? [英] Is there any way to use confluent schema registry with kafka-node module?

查看:24
本文介绍了有没有办法将融合模式注册表与 kafka-node 模块一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 node.js 中实现了 Avro 模式,模式与消息有效负载一起发送.它工作正常.我正在寻找是否有任何方法可以将架构注册表与 Kafka 节点模块一起使用.我已经探索过,但没有成功找到.

I have implemented Avro schema in node.js with schema being sent with the message payload. And it is working fine. I am looking if there is any way I can use schema-registry with Kafka-node module. I have explored but was not successful in finding any.

并且在每条消息中发送模式会增加消息大小?与使用架构注册表相比,它会影响性能吗?

And sending schema in each message increase the message size? Does it affect the performance compared to using schema registry?

对此的任何帮助将不胜感激.

Any help in this will be appreciated.

推荐答案

您可以使用 "avro-schema-registry" 模块.它对我有用.我也是 Kafka 的新手,只是尝试一下.

You can use "avro-schema-registry" module. It is working for me. I am also new to Kafka, just trying it out.

const kafka = require('kafka-node');
const avroSchemaRegistry = require('avro-schema-registry');

/* Configuration */
const kafkaTopic = 'newkafkatopic';//'kafka.test';
const host =  'localhost:9092';
const schemaRegistry = 'http://localhost:8081';

const Consumer = kafka.Consumer;
const Client = kafka.KafkaClient;
const registry = avroSchemaRegistry(schemaRegistry);

var client = new Client(host);
var topics = [{
  topic: kafkaTopic
}];

var options = {
  autoCommit: false,
  fetchMaxWaitMs: 1000,
  fetchMaxBytes: 1024 * 1024,
  encoding: 'buffer'
};

var consumer = new Consumer(client, topics, options);

consumer.on('message', function(rawMessage) {
  console.log("Raw Message", rawMessage);

  registry.decode(rawMessage.value)
    .then((msg) => {
      console.log(msg)
    })
    .catch(err=>console.log(err))
});

consumer.on('error', (e) => {
  console.log(e.message)
  consumer.close();
})

这篇关于有没有办法将融合模式注册表与 kafka-node 模块一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆