@aws-sdk/lib-sqs 3.1163.0 → 3.1165.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.
Files changed (2) hide show
  1. package/README.md +101 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @aws-sdk/lib-sqs
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@aws-sdk/lib-sqs/latest.svg)](https://www.npmjs.com/package/@aws-sdk/lib-sqs)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/lib-sqs.svg)](https://www.npmjs.com/package/@aws-sdk/lib-sqs)
5
+
6
+ An SQS poller with long polling, concurrency limits, automatic deletion, visibility timeout extension, error backoff, and graceful shutdown.
7
+
8
+ ```sh
9
+ npm install @aws-sdk/lib-sqs @aws-sdk/client-sqs
10
+ ```
11
+
12
+ `@aws-sdk/client-sqs` is a peer dependency.
13
+
14
+ ## Usage
15
+
16
+ ### Event-based
17
+
18
+ ```js
19
+ import { SQSPoller } from "@aws-sdk/lib-sqs";
20
+
21
+ const poller = new SQSPoller({ queueUrl: "https://sqs.us-east-1.amazonaws.com/123456789/my-queue" });
22
+
23
+ // Deleted once the handler resolves. If it throws, the message is redelivered after the visibility timeout.
24
+ const unsubscribe = poller.on("message", async (message) => {
25
+ console.log(message.body);
26
+ });
27
+ poller.on("error", (error) => console.error(error));
28
+
29
+ poller.start();
30
+ ```
31
+
32
+ Messages are only auto-deleted while at least one `message` listener is registered. `on()` returns a function that removes the listener, and `off(event)` removes all listeners for an event.
33
+
34
+ ### Async iteration
35
+
36
+ ```js
37
+ for await (const message of poller) {
38
+ console.log(message.body);
39
+ if (done) {
40
+ message.enqueueDelete(); // breaking out skips auto-delete for the current message
41
+ break;
42
+ }
43
+ }
44
+ ```
45
+
46
+ Each message is deleted when the loop moves on to the next one. Only one mode can run at a time.
47
+
48
+ ### Stopping
49
+
50
+ ```js
51
+ await poller.stop(); // waits for in-flight work, flushes pending deletes, then resolves with stats
52
+ await poller.stop(false); // returns right away. Running handlers keep going and their messages are still deleted
53
+ ```
54
+
55
+ Don't `await poller.stop()` inside a `message` handler or a `for await` body. Shutdown waits for that work, so the call waits the full `shutdownTimeoutMs` and then emits a `TimeoutError`. Use `void poller.stop()` or `break` instead. Passing an `abortSignal` also stops the poller gracefully, e.g. on `SIGTERM`.
56
+
57
+ ## Options
58
+
59
+ Timing options are in milliseconds.
60
+
61
+ | Option | Default | Notes |
62
+ | ------------------------------------------------ | ------------------ | ------------------------------------------------------------------------------------------------------ |
63
+ | `queueUrl` | required | |
64
+ | `client` / `clientConfig` | | An `SQSClient`, or config for a new one. `client` wins if both are set. |
65
+ | `receiveWaitTimeMs` | `20_000` | Long-poll wait (0–20,000). Rounded down to whole seconds, so values under 1,000 short poll. |
66
+ | `receiveBatchSize` | `10` | Messages per receive (1–10). |
67
+ | `maxConcurrency` | `10` | Max messages in flight. Event mode only. Use `1` to keep FIFO ordering within a message group. |
68
+ | `activePollIntervalMs` / `idlePollIntervalMs` | `0` | Delay after a poll with or without messages. The idle delay is 100 ms when `receiveWaitTimeMs` is `0`. |
69
+ | `idleTimeoutMs` | | Stop after this long without a message. |
70
+ | `systemAttributeNames` / `messageAttributeNames` | | Attributes to request, e.g. `["All"]`. |
71
+ | `deleteMessages` | `true` | Set `false` to delete manually with `message.enqueueDelete()`. |
72
+ | `deleteBatchSize` / `deleteWaitMs` | `10` / `2_000` | Deletes are batched until full or until the wait elapses. |
73
+ | `visibilityTimeoutMs` | queue default | |
74
+ | `extendTimeout` | `false` | Keep extending visibility while a message is processed. Requires `visibilityTimeoutMs`. |
75
+ | `extendTimeoutAdvanceMs` | `5_000` | How early to extend. Must be less than `visibilityTimeoutMs`. |
76
+ | `maxTimeoutExtensionMs` | 12 hours | Then extension stops and `heartbeatExpired` fires. |
77
+ | `backoffMs` / `maxBackoffMs` | `1_000` / `30_000` | Backoff after receive errors, doubling up to the max. |
78
+ | `shutdownTimeoutMs` | `30_000` | Max wait for in-flight work on a graceful stop. |
79
+ | `abortSignal` | | Aborting stops gracefully. |
80
+ | `beforeRequest` | | Called before each receive. May be async. Throwing stops polling. |
81
+
82
+ ## Events
83
+
84
+ - `message`: a message was received.
85
+ - `error`: any error, including failed receives, deletes and extensions, handlers that throw, shutdown timeouts, and `beforeRequest` throwing. Without an `error` listener, errors are dropped silently.
86
+ - `stopped`: shutdown finished, with the final stats. Fires once per run.
87
+ - `empty`: a poll returned nothing. `idle`: `idleTimeoutMs` elapsed and the poller is stopping.
88
+ - `timeoutExtended` and `heartbeatExpired`: a visibility extension happened, or `maxTimeoutExtensionMs` was reached.
89
+
90
+ ## Messages
91
+
92
+ Each message has `body`, `messageId`, `receiptHandle`, `attributes`, `messageAttributes`, `receivedAt`, and the underlying `raw` SQS message, plus:
93
+
94
+ - `enqueueDelete()`: delete it (batched).
95
+ - `keep()`: leave it on the queue. It reappears after the visibility timeout.
96
+ - `release()`: make it visible again immediately, e.g. to retry sooner after a failure.
97
+ - `changeVisibility(timeoutMs)`: set a new visibility timeout. This stops automatic extension, and the message is still auto-deleted.
98
+
99
+ ## Stats and errors
100
+
101
+ `poller.running`, `poller.inFlight` (event mode only), `poller.getStats()`, and `poller.toJSON()` report state. Counters accumulate across runs, since a poller can be restarted after `stop()`. Errors extend `PollerError`: `TimeoutError` (shutdown took longer than `shutdownTimeoutMs`), `DeleteError` (with `failures` and the failed `messageIds`), and `VisibilityExtensionError` (with `messageId`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/lib-sqs",
3
- "version": "3.1163.0",
3
+ "version": "3.1165.0",
4
4
  "description": "SQS message poller with auto-delete, backoff, and graceful shutdown",
5
5
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/lib/lib-sqs",
6
6
  "license": "Apache-2.0",
@@ -44,7 +44,7 @@
44
44
  "tslib": "^2.6.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@aws-sdk/client-sqs": "3.1163.0",
47
+ "@aws-sdk/client-sqs": "3.1165.0",
48
48
  "@tsconfig/recommended": "1.0.1",
49
49
  "@types/node": "^20.14.8",
50
50
  "concurrently": "7.0.0",
@@ -53,7 +53,7 @@
53
53
  "typescript": "~7.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
- "@aws-sdk/client-sqs": "^3.1163.0"
56
+ "@aws-sdk/client-sqs": "^3.1165.0"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=20.0.0"