项目作者: ali-sdk

项目描述 :
Aliyun Open Notification Service Client
高级语言: JavaScript
项目地址: git://github.com/ali-sdk/ali-ons.git
创建时间: 2015-11-12T05:17:02Z
项目社区:https://github.com/ali-sdk/ali-ons

开源协议:MIT License

下载


ali-ons

NPM version
ci-actions
David deps

Aliyun Open Notification Service Client (base on opensource project RocketMQ)

Sub module of ali-sdk.

Install

  1. npm install ali-ons --save

Usage

consumer

  1. 'use strict';
  2. const httpclient = require('urllib');
  3. const Consumer = require('ali-ons').Consumer;
  4. const consumer = new Consumer({
  5. httpclient,
  6. accessKeyId: 'your-accessKeyId',
  7. accessKeySecret: 'your-AccessKeySecret',
  8. consumerGroup: 'your-consumer-group',
  9. // namespace: '', // aliyun namespace support
  10. // isBroadcast: true,
  11. });
  12. consumer.subscribe(config.topic, '*', async msg => {
  13. console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
  14. // return Consumer.ACTION_RETRY; // you can return ACTION_RETRY, then this message will be directly retried
  15. });
  16. consumer.on('error', err => console.log(err));

If you want to use sql filter, you can subscribe a topic with a sql expression:

  1. consumer.subscribe(
  2. config.topic,
  3. {
  4. expressionType: 'SQL92',
  5. subString: 'a is not null'
  6. },
  7. async msg => {
  8. console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
  9. }
  10. );

For more information about sql filter, see: Filter Messages By SQL92

producer

  1. 'use strict';
  2. const httpclient = require('urllib');
  3. const Producer = require('ali-ons').Producer;
  4. const Message = require('ali-ons').Message;
  5. const producer = new Producer({
  6. httpclient,
  7. accessKeyId: 'your-accessKeyId',
  8. accessKeySecret: 'your-AccessKeySecret',
  9. producerGroup: 'your-producer-group',
  10. // namespace: '', // aliyun namespace support
  11. });
  12. (async () => {
  13. const msg = new Message('your-topic', // topic
  14. 'TagA', // tag
  15. 'Hello ONS !!! ' // body
  16. );
  17. // set Message#keys
  18. msg.keys = ['key1'];
  19. // delay consume
  20. // msg.setStartDeliverTime(Date.now() + 5000);
  21. const sendResult = await producer.send(msg);
  22. console.log(sendResult);
  23. })().catch(err => console.error(err))

Secure Keys

Please contact to @gxcsoccer to give you accessKey

License

MIT