1 | ali-ons
|
2 | =======
|
3 |
|
4 | [![NPM version][npm-image]][npm-url]
|
5 | [![ci-actions][ci-image]][ci-url]
|
6 | [![David deps][david-image]][david-url]
|
7 |
|
8 | [npm-image]: https://img.shields.io/npm/v/ali-ons.svg?style=flat-square
|
9 | [npm-url]: https://npmjs.org/package/ali-ons
|
10 | [ci-image]: https://github.com/ali-sdk/ali-ons/actions/workflows/ci-actions.yml/badge.svg
|
11 | [ci-url]: https://github.com/ali-sdk/ali-ons/actions/workflows/ci-actions.yml
|
12 | [david-image]: https://img.shields.io/david/ali-sdk/ali-ons.svg?style=flat-square
|
13 | [david-url]: https://david-dm.org/ali-sdk/ali-ons
|
14 |
|
15 | Aliyun Open Notification Service Client (base on opensource project [RocketMQ](https://rocketmq.apache.org/))
|
16 |
|
17 | Sub module of [ali-sdk](https://github.com/ali-sdk/ali-sdk).
|
18 |
|
19 | ## Install
|
20 |
|
21 | ```bash
|
22 | npm install ali-ons --save
|
23 | ```
|
24 |
|
25 | ## Usage
|
26 |
|
27 | consumer
|
28 |
|
29 | ```js
|
30 | 'use strict';
|
31 |
|
32 | const httpclient = require('urllib');
|
33 | const Consumer = require('ali-ons').Consumer;
|
34 | const consumer = new Consumer({
|
35 | httpclient,
|
36 | accessKeyId: 'your-accessKeyId',
|
37 | accessKeySecret: 'your-AccessKeySecret',
|
38 | consumerGroup: 'your-consumer-group',
|
39 | // namespace: '', // aliyun namespace support
|
40 | // isBroadcast: true,
|
41 | });
|
42 |
|
43 | consumer.subscribe(config.topic, '*', async msg => {
|
44 | console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
|
45 | // return Consumer.ACTION_RETRY; // you can return ACTION_RETRY, then this message will be directly retried
|
46 | });
|
47 |
|
48 | consumer.on('error', err => console.log(err));
|
49 | ```
|
50 |
|
51 | If you want to use sql filter, you can subscribe a topic with a sql expression:
|
52 | ```js
|
53 | consumer.subscribe(
|
54 | config.topic,
|
55 | {
|
56 | expressionType: 'SQL92',
|
57 | subString: 'a is not null'
|
58 | },
|
59 | async msg => {
|
60 | console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
|
61 | }
|
62 | );
|
63 | ```
|
64 | For more information about sql filter, see: [Filter Messages By SQL92](https://rocketmq.apache.org/rocketmq/filter-messages-by-sql92-in-rocketmq/)
|
65 |
|
66 | producer
|
67 |
|
68 | ```js
|
69 | 'use strict';
|
70 | const httpclient = require('urllib');
|
71 | const Producer = require('ali-ons').Producer;
|
72 | const Message = require('ali-ons').Message;
|
73 |
|
74 | const producer = new Producer({
|
75 | httpclient,
|
76 | accessKeyId: 'your-accessKeyId',
|
77 | accessKeySecret: 'your-AccessKeySecret',
|
78 | producerGroup: 'your-producer-group',
|
79 | // namespace: '', // aliyun namespace support
|
80 | });
|
81 |
|
82 | (async () => {
|
83 | const msg = new Message('your-topic', // topic
|
84 | 'TagA', // tag
|
85 | 'Hello ONS !!! ' // body
|
86 | );
|
87 |
|
88 | // set Message#keys
|
89 | msg.keys = ['key1'];
|
90 |
|
91 | // delay consume
|
92 | // msg.setStartDeliverTime(Date.now() + 5000);
|
93 |
|
94 | const sendResult = await producer.send(msg);
|
95 | console.log(sendResult);
|
96 | })().catch(err => console.error(err))
|
97 | ```
|
98 |
|
99 | ## Secure Keys
|
100 |
|
101 | Please contact to @gxcsoccer to give you accessKey
|
102 |
|
103 | - [ons secure data](https://sharelock.io/1/UM02CJiYyhXiZDOn1nhX0iqPqMIQtdwI_T5BY3F-tHs.d8-ycA/01veKH9kgAuFuKCqlVPzGsyPWJ8mQLaKPJjjcB9tpdbvi9L6XQ/IgqDvAdVDMzV9lK2gQzyAj7q-CNk8-1tWrLmdqMV0oJ5qgky40/HgpZyKKDfOGAcyqQ20RUdRgCLRWqF8LUUko0uDl_L-ATNOsi5z/W2bsvBc8tAoqSwNR7u2Sqe6XkNmD98s3UQOK-6T8--VwTbHzcG/dwkHwie3EkGB-TbiMnbRh7_5A-DaOTCtALP3xvl4G0XKxuOriC/2yfuPp7WRucTAoqx2STO5Hv3MZEhh3IXf7YiOQ8pWDDqjLuQSY/_irqzYyeseY9m106ksMUq3-yS_qkBRIuoyL-hHk9ZRhGppsdA5/Dw4Pjg.fmNP3aFkLnvPuhlPRwNcng)
|
104 |
|
105 | ## License
|
106 |
|
107 | [MIT](LICENSE)
|