Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Kafka = require('node-rdkafka');
const config = require('./setting');
console.log("features:" + Kafka.features);
console.log(Kafka.librdkafkaVersion);
var producer = new Kafka.Producer({
/*'debug': 'all', */
'api.version.request': 'true',
'bootstrap.servers': config['bootstrap_servers'],
'dr_cb': true,
'dr_msg_cb': true,
'security.protocol' : 'sasl_ssl',
'ssl.ca.location' : './ca-cert',
'sasl.mechanisms' : 'PLAIN',
'sasl.username' : config['sasl_plain_username'],
'sasl.password' : config['sasl_plain_password']
});
var connected = false
// Poll for events every 100 ms
const Kafka = require('node-rdkafka');
const config = require('./setting');
console.log("features:" + Kafka.features);
console.log(Kafka.librdkafkaVersion);
var producer = new Kafka.Producer({
/*'debug': 'all', */
'api.version.request': 'true',
'bootstrap.servers': config['bootstrap_servers'],
'dr_cb': true,
'dr_msg_cb': true
});
var connected = false
// Poll for events every 100 ms
producer.setPollInterval(100);
// Connect to the broker manually
producer.connect();
const Kafka = require('node-rdkafka');
const config = require('./setting');
console.log(Kafka.features);
console.log(Kafka.librdkafkaVersion);
console.log(config)
var consumer = new Kafka.KafkaConsumer({
/*'debug': 'all',*/
'api.version.request': 'true',
'bootstrap.servers': config['bootstrap_servers'],
'security.protocol' : 'sasl_ssl',
'ssl.ca.location' : './ca-cert',
'sasl.mechanisms' : 'PLAIN',
'message.max.bytes': 32000,
'fetch.max.bytes' : 32000,
'fetch.message.max.bytes': 32000,
'max.partition.fetch.bytes': 32000,
'sasl.username' : config['sasl_plain_username'],
'sasl.password' : config['sasl_plain_password'],
'group.id' : config['consumer_id']
const co = require('co')
const Kafka = require('node-rdkafka');
const config = require('./setting');
console.log(Kafka.features);
console.log(Kafka.librdkafkaVersion);
//该函数每次都会创建producer进行发送,性能可能较差,但是使用简答,仅供参考
var produceMessages = function(msgs) {
return new Promise(function(resolve, reject) {
let msgsCount = 1;
if(Array.isArray(msgs)){
msgsCount = msgs.length;
};
var producer = new Kafka.Producer({
/*'debug': 'all', */
'api.version.request': 'true',
'bootstrap.servers': config['bootstrap_servers'],
'dr_cb': true,
'dr_msg_cb': true,
'security.protocol' : 'sasl_ssl',
'ssl.ca.location' : './ca-cert',