1.1.1 • Published 8 years ago

brod-caster v1.1.1

Weekly downloads
4
License
GPL
Repository
github
Last release
8 years ago

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',
    // Append this value to the `eventName` value
    package: 'com.takeaway.events.cdn.page',
    // Path to `protoc` compiled message descriptors
    // Envelope has to have a message called `Envelope`
    envelope: './events/envelope.desc',
    messages: './events/my-events.desc'
  },

  topics: [
    {
      topic: 'service-broadcast'
    }, {
      topic: 'foo',
      offset: 20
    }
  ],

  client: {
    connectionString: 'localhost:2181/',
    // Set your own client name
    clientId: 'brod-caster',
    zkOptions: {}, // see: node-zookeeper-client
  },

  consumer: {
    // Default value for `protocolBuffer` adaptor
    encoding: 'buffer'
  },

  producer: {

  },

  // Only for testing purposes
  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)