qrusty-client 0.2.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 +4 -4
- package/index.js +24 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,12 +22,12 @@ const QrustyClient = require("qrusty-client");
|
|
|
22
22
|
const client = new QrustyClient("http://localhost:6784");
|
|
23
23
|
|
|
24
24
|
(async () => {
|
|
25
|
-
|
|
25
|
+
await client.createQueue("orders", "MaxFirst", true);
|
|
26
26
|
await client.publish("orders", 100, { order_id: 123 });
|
|
27
27
|
const msg = await client.consume("orders", "worker-1");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (msg) {
|
|
29
|
+
await client.ack("orders", msg.id, "worker-1");
|
|
30
|
+
}
|
|
31
31
|
})();
|
|
32
32
|
```
|
|
33
33
|
|
package/index.js
CHANGED
|
@@ -38,20 +38,26 @@ class QrustyClient {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param {string}
|
|
43
|
-
* @param {string}
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {boolean} [allowDuplicates=true]
|
|
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)
|
|
46
45
|
* @returns {Promise<void>}
|
|
47
46
|
*/
|
|
48
|
-
async
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
config
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
|
52
|
+
|
|
53
|
+
if (Object.keys(config).length === 0) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"At least one of newName or allowDuplicates must be specified",
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const data = { name, config };
|
|
60
|
+
await axios.post(`${this.baseUrl}/update-queue`, data);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
/**
|
|
@@ -75,7 +81,12 @@ class QrustyClient {
|
|
|
75
81
|
async publish(queue, priority, payload, maxRetries = 3) {
|
|
76
82
|
const payloadStr =
|
|
77
83
|
typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
78
|
-
const data = {
|
|
84
|
+
const data = {
|
|
85
|
+
queue,
|
|
86
|
+
priority,
|
|
87
|
+
payload: payloadStr,
|
|
88
|
+
max_retries: maxRetries,
|
|
89
|
+
};
|
|
79
90
|
const resp = await axios.post(`${this.baseUrl}/publish`, data);
|
|
80
91
|
return resp.data;
|
|
81
92
|
}
|