- 待完善
npm install egg-kafka --save
- config/config.{env}.js:
module.exports = appInfo => {
config.kafka = {
client: {
host: 'localhost', // host
port: '3306', // 端口号
},
app: true, // 是否加载到 app 上,默认开启
agent: true, // 是否加载到 agent 上,默认关闭
};
return config;
}
example:
'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:
'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
}]
)
}
-------------- 待完善 ---------------
##胡猪te