Skip to content

基于阿里云mq http sdk,参考部分ali-ons代码

License

Notifications You must be signed in to change notification settings

WMTcore/ali-ons-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ali-ons-http

基于阿里云mq http sdk,参考部分ali-ons代码

Install

npm install ali-ons-egg --save

Usage

consumer

'use strict';

const Consumer = require('ali-ons-http').Consumer;
const consumer = new Consumer({
  accessKeyId: 'your-accessKeyId',
  accessKeySecret: 'your-AccessKeySecret',
  consumerGroup: 'your-consumer-group',
  // onsAddr: '', // ons http的接入地址
  // instanceId:'', // 公网实例不要填,会报权限问题
});

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 Producer = require('ali-ons-http').Producer;
const Message = require('ali-ons-http').Message;

const producer = new Producer({
  accessKeyId: 'your-accessKeyId',
  accessKeySecret: 'your-AccessKeySecret',
  producerGroup: 'your-producer-group',
  // onsAddr: '', // ons http的接入地址
  // instanceId:'', // 公网实例不要填,会报权限问题
});

(async () => {
  const msg = new Message('your-topic', // topic
    'TagA', // tag
    'Hello ONS !!! ' // body
  );

  // set Message#keys
  msg.keys = ['key1'];

  // delay consume
  // msg.setStartDeliverTime(Date.now() + 5000);

  const sendResult = await producer.send(msg);
  console.log(sendResult);
})().catch(err => console.error(err))

About

基于阿里云mq http sdk,参考部分ali-ons代码

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published