The sample scripts in this article demonstrate how to connect to your Aiven for Apache Kafka service and pass a few messages.


  • node-rdkafka
    Note: Install this library with SSL support enabled.

To test your Aiven for Apache Kafka service:

  1. Download the SSL certificate files in the Aiven web console.

    1. Go to the Overview page of your Aiven for Apache Kafka service.

    2. Click Download next to Access Key and save the service.key file.

    3. Click Download next to Access Certificate and save the service.cert file.

    4. Click Download next to CA Certificate and save the ca.pem file.

  2. Go to the Topics page for your service and add a new topic named demo-topic.

  3. Create and run the producer script:

    var Kafka = require('node-rdkafka');
    console.log(Kafka.features); // this should print 'ssl', among other things

    var producer = new Kafka.Producer({
    '': '',
    'security.protocol': 'ssl',
    'ssl.key.location': 'service.key',
    'ssl.certificate.location': 'service.cert',
    '': 'ca.pem',
    'dr_cb': true


    producer.on('ready', function() {
    try {
    'demo-topic', // topic to send the message to
    null, // partition, null for librdkafka default partitioner
    new Buffer('Hello world!'), // value
    null, // optional key // optional timestamp
    console.log('Message sent successfully');
    } catch (err) {
    console.log('Failed to send message', err);

  4. Create the consumer script:

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

    var stream = new Kafka.createReadStream({
    '': '',
    '': 'demo-consumer-group',
    'security.protocol': 'ssl',
    'ssl.key.location': 'service.key',
    'ssl.certificate.location': 'service.cert',
    '': 'ca.pem'
    }, {}, {'topics': ['demo-topic']});

    stream.on('data', function(message) {
    console.log('Got message');

Did this answer your question?