Friday, 9 June 2017

Apache Kafka, node js and Point-to-point workflow

So I am just starting to explore kafka (with node js) and I am using kafka-node module to interact with kafka.

how to id implement point-to-point workflow? i.e. One or more consumers can consume the messages in the queue, but a particular message can be consumed by a maximum of one consumer only. Once a consumer reads a message in the queue, it should disappear from that queue.

I just wrote some test consumer code (see below). When i run multiple instances of this consumer code, and push new messages to a topic, all the instances of consumers pull the message (and display on console). I want only 1 of the consumers to pull the message and process it.

var kafka = require("kafka-node");
var client = new kafka.Client();
var Consumer = kafka.Consumer;

var consumer = new Consumer(
        client,
        [
            { topic: 'testtopic**strong text**', partition: 0 }
        ],
        {
            autoCommit: true,
        }
    )

consumer.on('message', function (message) {
    console.log(message);
});

Any help will be greatly appreciated!

Thanks



via Web G

No comments:

Post a Comment