You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
739 B
26 lines
739 B
var kafka = require('..'); |
|
var Producer = kafka.Producer; |
|
var KeyedMessage = kafka.KeyedMessage; |
|
var Client = kafka.Client; |
|
var client = new Client('localhost:2181'); |
|
var argv = require('optimist').argv; |
|
var topic = argv.topic || 'topic1'; |
|
var p = argv.p || 0; |
|
var a = argv.a || 0; |
|
var producer = new Producer(client, { requireAcks: 1 }); |
|
|
|
producer.on('ready', function () { |
|
var message = 'a message'; |
|
var keyedMessage = new KeyedMessage('keyed', 'a keyed message'); |
|
|
|
producer.send([ |
|
{ topic: topic, partition: p, messages: [message, keyedMessage], attributes: a } |
|
], function (err, result) { |
|
console.log(err || result); |
|
process.exit(); |
|
}); |
|
}); |
|
|
|
producer.on('error', function (err) { |
|
console.log('error', err); |
|
});
|
|
|