@3g/kafka-wrapper 中文文档教程
Kafka Wrapper
一个轻量级的 Kafka 包装器,用于创建监听器和发布器。
目前在幕后使用 node-rdkafka
。
Usage
Listener
const listener = kafkaListener({
host: '127.0.0.1:29092',
groupId: 'testing.123',
topics: ['test-wrapper'],
}, (message: IMessage) => {
console.log('here be msgs', message);
console.log('message value', message.value.toString());
}, (err: Error) => {
console.error('Err', err);
});
Publisher
const publisher = kafkaPublisher({
host: '127.0.0.1:29092',
clientId: 'testing-wrapper-publisher',
}, (err: Err) => {
console.error('Err', err);
});
publisher.send({
topic: 'test-wrapper',
message: {
stuff: 123,
},
}).then(() => {
console.log('Message sent successfully', i);
}).catch(err => {
console.error('Err sending message', err);
});
Notes
Consumer Groups
Kafka Wrapper
A lightweight Kafka wrapper that creates listeners and publisher.
Currently uses node-rdkafka
behind the scenes.
Usage
Listener
const listener = kafkaListener({
host: '127.0.0.1:29092',
groupId: 'testing.123',
topics: ['test-wrapper'],
}, (message: IMessage) => {
console.log('here be msgs', message);
console.log('message value', message.value.toString());
}, (err: Error) => {
console.error('Err', err);
});
Publisher
const publisher = kafkaPublisher({
host: '127.0.0.1:29092',
clientId: 'testing-wrapper-publisher',
}, (err: Err) => {
console.error('Err', err);
});
publisher.send({
topic: 'test-wrapper',
message: {
stuff: 123,
},
}).then(() => {
console.log('Message sent successfully', i);
}).catch(err => {
console.error('Err sending message', err);
});