kafkajs plugin for Egg.js.
NOTE: This plugin just for integrate kafkajs into Egg.js, more documentation please visit https://kafka.js.org/docs/getting-started.
$ npm i egg-apache-kafkajs --save
or
$ yarn add egg-apache-kafkajs
// {app_root}/config/config.default.js
exports.kafka = {
options: {
clientId: 'clientId',
brokers: [ 'broker:9092' ],
connectionTimeout: 3000,
},
consumers: [
{
groupId: 'consumer-groupId',
topics: [ 'topic1' ],
},
],
};
// {app_root}/config/plugin.js
exports.kafka = {
enable: true,
package: 'egg-apache-kafkajs',
};
// Producer
const kafka = this.ctx.app.kafka;
await kafka.send({
topic: 'topic1',
messages: [{
value: 'Hello World',
}],
});
// Producer
const kafka = this.ctx.app.kafka;
const producer = kafka.producer();
await producer.connect();
await producer.send({
topic: 'topic1',
messages: [{
value: 'Hello World',
}],
});