qrusty-client 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/index.js +174 -67
- package/package.json +18 -18
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/index.html +0 -65
- package/docs/index.js.html +0 -136
- package/docs/module-QrustyClient-QrustyClient.html +0 -1317
- package/docs/module-QrustyClient.html +0 -172
- package/docs/scripts/linenumber.js +0 -25
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/scripts/prettify/lang-css.js +0 -2
- package/docs/scripts/prettify/prettify.js +0 -28
- package/docs/styles/jsdoc-default.css +0 -358
- package/docs/styles/prettify-jsdoc.css +0 -111
- package/docs/styles/prettify-tomorrow.css +0 -132
- package/jsdoc.json +0 -13
- package/test.js +0 -20
package/README.md
CHANGED
|
@@ -18,13 +18,16 @@ npm install qrusty-client
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
|
-
const QrustyClient = require(
|
|
22
|
-
const client = new QrustyClient(
|
|
21
|
+
const QrustyClient = require("qrusty-client");
|
|
22
|
+
const client = new QrustyClient("http://localhost:6784");
|
|
23
23
|
|
|
24
24
|
(async () => {
|
|
25
|
-
await client.
|
|
26
|
-
|
|
27
|
-
await client.
|
|
25
|
+
await client.createQueue("orders", "MaxFirst", true);
|
|
26
|
+
await client.publish("orders", 100, { order_id: 123 });
|
|
27
|
+
const msg = await client.consume("orders", "worker-1");
|
|
28
|
+
if (msg) {
|
|
29
|
+
await client.ack("orders", msg.id, "worker-1");
|
|
30
|
+
}
|
|
28
31
|
})();
|
|
29
32
|
```
|
|
30
33
|
|
package/index.js
CHANGED
|
@@ -2,84 +2,191 @@
|
|
|
2
2
|
* QrustyClient - Node.js client for the qrusty priority queue API
|
|
3
3
|
* @module QrustyClient
|
|
4
4
|
*/
|
|
5
|
-
const axios = require(
|
|
5
|
+
const axios = require("axios");
|
|
6
6
|
|
|
7
7
|
class QrustyClient {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create a new QrustyClient
|
|
10
|
+
* @param {string} baseUrl - Base URL of the qrusty server
|
|
11
|
+
*/
|
|
12
|
+
constructor(baseUrl) {
|
|
13
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
async publish(queue, priority, payload, maxRetries = 3) {
|
|
25
|
-
const data = { queue, priority, payload, max_retries: maxRetries };
|
|
26
|
-
const resp = await axios.post(`${this.baseUrl}/publish`, data);
|
|
27
|
-
return resp.data;
|
|
28
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Check server health
|
|
18
|
+
* @returns {Promise<string>}
|
|
19
|
+
*/
|
|
20
|
+
async health() {
|
|
21
|
+
const resp = await axios.get(`${this.baseUrl}/health`);
|
|
22
|
+
return resp.data;
|
|
23
|
+
}
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
25
|
+
/**
|
|
26
|
+
* Create or configure a queue
|
|
27
|
+
* @param {string} name
|
|
28
|
+
* @param {string} [ordering="MaxFirst"] - One of: Fifo | MinFirst | MaxFirst
|
|
29
|
+
* @param {boolean} [allowDuplicates=true]
|
|
30
|
+
* @returns {Promise<void>}
|
|
31
|
+
*/
|
|
32
|
+
async createQueue(name, ordering = "MaxFirst", allowDuplicates = true) {
|
|
33
|
+
const data = {
|
|
34
|
+
name,
|
|
35
|
+
config: { ordering, allow_duplicates: allowDuplicates },
|
|
36
|
+
};
|
|
37
|
+
await axios.post(`${this.baseUrl}/create-queue`, data);
|
|
38
|
+
}
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Update queue configuration (name and/or allow_duplicates)
|
|
42
|
+
* @param {string} name - Current queue name
|
|
43
|
+
* @param {string} [newName] - New name for the queue (optional)
|
|
44
|
+
* @param {boolean} [allowDuplicates] - New allow_duplicates setting (optional)
|
|
45
|
+
* @returns {Promise<void>}
|
|
46
|
+
*/
|
|
47
|
+
async updateQueue(name, newName = undefined, allowDuplicates = undefined) {
|
|
48
|
+
const config = {};
|
|
49
|
+
if (newName !== undefined) config.name = newName;
|
|
50
|
+
if (allowDuplicates !== undefined)
|
|
51
|
+
config.allow_duplicates = allowDuplicates;
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
async purge(queue) {
|
|
62
|
-
const resp = await axios.post(`${this.baseUrl}/purge-queue/${queue}`);
|
|
63
|
-
return resp.data;
|
|
53
|
+
if (Object.keys(config).length === 0) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"At least one of newName or allowDuplicates must be specified",
|
|
56
|
+
);
|
|
64
57
|
}
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
const data = { name, config };
|
|
60
|
+
await axios.post(`${this.baseUrl}/update-queue`, data);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Delete a queue and its messages
|
|
65
|
+
* @param {string} queue
|
|
66
|
+
* @returns {Promise<object>}
|
|
67
|
+
*/
|
|
68
|
+
async deleteQueue(queue) {
|
|
69
|
+
const resp = await axios.delete(`${this.baseUrl}/delete-queue/${queue}`);
|
|
70
|
+
return resp.data;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Publish a message to a queue
|
|
75
|
+
* @param {string} queue
|
|
76
|
+
* @param {number} priority
|
|
77
|
+
* @param {object} payload
|
|
78
|
+
* @param {number} [maxRetries=3]
|
|
79
|
+
* @returns {Promise<object>}
|
|
80
|
+
*/
|
|
81
|
+
async publish(queue, priority, payload, maxRetries = 3) {
|
|
82
|
+
const payloadStr =
|
|
83
|
+
typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
84
|
+
const data = {
|
|
85
|
+
queue,
|
|
86
|
+
priority,
|
|
87
|
+
payload: payloadStr,
|
|
88
|
+
max_retries: maxRetries,
|
|
89
|
+
};
|
|
90
|
+
const resp = await axios.post(`${this.baseUrl}/publish`, data);
|
|
91
|
+
return resp.data;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Consume a message from a queue
|
|
96
|
+
* @param {string} queue
|
|
97
|
+
* @param {string} consumerId
|
|
98
|
+
* @param {number} [timeoutSeconds=30]
|
|
99
|
+
* @returns {Promise<object>}
|
|
100
|
+
*/
|
|
101
|
+
async consume(queue, consumerId, timeoutSeconds = 30) {
|
|
102
|
+
const data = { consumer_id: consumerId, timeout_seconds: timeoutSeconds };
|
|
103
|
+
const resp = await axios.post(`${this.baseUrl}/consume/${queue}`, data);
|
|
104
|
+
return resp.data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Acknowledge a message
|
|
109
|
+
* @param {string} queue
|
|
110
|
+
* @param {string} messageId
|
|
111
|
+
* @param {string} consumerId
|
|
112
|
+
* @returns {Promise<object>}
|
|
113
|
+
*/
|
|
114
|
+
async ack(queue, messageId, consumerId) {
|
|
115
|
+
const data = { consumer_id: consumerId };
|
|
116
|
+
try {
|
|
117
|
+
await axios.post(`${this.baseUrl}/ack/${queue}/${messageId}`, data);
|
|
118
|
+
return true;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
if (e?.response?.status === 404) return false;
|
|
121
|
+
throw e;
|
|
73
122
|
}
|
|
123
|
+
}
|
|
74
124
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Negative-acknowledge a message
|
|
127
|
+
* @param {string} queue
|
|
128
|
+
* @param {string} messageId
|
|
129
|
+
* @param {string} consumerId
|
|
130
|
+
* @returns {Promise<boolean>} True if nack'd, false if not found
|
|
131
|
+
*/
|
|
132
|
+
async nack(queue, messageId, consumerId) {
|
|
133
|
+
const data = { consumer_id: consumerId };
|
|
134
|
+
try {
|
|
135
|
+
await axios.post(`${this.baseUrl}/nack/${queue}/${messageId}`, data);
|
|
136
|
+
return true;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
if (e?.response?.status === 404) return false;
|
|
139
|
+
throw e;
|
|
82
140
|
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Purge a queue
|
|
145
|
+
* @param {string} queue
|
|
146
|
+
* @returns {Promise<object>}
|
|
147
|
+
*/
|
|
148
|
+
async purge(queue) {
|
|
149
|
+
const resp = await axios.post(`${this.baseUrl}/purge-queue/${queue}`);
|
|
150
|
+
return resp.data;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get stats for all queues
|
|
155
|
+
* @returns {Promise<object>}
|
|
156
|
+
*/
|
|
157
|
+
async stats() {
|
|
158
|
+
const resp = await axios.get(`${this.baseUrl}/stats`);
|
|
159
|
+
return resp.data;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get statistics for a specific queue
|
|
164
|
+
* @param {string} queue
|
|
165
|
+
* @returns {Promise<object>}
|
|
166
|
+
*/
|
|
167
|
+
async queueStats(queue) {
|
|
168
|
+
const resp = await axios.get(`${this.baseUrl}/queue-stats/${queue}`);
|
|
169
|
+
return resp.data;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get time-series metrics for a queue
|
|
174
|
+
* @param {string} queue
|
|
175
|
+
* @returns {Promise<object>}
|
|
176
|
+
*/
|
|
177
|
+
async queueMetrics(queue) {
|
|
178
|
+
const resp = await axios.get(`${this.baseUrl}/queues/${queue}/metrics`);
|
|
179
|
+
return resp.data;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* List all queues
|
|
184
|
+
* @returns {Promise<object>}
|
|
185
|
+
*/
|
|
186
|
+
async listQueues() {
|
|
187
|
+
const resp = await axios.get(`${this.baseUrl}/queues`);
|
|
188
|
+
return resp.data;
|
|
189
|
+
}
|
|
83
190
|
}
|
|
84
191
|
|
|
85
192
|
module.exports = QrustyClient;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
2
|
+
"name": "qrusty-client",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Node.js client for the qrusty priority queue server API.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "Gordon Greene <greeng3@obscure-reference.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"docs": "jsdoc -c jsdoc.json"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"axios": "^1.13.2"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"jest": "30.2.0",
|
|
17
|
+
"jsdoc": "^4.0.5"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
Binary file
|