qrusty-client 0.6.0 → 0.7.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 +28 -1
- package/index.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Node.js client for the qrusty priority queue server API.
|
|
|
8
8
|
- Publish, consume, ack, and purge messages
|
|
9
9
|
- List and manage queues
|
|
10
10
|
- Promise-based API using axios
|
|
11
|
+
- WebSocket client (`WsSession`) for push-based delivery
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
|
@@ -17,8 +18,10 @@ npm install qrusty-client
|
|
|
17
18
|
|
|
18
19
|
## Usage
|
|
19
20
|
|
|
21
|
+
### HTTP client
|
|
22
|
+
|
|
20
23
|
```js
|
|
21
|
-
const QrustyClient = require("qrusty-client");
|
|
24
|
+
const { QrustyClient } = require("qrusty-client");
|
|
22
25
|
const client = new QrustyClient("http://localhost:6784");
|
|
23
26
|
|
|
24
27
|
(async () => {
|
|
@@ -31,6 +34,30 @@ const client = new QrustyClient("http://localhost:6784");
|
|
|
31
34
|
})();
|
|
32
35
|
```
|
|
33
36
|
|
|
37
|
+
### WebSocket client
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { WsSession } = require("qrusty-client");
|
|
41
|
+
|
|
42
|
+
(async () => {
|
|
43
|
+
const session = new WsSession("ws://localhost:6784");
|
|
44
|
+
await session.connect();
|
|
45
|
+
|
|
46
|
+
const id = await session.publish("orders", "hello", 10);
|
|
47
|
+
|
|
48
|
+
for await (const msg of session.subscribe("orders")) {
|
|
49
|
+
console.log(msg.payload);
|
|
50
|
+
await session.ack(msg.queue, msg.id);
|
|
51
|
+
break; // or keep processing
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await session.close();
|
|
55
|
+
})();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
If the server closes the connection, all pending `publish`/`ack`/`nack` calls
|
|
59
|
+
reject immediately and any active `subscribe` iterators stop iterating.
|
|
60
|
+
|
|
34
61
|
## Documentation
|
|
35
62
|
|
|
36
63
|
Generate HTML docs with:
|
package/index.js
CHANGED
|
@@ -190,6 +190,7 @@ class QrustyClient {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// ---------------------------------------------------------------------------
|
|
193
|
+
// Implements: WS-0019
|
|
193
194
|
// WsSession – WebSocket client (WS-0019)
|
|
194
195
|
// ---------------------------------------------------------------------------
|
|
195
196
|
|
|
@@ -248,9 +249,26 @@ class WsSession {
|
|
|
248
249
|
this._ws.once("open", resolve);
|
|
249
250
|
this._ws.once("error", reject);
|
|
250
251
|
this._ws.on("message", (raw) => this._onMessage(raw));
|
|
252
|
+
this._ws.on("close", () => this._onClose());
|
|
251
253
|
});
|
|
252
254
|
}
|
|
253
255
|
|
|
256
|
+
_onClose() {
|
|
257
|
+
// Reject all pending request promises so callers unblock immediately.
|
|
258
|
+
for (const { reject } of this._pending.values()) {
|
|
259
|
+
reject(new Error("connection closed"));
|
|
260
|
+
}
|
|
261
|
+
this._pending.clear();
|
|
262
|
+
|
|
263
|
+
// Reject all delivery waiters so any active subscribe iterators unblock.
|
|
264
|
+
for (const waiters of this._deliverQueues.values()) {
|
|
265
|
+
for (const { reject } of waiters.splice(0)) {
|
|
266
|
+
reject(new Error("connection closed"));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this._deliverQueues.clear();
|
|
270
|
+
}
|
|
271
|
+
|
|
254
272
|
/** Close the connection gracefully. */
|
|
255
273
|
async close() {
|
|
256
274
|
return new Promise((resolve) => {
|