@fgiova/fastify-sqs-consumer 1.0.0 → 1.1.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 +14 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# fastify sqs-consumer
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
[](https://www.npmjs.com/package/@fgiova/fastify-rest-gateway)
|
|
3
|
+

|
|
4
|
+
[](http://www.typescriptlang.org/)
|
|
5
5
|
## Description
|
|
6
6
|
This plugin for fastify 4.x allows you to consume messages from AWS SQS queues.
|
|
7
7
|
On fastify shutdown a simple wait function is called to wait for the end of the processing of the messages in progress.
|
|
@@ -32,16 +32,17 @@ fastify.register(require("fastify-sqs-consumer"), [
|
|
|
32
32
|
### Options
|
|
33
33
|
Options are an array of objects with the following properties (one more for each queue):
|
|
34
34
|
|
|
35
|
-
| Option
|
|
36
|
-
|
|
37
|
-
| url*
|
|
38
|
-
| waitTimeSeconds
|
|
39
|
-
| timeout
|
|
40
|
-
| batchSize
|
|
41
|
-
| handlerFunction*
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
35
|
+
| Option | Type | Description |
|
|
36
|
+
|------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
37
|
+
| url* | string | The URL of the Amazon SQS queue from which messages are received. |
|
|
38
|
+
| waitTimeSeconds | number | The duration (in seconds, default 20s) for which the call waits for a message to arrive in the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call returns successfully with an empty list of messages. |
|
|
39
|
+
| timeout | number | The duration before the message is considered as failed: default 90000ms. |
|
|
40
|
+
| batchSize | number | The maximum number of messages to return. Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values: 1 to 10. Default: 1. |
|
|
41
|
+
| handlerFunction* | function | The function that will be called for each message. |
|
|
42
|
+
| messageAttributeNames | string[] | Array of caught message's attributes for each message |
|
|
43
|
+
| attributeNames | string[] | Array of caught queue's attributes for each message |
|
|
44
|
+
| events | object | Events functions for the consumer (detail in next table) |
|
|
45
|
+
| sqs | SQSClient | Initialized SQS Client (useful for testing sessions) |
|
|
45
46
|
|
|
46
47
|
### handlerFunction
|
|
47
48
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare function sqsConsumerPlugin(fastify: FastifyInstance, options: {
|
|
|
24
24
|
waitTimeSeconds?: number;
|
|
25
25
|
batchSize?: number;
|
|
26
26
|
attributeNames?: string[];
|
|
27
|
+
messageAttributeNames?: string[];
|
|
27
28
|
events?: eventsHandlers;
|
|
28
29
|
sqs?: SQSClient;
|
|
29
30
|
}[], done: any): void;
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
|
6
6
|
const sqs_consumer_1 = require("sqs-consumer");
|
|
7
7
|
const promises_1 = require("timers/promises");
|
|
8
8
|
;
|
|
9
|
-
function createConsumer(fastify, queueUrl, handlerFunction, meta, timeout = 90000, waitTimeSeconds = 20, batchSize = 1, attributeNames = [], events, sqs) {
|
|
9
|
+
function createConsumer(fastify, queueUrl, handlerFunction, meta, timeout = 90000, waitTimeSeconds = 20, batchSize = 1, attributeNames = [], messageAttributeNames = [], events, sqs) {
|
|
10
10
|
return sqs_consumer_1.Consumer.create({
|
|
11
11
|
queueUrl,
|
|
12
12
|
handleMessageTimeout: 0,
|
|
@@ -15,6 +15,7 @@ function createConsumer(fastify, queueUrl, handlerFunction, meta, timeout = 9000
|
|
|
15
15
|
batchSize,
|
|
16
16
|
sqs,
|
|
17
17
|
attributeNames,
|
|
18
|
+
messageAttributeNames,
|
|
18
19
|
handleMessage: async function handleMessageFunction(message) {
|
|
19
20
|
meta.pendingMessages++;
|
|
20
21
|
try {
|
|
@@ -90,8 +91,8 @@ function sqsConsumerPlugin(fastify, options, done) {
|
|
|
90
91
|
const consumers = [];
|
|
91
92
|
fastify.decorate("sqsConsumers", consumers);
|
|
92
93
|
for (const handler of options) {
|
|
93
|
-
const { queueUrl, handlerFunction, timeout, waitTimeSeconds, batchSize, attributeNames, events, sqs } = handler;
|
|
94
|
-
consumers.push(createConsumer(fastify, queueUrl, handlerFunction, metaData, timeout, waitTimeSeconds, batchSize, attributeNames, events, sqs));
|
|
94
|
+
const { queueUrl, handlerFunction, timeout, waitTimeSeconds, batchSize, attributeNames, messageAttributeNames, events, sqs } = handler;
|
|
95
|
+
consumers.push(createConsumer(fastify, queueUrl, handlerFunction, metaData, timeout, waitTimeSeconds, batchSize, attributeNames, messageAttributeNames, events, sqs));
|
|
95
96
|
}
|
|
96
97
|
fastify.addHook("onReady", (done) => {
|
|
97
98
|
for (const consumer of consumers) {
|