Skip to content

Instantly share code, notes, and snippets.

@jp
Last active July 13, 2024 02:33
Show Gist options
  • Select an option

  • Save jp/4628ddf1a1811f659d25 to your computer and use it in GitHub Desktop.

Select an option

Save jp/4628ddf1a1811f659d25 to your computer and use it in GitHub Desktop.

Revisions

  1. jp renamed this gist Mar 4, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jp created this gist Mar 4, 2015.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    var WebSocketServer = require('ws').Server
    , wss = new WebSocketServer({ port: 8080 });

    wss.broadcast = function broadcast(data) {
    wss.clients.forEach(function each(client) {
    client.send(JSON.stringify(data));
    });
    };

    var kafka = require('kafka-node'),
    Producer = kafka.Producer,
    Consumer = kafka.Consumer,
    client = new kafka.Client("localhost:2181", "topic-test"),

    consumer = new Consumer(
    client,
    [
    { topic: 'test', partition: 0 }
    //, { topic: 't1', partition: 1 }
    ],
    {
    autoCommit: false
    }
    );

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