Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://github.com/SOHU-Co/kafka-node/
  2. // https://www.npmjs.org/package/kafka-node
  3.  
  4. var kafka = require('kafka-node');
  5. var HighLevelProducer = kafka.HighLevelProducer;
  6. var Client = kafka.Client;
  7. var client = new Client('localhost:2181');
  8. var argv = require('optimist').argv;
  9. var topic = argv.topic || 'mytopic';
  10. var count = 3, rets = 0;
  11. var producer = new HighLevelProducer(client);
  12.  
  13. producer.on('ready', function () {
  14.     send('hello 1');
  15.     setTimeout(function () {
  16.         send('world 2');
  17.         send('world 3');
  18.     }, 2000);
  19. });
  20.  
  21. function send(message) {
  22.     producer.send([
  23.         {topic: topic, messages: [message] }
  24.     ], function (err, data) {
  25.         if (err) console.log(arguments);
  26.         if (++rets === count) process.exit();
  27.     });
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement