egg-kafka-cluster
v0.1.0
Published
provides egg bindings for the kafka.
Downloads
4
Readme
egg-kafka-cluster
provides egg bindings for the kafka.
Install
$ npm i egg-kafka-cluster --save
Configuration
// {app_root}/config/plugin.ts
export const kafkaCluster = {
enable: true,
package: 'egg-kafka-cluster',
};
// {app_root}/config/config.default.ts
exports.kafka = {
consumerGlobalConfig: {
'group.id': 'consumer-default',
'metadata.broker.list': 'kafka',
},
consumerTopicConfig: {
'auto.offset.reset': 'beginning',
},
readStreamOptions: {
topics: [ 'activity' ],
},
producerGlobalConfig: {
'metadata.broker.list': 'kafka',
},
producerTopicConfig: {},
writeStreamOptions: {
topic: 'activity',
},
};
Usage
// Producer
this.app.kafka.write('activity', {status: 'start'});
// Consumer
// {app_root}/app/mq/Activity.ts
import { Consumer } from 'egg-kafka-cluster';
export default class Activity extends Consumer {
async run(data: Record<string, unknown>) {
console.log('Topic Activity Data: %s', JSON.stringify(data));
}
}
see config/config.default.ts for more detail.
Questions & Suggestions
Please open an issue here.