/egg-kafkajs

☎️kafka plugin for eggjs

Primary LanguageJavaScriptMIT LicenseMIT

egg-kafkajs

NPM version npm download

kafka-node plugin for Egg.js.

NOTE: This plugin just for integrate kafka-node into Egg.js, more documentation please visit https://github.com/SOHU-Co/kafka-node.

Install

$ npm i egg-kafkajs --save

or

$ yarn add egg-kafkajs

Usage

// {app_root}/config/plugin.js
exports.kafkajs = {
  enable: true,
  package: 'egg-kafkajs',
};

Configuration

// {app_root}/config/config.default.js
config.kafkajs = {
    host: '127.0.0.1:2181',
    sub: [
      {
        groupId: 'consumer-groupId',
        topics: [ 'topic1', 'topic2' ],
        topic1: [ 'key1', 'key2' ],
        topic2: [ 'key3', 'key4' ],
      },
    ],
    pub:
      {
        key: 'test',
        topics: [],
        // Configuration for when to consider a message as acknowledged, default 1
        requireAcks: 1,
        // The amount of time in milliseconds to wait for all acks before considered, default 100ms
        ackTimeoutMs: 1000,
        // Partitioner type (default = 0, random = 1, cyclic = 2, keyed = 3, custom = 4), default 0
        partitionerType: 2,
        partition: 0,
        attributes: 0,
      },
  };

Structure

egg-project
├── package.json
├── app.js (optional)
├── app
|   ├── router.js
│   ├── controller
│   |   └── home.js
│   ├── service (optional)
│   |   └── user.js
│   |   └── response_time.js
│   └── kafka (optional)  --------> like `controller, service...`
│       ├── topic1 (optional)  -------> topic name of kafka
│            ├── key1_comsumer.js(optional)  ------> `key` is the key of topic
|            └── key2_comsumer.js(optional)
├── config
|   ├── plugin.js
|   ├── config.default.js
│   ├── config.prod.js
|   ├── config.test.js (optional)
|   ├── config.local.js (optional)
|   └── config.unittest.js (optional)

Example

see test/fixtures/apps/kafkajs-test/ for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT