Aliyun Open Notification Service Client (base on opensource project RocketMQ)
Sub module of ali-sdk.
npm install ali-ons --save
consumer
'use strict';
const httpclient = require('urllib');
const Consumer = require('ali-ons').Consumer;
const consumer = new Consumer({
httpclient,
accessKeyId: 'your-accessKeyId',
accessKeySecret: 'your-AccessKeySecret',
consumerGroup: 'your-consumer-group',
// 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 co = require('co');
const httpclient = require('urllib');
const Producer = require('ali-ons').Producer;
const Message = require('ali-ons').Message;
const producer = new Producer({
httpclient,
accessKeyId: 'your-accessKeyId',
accessKeySecret: 'your-AccessKeySecret',
producerGroup: 'your-producer-group',
});
(async () => {
const msg = new Message('your-topic', // topic
'TagA', // tag
'Hello ONS !!! ' // body
);
// set Message#keys
msg.keys = ['key1'];
const sendResult = await producer.send(msg);
console.log(sendResult);
})().catch(err => console.error(err))