ax-rocketmq
v3.0.2
Published
Fork Aliyun Open Notification Service Client
Downloads
16
Maintainers
Readme
RocketMQ-Nodejs-client
RocketMq Open Notification Service Client (base on opensource project RocketMQ)
Sub module of ali-sdk.
Install
npm install ax-rocketmq --save
Usage
consumer
'use strict';
const httpclient = require('urllib');
const Consumer = require('ax-rocketmq').Consumer;
const consumer = new Consumer({
httpclient,
consumerGroup: 'your-consumer-group',
namesrvAddr: 'your-namesrv-address'
// isBroadcast: true,
});
consumer.subscribe(config.topic, '*', async msg => {
console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
});
consumer.on('error', err => console.log(err));
producer
'use strict';
const httpclient = require('urllib');
const Producer = require('ax-rocketmq').Producer;
const Message = require('ax-rocketmq').Message;
const producer = new Producer({
httpclient,
producerGroup: 'your-producer-group',
namesrvAddr: 'your-namesrv-address'
});
producer.ready(() => {
console.log('producer ready');
const msg = new Message('your-topic', // topic
'TagA', // tag
'Hello ONS !!! ' // body
);
producer.send(msg, (err, sendResult) => console.log(err, sendResult));
});