How to use node-rdkafka - 10 common examples

To help you get started, we’ve selected a few node-rdkafka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scality / backbeat / tests / functional / api / BackbeatServer.js View on Github external
next => {
                    testProducer = new Producer({
                        'metadata.broker.list': config.kafka.hosts,
                    });
                    testProducer.connect();
                    testProducer.on('ready', () => next());
                    testProducer.on('event.error', error => {
                        assert.ifError(error);
                    });
                },
                // create topics by fetching metadata from these topics
github scality / backbeat / tests / functional / api / routes.js View on Github external
next => {
                    testProducer = new Producer({
                        'metadata.broker.list': config.kafka.hosts,
                    });
                    testProducer.connect();
                    testProducer.on('ready', () => next());
                    testProducer.on('event.error', error => {
                        assert.ifError(error);
                    });
                },
                // create topics by fetching metadata from these topics
github scality / backbeat / tests / functional / ingestion / IngestionReader.js View on Github external
});
const ingestionQP = new IngestionQueuePopulator({
    config: testConfig.extensions.ingestion,
    logger: dummyLogger,
});
const consumerParams = {
    'metadata.broker.list': [testConfig.kafka.hosts],
    'group.id': 'test-consumer-group-ingestion',
    // we manage stored offsets based on the highest
    // contiguous offset fully processed by a worker, so
    // disabling automatic offset store is needed
    'enable.auto.offset.store': false,
    // this function is called periodically based on
    // auto-commit of stored offsets
};
const consumer = new kafka.KafkaConsumer(consumerParams, {});

function setZookeeperInitState(ingestionReader, cb) {
    const path = `${ingestionReader.bucketInitPath}/isStatusComplete`;
    async.series([
        next => zkClient.mkdirp(path, next),
        next => zkClient.setData(path, Buffer.from('true'),
            -1, next),
    ], cb);
}

function checkEntryInQueue(kafkaEntries, expectedEntries, done) {
    // 2 entries per object, but the master key is filtered
    assert.strictEqual(kafkaEntries.length, expectedEntries.length);

    const retrievedEntries = kafkaEntries.map(entry => JSON.parse(entry.value));
github AliwareMQ / aliware-kafka-demos / kafka-nodejs-demo / vpc-ssl / producer.js View on Github external
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
producer.setPollInterval(100);
github Azure / azure-event-hubs-for-kafka / quickstart / node / producer.js View on Github external
/* Copyright (c) Microsoft Corporation. All rights reserved.
 * Copyright (c) 2016 Blizzard Entertainment
 * Licensed under the MIT License.
 *
 * Original Blizzard node-rdkafka sample modified for use with Azure Event Hubs for Apache Kafka Ecosystems
 */

var Kafka = require('node-rdkafka');

var producer = new Kafka.Producer({
  //'debug' : 'all',
  'metadata.broker.list': 'mynamespace.servicebus.windows.net:9093', //REPLACE
  'dr_cb': true,  //delivery report callback
  'security.protocol': 'SASL_SSL',
  'sasl.mechanisms': 'PLAIN',
  'sasl.username': '$ConnectionString', //do not replace $ConnectionString
  'sasl.password': 'Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=XXXXXX;SharedAccessKey=XXXXXX' //REPLACE
});

var topicName = 'test';

//logging debug messages, if debug is enabled
producer.on('event.log', function(log) {
  console.log(log);
});
github scality / backbeat / lib / BackbeatConsumer.js View on Github external
_onOffsetCommit(err, topicPartitions) {
        if (err) {
            // NO_OFFSET is a "soft error" meaning that the same
            // offset is already committed, which occurs because of
            // auto-commit (e.g. if nothing was done by the producer
            // on this partition since last commit).
            if (err === kafka.CODES.ERRORS.ERR__NO_OFFSET) {
                return undefined;
            }
            this._log.error('error committing offset to kafka',
                            { errorCode: err });
            return undefined;
        }
        this._log.debug('commit offsets callback',
                        { topicPartitions });
        return undefined;
    }
github AliwareMQ / aliware-kafka-demos / kafka-nodejs-demo / vpc / producer.js View on Github external
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();
github AliwareMQ / aliware-kafka-demos / kafka-nodejs-demo / vpc-ssl / producer.js View on Github external
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
github AliwareMQ / aliware-kafka-demos / kafka-nodejs-demo / vpc / producer.js View on Github external
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();
github ibm-messaging / event-streams-samples / kafka-nodejs-console-sample / app.js View on Github external
'log.connection.close' : false
};

var admin_opts = {
    'client.id': 'kafka-nodejs-console-sample-admin',
};

// Add the common options to client and producer
for (var key in driver_options) { 
    admin_opts[key] = driver_options[key];
}

// Use the AdminClient API to create the topic
// with 1 partition and a retention period of 24 hours.
console.log('Creating the topic ' + topicName + ' with AdminClient');
admin = Kafka.AdminClient.create(admin_opts);
admin.connect();
console.log("AdminClient connected");

admin.createTopic({
    topic: topicName,
    num_partitions: 1,
    replication_factor: 3,
    config: { 'retention.ms': (24*60*60*1000).toString() }
    }, 
    function(err) {
        if(err) {
            console.log(err);
        } else {
            console.log('Topic ' + topicName + ' created');
        }