How to use the node-rdkafka.AdminClient function in node-rdkafka

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 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');
        }