{"_id":"@dengzhaofun/egg-kafka-node","_rev":"1-b1cfa73f9cdfceebbd7a57b0a8cd16b7","name":"@dengzhaofun/egg-kafka-node","dist-tags":{"latest":"1.0.7"},"versions":{"1.0.7":{"name":"@dengzhaofun/egg-kafka-node","version":"1.0.7","description":"kafka plugin for egg.js","eggPlugin":{"name":"kafkaNode"},"keywords":["egg","eggPlugin","egg-plugin","kafka-node","kafka-plugin","kafka-node-plugin","egg-kafka-node"],"dependencies":{"eventsproxy":"^1.3.0","kafka-node":"^4.0.0"},"devDependencies":{"autod":"^3.0.0","autod-egg":"^1.0.0","egg":"^2.0.0","egg-bin":"^4.3.0","egg-ci":"^1.8.0","egg-mock":"^3.13.0","eslint":"^4.11.0","eslint-config-egg":"^5.1.0","webstorm-disable-index":"^1.2.0"},"engines":{"node":">=8.0.0"},"scripts":{"test":"npm run lint -- --fix && egg-bin pkgfiles && npm run test-local","test-local":"egg-bin test","cov":"egg-bin cov","lint":"eslint .","ci":"egg-bin pkgfiles --check && npm run lint && npm run cov","pkgfiles":"egg-bin pkgfiles","autod":"autod"},"ci":{"version":"8, 9"},"repository":{"type":"git","url":"git+https://github.com/dengzhaofun/egg-kafka-node.git"},"bugs":{"url":"https://github.com/dengzhaofun/egg-kafka-node/issues"},"homepage":"https://github.com/dengzhaofun/egg-kafka-node#readme","author":{"name":"dengzhaofun"},"license":"MIT","gitHead":"6491d9516ff8aecd2d8d45ccf3a7fac6a3ec4cb2","_id":"@dengzhaofun/egg-kafka-node@1.0.7","_nodeVersion":"12.14.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-PruAkoECpOY6pJ9XU3qVfuLqClR2gjIdsA05nR/DZmx/xn4O8I1DR+6HZuipG7sz7HvAaChVQoNYqck9NiK1Ew==","shasum":"cbf1633c885e93709830aab69b910aa6070d0575","tarball":"https://registry.npmjs.org/@dengzhaofun/egg-kafka-node/-/egg-kafka-node-1.0.7.tgz","fileCount":18,"unpackedSize":37110,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeQ9O+CRA9TVsSAnZWagAAOegQAJ3xmBUwy0trdcWbMJxp\ny+oNJ2fKGpzCnVV1bYyJ+4JuevJU2W8HdDyTdjCEscTQPOq2cOC3ZEbTkOl3\n+8YMvS0U0TSJvyTTpAR4Ju6Ro0bE219m3Oqg3kf35KYthEqjOyyf/fjjcoGO\nANOHxaNdVtSR5bDiMrMs1TjA9iLclpZhe65Hc+CzJlWZbfPwMdnHnElGvJ3K\nN00zFDnR4SfgQdXEft66YuVYUxEmZk2Ofr50xsqOpd0UdfZ8uU33Q0QITO4i\not6+JZjyiPB0HJFHViRQamamAr5eMqu08mxj0u9hoVsOXjPBo21BRTXP8Xlf\n9z83M5yQkEtb0SCSpyjKBiLErNYt6s7d8t7NLjP5bOcnQ2zrnoLC9RGKfKzS\ndGqtmv1Z0F8suljz2gB4YmXs33GKWZ3mi+8RyrzfLr+4QYHv5zgrta/Z5W3e\nuMbKVqrR0TM8fYvp967F1UKlUiAIW7w7mtc+1k5TmcyFuiq9GsNOSWC6/OKL\nj076lHVsSw8oxKds4GX9nhqFgQjLSQsBR61DtRHQlyGowFJLzDd731e4l/lS\npCWNhdPTyh9tw2PiJ6DhwKtY3dsLtb26CZnPcNqHJLrSHIA82kNmh2o2tqIi\nj501/6Ai5Imp1ggccMuDLhTAGivdWab5RE+xuqt+SXSODzNV4gPif7xRwrgK\nOfae\r\n=dOu+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDKoolF3Y0lLGYfluAyTo1SgbQLyhqae+K+r9cYJKD3lAiB+I5LeXDxmknDDFlWDcTS1AbXJigmFsdP+vonJC1sjNA=="}]},"maintainers":[{"name":"dengzhaofun","email":"3328638734@qq.com"}],"_npmUser":{"name":"dengzhaofun","email":"3328638734@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/egg-kafka-node_1.0.7_1581503421956_0.5961556322983477"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-12T10:30:21.923Z","1.0.7":"2020-02-12T10:30:22.073Z","modified":"2022-04-05T03:44:54.687Z"},"maintainers":[{"name":"dengzhaofun","email":"3328638734@qq.com"}],"description":"kafka plugin for egg.js","homepage":"https://github.com/dengzhaofun/egg-kafka-node#readme","keywords":["egg","eggPlugin","egg-plugin","kafka-node","kafka-plugin","kafka-node-plugin","egg-kafka-node"],"repository":{"type":"git","url":"git+https://github.com/dengzhaofun/egg-kafka-node.git"},"author":{"name":"dengzhaofun"},"bugs":{"url":"https://github.com/dengzhaofun/egg-kafka-node/issues"},"license":"MIT","readme":"# egg-kafka-node\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-kafka-node.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-kafka-node\n[travis-image]: https://www.travis-ci.org/JohnApache/events-proxy.svg\n[travis-url]: https://travis-ci.org/JohnApache/egg-kafka-node\n[codecov-image]: https://codecov.io/gh/JohnApache/egg-kafka-node/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/JohnApache/egg-kafka-node\n[snyk-image]: https://snyk.io/test/github/JohnApache/egg-kafka-node/badge.svg?targetFile=package.json\n[snyk-url]: https://snyk.io/test/github/JohnApache/egg-kafka-node?targetFile=package.json\n[download-image]: https://img.shields.io/npm/dm/egg-kafka-node.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-kafka-node\n\n- [English](README.md)\n- [简体中文](README.zh_CN.md)\n\nThis plug-in is a package of [kafka-node] (https://github.com/SOHU-Co/kafka-node). It is an egg-style plug-in for easy use in the environment of egg.js. It also provides a detailed configuration of methods for sending Kafka messages. Refer to [https://github.com/SOHU-Co/kafka-node] (https://github.com/SOHU-Co/kafka-node). \n\n\n## Install\n\n```bash\n$ npm i egg-kafka-node --save\n```\n\n## Usage\n\n```js\n// {app_root}/config/plugin.js\nexports.kafkaNode = {\n  enable: true,\n  package: 'egg-kafka-node',\n};\n```\n\n## Configuration\n\n```js\n// {app_root}/config/config.default.js\nexports.kafkaNode = {\n  kafkaHost: '127.0.0.1:9092', // kafka connect host\n  clientOption: {}, // KafkaClient option, more documentation please visit kafka-node\n  consumerOption: [{\n    groupId: 'group1', // consumerGroup's groupId\n    topics: [ 'testTopic1' ], // topics under the same consumer group \n    options: {\n      fetchMaxWaitMs: 100,\n      fetchMinBytes: 1,\n      fetchMaxBytes: 1024 * 1024,\n    }, // relevant configuration for each consumer group, more documentation please visit kafka-node\n  }, {\n    groupId: 'group2',\n    topics: [ 'testTopic2' ],\n    options: {},\n  }, {\n    groupId: 'group3',\n    topics: [ 'testTopic3' ],\n  }],\n  // HighLevelProducer option, more documentation please visit kafka-node\n  producerOption: {\n    requireAcks: 1, \n    ackTimeoutMs: 100, \n    partitionerType: 2, \n    autoCreateTopic: true, // Whether to turn on automatic topic creation. default true\n    topics: [ 'testTopic1', 'testTopic2', 'testTopic3' ], // Topics that all consumers need to consume\n  },\n  messageOption: {\n    partition: 0,\n    attributes: 0, // send message option\n  },\n};\n```\n\nsee [config/config.default.js](test/fixtures/apps/config/config.default.js) for more detail.\n\n## Structure\n```js\negg-project\n├── package.json\n├── app.js (optional)\n├── app\n|   ├── router.js\n│   ├── controller\n│   |   └── home.js\n│   ├── service (optional)\n│   |   └── user.js\n│   |   └── response_time.js\n│   └── kafka (optional)  --------> like `controller, service...`\n│       ├── someTopic (optional)  -------> topic name of kafka\n│            ├── someKey1Consumer.js(optional)  ------> `someKey1` is a key of someTopic\n|            └── someKey2Consumer.js(optional)  ------> `someKey2` is an another key of someTopic\n├── config\n|   ├── plugin.js\n|   ├── config.default.js\n│   ├── config.prod.js\n|   ├── config.test.js (optional)\n|   ├── config.local.js (optional)\n|   └── config.unittest.js (optional)\n\n```  \n## USE TIPS\n\n> Note: The producer option topics of the kafkaNode configuration must create a corresponding topic directory under the {app-root}/kafka directory. Kafka-node automatically reads the file containing the'Consumers'filename under the topic, and the key needs to be passed in when sendMessage to facilitate business differentiation.\n\n> Note: You must set app.config.baseDir, kafka need to load consumers base on the baseDir.\n\n> Note: SendMessage messages max bytes depending on the configuration of you set.\n\n## Example\n\n```js\n// {app_root}/controller/index.js\nclass IndexController extends Controller {\n  async index() {\n    await this.ctx.kafka.sendMessage({\n      topic: 'someTopic', // Specify topics in the Kafka directory\n      key: 'someKey', // Specify consumer for the corresponding key under topic\n      messages: JSON.stringify({\n        username: 'JohnApache',\n        userId: 10001,\n        gender: 0\n      })\n    });\n  }\n\n  async some() {\n    this.ctx.kafka.sendMessageSync({\n      topic: 'someTopic', // Specify topics in the Kafka directory\n      key: 'someKey', // Specify consumer for the corresponding key under topic\n      messages: JSON.stringify({\n        username: 'JohnApache',\n        userId: 10001,\n        gender: 0\n      })\n    }, () => {\n      // success callback \n    }, () => {\n      // error callback \n    })\n  }\n}\n\n// {app_root}/kafka/someTopic/someKeyConsumer.js\nclass SomeKeySubscription extends Subscription {\n  async subscribe(message) {\n    const {value, topic, key} = message;\n    this.ctx.logger.info(`consume message ${value} by topic ${topic} key ${key} consumer`);\n    await asyncTask();\n  }\n}\n```\n\n## Questions & Suggestions\nPlease open an issue [here](https://github.com/JohnApache/egg-kafka-node/issues).\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md"}