BrodCaster
Combines Apache Kafka & Google Protocol Buffers
Watch your Kafka message queue and dispatch tasks accordingly.
As Kafka's literary executor, Max Brod refused to follow the writer's instructions to burn his life's work, and had them published instead. (Wikipedia)
How to use
var kafka = new BrodCaster();
kafka.on('myService', 'eventName', function(data) {
console.log(data);
});
kafka.send('myService', 'eventName', { my: 'data' }, function(err, result) {
console.log(err || result);
})
Options
Use with Kafka
{
adaptor: {
type: 'protocolBuffer',
package: 'com.takeaway.events.cdn.page',
envelope: './events/envelope.desc',
messages: './events/my-events.desc'
},
topics: [
{
topic: 'service-broadcast'
}, {
topic: 'foo',
offset: 20
}
],
client: {
connectionString: 'localhost:2181/',
clientId: 'brod-caster',
zkOptions: {},
},
consumer: {
encoding: 'buffer'
},
producer: {
},
producerInstance: myInstance
}
Pass in options.parser
& options.serializer
functions to skip using adaptor.
API
on(origin, status, cb)
- origin: String
- status: String
- cb: function(data, raw)
- data: Object, the additional data sent with the message
- raw: Object, the original message the consumer instance got
send(origin, status, data, cb)
- origin: String
- status: String
- data
- message: String, (required) name of the message
data
gets serialized by - (toProto: function, (optional) returns serialized message as
Buffer
for envelope - currently not supported) - data: Object, contains all required fields to serialize Message
message
- options:
- topics: Array
- partition: Number
- attributes: Number
- cb: function(err, result)