@efebia/sqs-queue-v2 0.0.7 → 0.0.9
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 +80 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @efebia/sqs-queue-v2
|
|
2
|
+
|
|
3
|
+
AWS SQS queue consumer built on `@efebia/queue`, using the AWS SDK v2 (`aws-sdk`).
|
|
4
|
+
|
|
5
|
+
> If you are starting a new project, prefer [`@efebia/sqs-queue-v3`](../sqs-queue-v3) which uses the modern modular AWS SDK v3.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @efebia/sqs-queue-v2
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import AWS from 'aws-sdk';
|
|
17
|
+
import { Queue } from '@efebia/sqs-queue-v2';
|
|
18
|
+
|
|
19
|
+
type MyMessage = { userId: string; action: string };
|
|
20
|
+
|
|
21
|
+
const sqs = new AWS.SQS({ region: 'eu-west-1' });
|
|
22
|
+
|
|
23
|
+
const queue = new Queue<MyMessage>({
|
|
24
|
+
client: sqs,
|
|
25
|
+
receiveOptions: {
|
|
26
|
+
QueueUrl: 'https://sqs.eu-west-1.amazonaws.com/123456789/my-queue',
|
|
27
|
+
WaitTimeSeconds: 20,
|
|
28
|
+
MaxNumberOfMessages: 1,
|
|
29
|
+
},
|
|
30
|
+
sleepTimeout: 5000,
|
|
31
|
+
logger: (obj, msg) => console.log(msg, obj),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Start consuming
|
|
35
|
+
queue.start(async (name, params, state) => {
|
|
36
|
+
console.log(`Received "${name}":`, params);
|
|
37
|
+
// set state.del = false to leave the message in the queue
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Send a message
|
|
41
|
+
await queue.send({ name: 'doWork', params: { userId: '42', action: 'sync' } });
|
|
42
|
+
|
|
43
|
+
// Stop the loop
|
|
44
|
+
queue.stop();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### `new Queue<TMessage>(options)`
|
|
50
|
+
|
|
51
|
+
| Option | Type | Default | Description |
|
|
52
|
+
|--------|------|---------|-------------|
|
|
53
|
+
| `client` | `AWS.SQS` | — | **Required.** Configured SQS client instance |
|
|
54
|
+
| `receiveOptions` | `AWS.SQS.ReceiveMessageRequest` | — | **Required.** Passed directly to `receiveMessage`. Must include `QueueUrl`. |
|
|
55
|
+
| `receiveOptions.WaitTimeSeconds` | `number` | `20` | Long-polling wait time |
|
|
56
|
+
| `receiveOptions.MaxNumberOfMessages` | `number` | `1` | Max messages per receive call |
|
|
57
|
+
| `canRead` | `() => boolean \| Promise<boolean>` | `() => true` | Called before each receive; returning `false` skips the iteration |
|
|
58
|
+
| `logger` | `(obj, msg?) => void` | no-op | Logging function for errors and warnings |
|
|
59
|
+
| `sleepTimeout` | `number` | `5000` | Ms to wait after an error before retrying |
|
|
60
|
+
| `errorCallback` | `(error) => void` | `console.error` | Called on uncaught errors in the loop |
|
|
61
|
+
|
|
62
|
+
### Inherited from `@efebia/queue`
|
|
63
|
+
|
|
64
|
+
- `start(callback, canThrow?)` — starts the polling loop
|
|
65
|
+
- `stop()` — signals the loop to stop
|
|
66
|
+
- `resume(callback)` — restarts a stopped queue
|
|
67
|
+
- `isRunning()` — returns `true` if the loop is active
|
|
68
|
+
- `send(message)` — sends a message (adds `createdAt` automatically)
|
|
69
|
+
|
|
70
|
+
**Callback signature:**
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
(name: string, params: TMessage, state: { del: boolean }) => void | Promise<void>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
After the callback resolves, the message is deleted from SQS unless `state.del` is set to `false`.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efebia/sqs-queue-v2",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@types/node": "^18.11.18",
|
|
7
7
|
"typescript": "~5.8.3"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@efebia/queue": "^0.0.
|
|
10
|
+
"@efebia/queue": "^0.0.7",
|
|
11
11
|
"aws-sdk": "^2.1292.0"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|