Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phambanhan/egg-apache-kafkajs
Kafkajs plugin for Egg.js
https://github.com/phambanhan/egg-apache-kafkajs
egg egg-plugin eggjs kafka kafkajs
Last synced: about 1 month ago
JSON representation
Kafkajs plugin for Egg.js
- Host: GitHub
- URL: https://github.com/phambanhan/egg-apache-kafkajs
- Owner: phambanhan
- License: mit
- Created: 2019-09-25T02:59:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T00:41:26.000Z (almost 2 years ago)
- Last Synced: 2024-11-06T19:09:18.457Z (about 2 months ago)
- Topics: egg, egg-plugin, eggjs, kafka, kafkajs
- Language: JavaScript
- Size: 892 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-apache-kafkajs
[kafkajs](https://kafka.js.org/) 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
```bash
$ npm i egg-apache-kafkajs --save
```
or```bash
$ yarn add egg-apache-kafkajs
```## Configuration
```js
// {app_root}/config/config.default.js
exports.kafka = {
options: {
clientId: 'clientId',
brokers: [ 'broker:9092' ],
connectionTimeout: 3000,
},
consumers: [
{
groupId: 'consumer-groupId',
topics: [ 'topic1' ],
},
],
};
``````js
// {app_root}/config/plugin.js
exports.kafka = {
enable: true,
package: 'egg-apache-kafkajs',
};
```## Usage
```js
// Producer
const kafka = this.ctx.app.kafka;
await kafka.send({
topic: 'topic1',
messages: [{
value: 'Hello World',
}],
});
``````js
// 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](LICENSE)