Skip to content

DanielWLam/egg-kafka

 
 

Repository files navigation

eggjs kafka插件

NPM version build status Test coverage David deps Known Vulnerabilities npm download

  • 待完善

Install

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;
}

API

Producer

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 
      }]
    )
}

HighLevelProducer same as Producer

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

Comuser

HighLevelConsumer

ConsumerGroup

Offset

About

kafka plugin for eggjs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 94.0%
  • Shell 6.0%