const kafka = require("kafka-node"); const Client = kafka.KafkaClient; const Offset = kafka.Offset; const Consumer = kafka.Consumer; function toKafka() { const client = new Client({ kafkaHost: "192.168.100.129:9092" }); const offset = new Offset(client); console.log("连接kafka中"); ...
kafka-node地址: 下面代码只是消费信息的 const kafka = require("kafka-node");const Client = kafka.KafkaClient;const Offset = kafka.Offset;const Consumer = kafka.Consumer;function toKafka() {const client = new Client({ kafkaHost: "192.168.100.129:9092" });const offset = new Offset(client);c...
constkafka=require('kafka-node');constclient=newkafka.KafkaClient({kafkaHost:'127.0.0.1:9092'})#创建topiccreateTopics();#启动消息消费createConsumer((message)=>{console.log('event callback receive message:');console.log(message);});createHighLevelProducter((producter)=>{#对主题:topic-for-1的...
Simple POC Kafka (node-rdkafka) + NodeJS + Typescript & Docker (Kafka, Zookeeper, MongoDB) - GitHub - jazzify/kafka-node: Simple POC Kafka (node-rdkafka) + NodeJS + Typescript & Docker (Kafka, Zookeeper, MongoDB)
kafka-nodewww.npmjs.com/package/kafka-node 生产者: /** * 生产者 */ const kafka = require('kafka-node'); let conn = {'kafkaHost':'127.0.0.1:9092'}; var MQ = function (){ this.mq_producers = {}; } MQ.prototype.AddProducer = function (conn, handler){ ...
"name": "kafka", "private": false, "dependencies": { "kafka-node": "4.1.3" }, "devDependencies": { "mocha": ">=0.0.1" } } 3. 编写生产者与消费者 具体api可以参考官网: kafka-nodewww.npmjs.com/package/kafka-node 生产者: ...
文档地址https://www.npmjs.com/package/kafka-node 需求日志接入kafka存到elk上,各种要求都不高,找一段最基础的发送message varkafka=require('kafka-node'),Producer=kafka.Producer,KeyedMessage=kafka.KeyedMessage,client=newkafka.KafkaClient(),producer=newProducer(client),km=newKeyedMessage('key','message...
//引入kafka-node const kafka = require('kafka-node'); //创建连接 let generateKafkaConnection= function(host){ return new Promise((resolve,reject)=>{ try{ let client = new kafka.KafkaClient({'kafkaHost':host}); resolve(client) }catch (e) { ...
node接入kafka 模块: kafka-node 默认一个分区模式 首先创建生产者: var kafka = require('kafka-node'), Producer = kafka.Producer, client = newkafka.KafkaClient({kafkaHost:'192.168.20.59:9092'}); /** * 定义生产类 * partitionerType 定义 ...
var kafka = require('kafka-node'), Producer = kafka.Producer, client = new kafka.Client(), producer = new Producer(client); // Create topics sync producer.createTopics(['t','t1'], false, function (err, data) { console.log(data); }); // Create topics async producer.createTopics([...