architect-kafka
Expose kafka-node as architect plugin
Last updated 4 years ago by jcreigno .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install architect-kafka 
SYNC missed versions from official npm registry.

architect-kafka NPM version

Expose kafka-node as architect plugin

Installation

npm install --save architect-kafka

Usage

Boot Architect :

var path = require('path');
var architect = require("architect");

var configPath = path.join(__dirname, "config.js");
var config = architect.loadConfig(configPath);

architect.createApp(config, function (err, app) {
    if (err) {
        throw err;
    }
    console.log("app ready");
});

Configure Architect with config.js :

See kafka-node documentation for Client options
See kafka-node documentation for Consumer options
See kafka-node documentation for Producer options

module.exports = [
	{
		packagePath: 'architect-kafka',
		client: { // Optional, default client
			// See kafka-node documentation for Client options
			connectionString: 'localhost:2181', // Default localhost:2181
		},
		consumers: {
			// Create a HighLevelConsumer using custom client, consuming from topics topicName1 and topicName2
			consumer1: {
				// Consumer type  [HighLevel|ConsumerGroup], optional default to Consumer
				type: HighLevel, 
				// See kafka-node documentation for Client options
			    client: {
			        connectionString: 'localhost:2181',
			        clientId: 'architect-kafka-client'
			    },
				// See kafka-node documentation for Consumer options
			    payloads: [
			        {
			            topic: 'topicName1',
			            offset: 0
			        },
			        {
			            topic: 'topicName2',
			            offset: 10
			        }
			    ],
			    options: {
			        groupId: 'kafka-node-group'
			    }
		    },
			// Create Consumer using default client
		    consumer2: {
		        payloads: [
		            {
		                topic: 'topicName1',
		                offset: 0
		            }
		        ],
		        options: {}
		    }
		},
		producers: {
			// Create a HighLevelProducer using custom client
		    producer1: {
		        highLevel: true, // Use HighLevelproducer instead of Producer, default false
				// See kafka-node documentation for Client options
		        client: {
		            connectionString: 'localhost:2181',
		            clientId: 'architect-kafka-client'
		        },
				// See kafka-node documentation for Producer options
		        options: {}
		    },
			// Create a regular Kafka Producer using default client
		    producer2: {}
		}
	}
];

Use it :

See kafka-node documentation for Consumer usage
See kafka-node documentation for Producer usage

module.exports = function setup(options, imports, register) {

    var kafka = imports.kafka;

	var producer1 = kafka.producers.producer1;
	var consumer2 = kafka.consumers.consumer2;

	producer1.send([
		{
			topic: 'topicName1',
			message: ['hello world !']
		}
	], function(err, res) {
		...	
	});

	consumer2.on('message', function(message) {
		...
	});
   
    register();
};

module.exports.consumes = ['kafka'];
module.exports.provides = [];

Current Tags

  • 1.1.0                                ...           latest (4 years ago)

11 Versions

  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.6                                ...           4 years ago
  • 0.0.5                                ...           4 years ago
  • 0.0.4                                ...           4 years ago
  • 0.0.3                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |