kafka-avro
Node.js bindings for librdkafka with Avro schema serialization.
WARNING Still WIP, consumer not working!
Install
Install the module using NPM:
npm install kafka-avro --save
Documentation
Initialize kafka-avro
Initialize kafka-avro
var KafkaAvro = require('kafka-avro');
var kafkaAvro = new KafkaAvro({
kafkaBroker: 'localhost:9092',
schemaRegistry: 'localhost:8081',
});
kafkaAvro.on('log', function(message) {
console.log(message);
})
kafkaAvro.init()
.then(function() {
console.log('Ready to use');
});
Quick Usage Producer
NOTICE: You need to initialize kafka-avro before you can produce or consume messages.
var producer = kafkaAvro.getProducer({
});
var topicName = 'test';
producer.on('ready', function() {
var topic = producer.Topic(topicName, {
'request.required.acks': 1
});
var value = new Buffer('value-' +i);
var key = 'key';
var partition = -1;
producer.produce(topicName, topic, partition, value, key);
});
producer.on('disconnected', function(arg) {
console.log('producer disconnected. ' + JSON.stringify(arg));
});
producer.connect();
What kafka-avro basically does is wrap around node-rdkafka and intercept the produce method to validate and serialize the message.
Quick Usage Consumer
var Transform = require('stream').Transform;
var consumer = kafkaAvro.getConsumer({
'group.id': 'librd-test',
'socket.keepalive.enable': true,
'enable.auto.commit': true,
});
var topicName = 'test';
var stream = consumer.getReadStream(topicName, {
waitInterval: 0
});
stream.on('error', function() {
process.exit(1);
});
stream
.pipe(new Transform({
objectMode: true,
transform: function(data, encoding, callback) {
callback(null, data.message);
}
}))
.pipe(process.stdout);
consumer.on('error', function(err) {
console.log(err);
});
Same deal here, thin wrapper around node-rdkafka and deserialize incoming messages before they reach your consuming method.
Releasing
- Update the changelog bellow.
- Ensure you are on master.
- Type:
grunt release
grunt release:minor
for minor number jump.grunt release:major
for major number jump.
Release History
License
Copyright Waldo, Inc. All rights reserved.