1.1.0 • Published 5 years ago

egg-apache-kafkajs v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

egg-apache-kafkajs

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.

Install

$ npm i egg-apache-kafkajs --save

or

$ yarn add egg-apache-kafkajs

Configuration

// {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',
};

Usage

// 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',
  }],
});

License

MIT

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago