egg-kafka
Version:
Kafka plugin for egg
74 lines (66 loc) • 2.65 kB
Markdown
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[]: https://img.shields.io/npm/v/egg-kafka.svg?style=flat-square
[]: https://npmjs.org/package/egg-kafka
[]: https://img.shields.io/travis/ntfs32/egg-kafka.svg?style=flat-square
[]: https://travis-ci.org/ntfs32/egg-kafka
[]: https://codecov.io/gh/ntfs32/egg-kafka/branch/master/graph/badge.svg
[]: https://codecov.io/gh/ntfs32/egg-kafka
[]: https://img.shields.io/david/ntfs32/egg-kafka.svg?style=flat-square
[]: https://david-dm.org/ntfs32/egg-kafka
[]: https://snyk.io/test/github/ntfs32/egg-kafka/badge.svg?style=flat-square
[]: https://snyk.io/test/github/ntfs32/egg-kafka
[]: https://img.shields.io/npm/dm/egg-kafka.svg?style=flat-square
[]: https://npmjs.org/package/egg-kafka
- 待完善
```bash
npm install egg-kafka --save
```
- config/config.{env}.js:
```javascript
module.exports = appInfo => {
config.kafka = {
client: {
host: 'localhost', // host
port: '3306', // 端口号
},
app: true, // 是否加载到 app 上,默认开启
agent: true, // 是否加载到 agent 上,默认关闭
};
return config;
}
```
example:
```javascript
'use strict'
module.exports = function * () {
//producer() optionl arguments true/false it`s aysnc/sync to create topics in kafka-node
let createTopicsResult = yield this.app.kafka.producer().createTopicsAsync(['topic5'], true)
// send create topics request to the kafka server , but there not anything response,why ?
let sendResult = yield this.app.kafka.producer().sendAsync([{ topic: 'topic5', messages: 'test' + new Date().getSeconds(), partition: 0 }])
}
```
example:
```javascript
'use strict'
module.exports = function * () {
//producer() optionl arguments true/false it`s aysnc/sync to create topics in kafka-node
let createTopicsResult = yield this.app.kafka.highLevelProducer().createTopicsAsync(['topic5'], true)
// send create topics request to the kafka server , but there not anything response,why ?
let sendResult = yield this.app.kafka.highLevelProducer().sendAsync([{ topic: 'topic5', messages: 'test' + new Date().getSeconds(), partition: 0 }])
}
```
-------------- 待完善 ----------------