sqs-consumer 8.2.0 → 9.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/.github/workflows/publish.yml +0 -2
- package/CHANGELOG.md +8 -4
- package/README.md +12 -2
- package/dist/consumer.d.ts +6 -2
- package/dist/consumer.js +12 -12
- package/dist/errors.js +2 -1
- package/dist/types.d.ts +13 -0
- package/package.json +26 -22
- package/src/consumer.ts +14 -14
- package/src/errors.ts +2 -1
- package/src/types.ts +13 -0
|
@@ -17,8 +17,6 @@ jobs:
|
|
|
17
17
|
cache: 'npm'
|
|
18
18
|
registry-url: 'https://registry.npmjs.org'
|
|
19
19
|
- run: npm ci
|
|
20
|
-
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
|
|
21
|
-
run: npm audit signatures
|
|
22
20
|
- name: Release
|
|
23
21
|
env:
|
|
24
22
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [9.1.0](https://github.com/bbc/sqs-consumer/compare/v9.0.0...v9.1.0) (2024-03-12)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Features
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* feat: Add useQueueUrlAsEndpoint to ConsumerOptions ([#472](https://github.com/bbc/sqs-consumer/issues/472)) ([075bd54](https://github.com/bbc/sqs-consumer/commit/075bd54a0aa574f4589d7d8f2c6c82d6adbdf1a1))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* handle CredentialsProviderError from AWS SDK JS v3 ([#474](https://github.com/bbc/sqs-consumer/issues/474)) ([9a14d66](https://github.com/bbc/sqs-consumer/commit/9a14d661c36e7bbca0dfc1ce467253991103279f))
|
|
7
12
|
|
|
8
13
|
|
|
9
14
|
### Chores
|
|
10
15
|
|
|
11
|
-
*
|
|
12
|
-
* updating release config ([6b95edb](https://github.com/bbc/sqs-consumer/commit/6b95edbf894864e25a61a748ab0ac9d6ebf2a2f7))
|
|
16
|
+
* version bump to 9.1.0 ([c031e1e](https://github.com/bbc/sqs-consumer/commit/c031e1e12bfa43f35f2cae8221694b0ac31a8712))
|
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ npm install sqs-consumer
|
|
|
26
26
|
|
|
27
27
|
We will only support Node versions that are actively or security supported by the Node team. If you are still using an Node 14, please use a version of this library before the v7 release, if you are using Node 16, please use a version before the v7.3.0 release.
|
|
28
28
|
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Visit [https://bbc.github.io/sqs-consumer/](https://bbc.github.io/sqs-consumer/) for the full API documentation.
|
|
32
|
+
|
|
29
33
|
## Usage
|
|
30
34
|
|
|
31
35
|
```js
|
|
@@ -125,9 +129,15 @@ By default, the value of `abort` is set to `false` which means pre existing requ
|
|
|
125
129
|
|
|
126
130
|
`consumer.stop({ abort: true })`
|
|
127
131
|
|
|
128
|
-
### `consumer.
|
|
132
|
+
### `consumer.status`
|
|
133
|
+
|
|
134
|
+
Returns the current status of the consumer.
|
|
135
|
+
|
|
136
|
+
- `isRunning` - `true` if the consumer has been started and not stopped, `false` if was not started or if it was stopped.
|
|
137
|
+
- `isPolling` - `true` if the consumer is actively polling, `false` if it is not.
|
|
129
138
|
|
|
130
|
-
|
|
139
|
+
> **Note:**
|
|
140
|
+
> This method is not available in versions before v9.0.0 and replaced the method `isRunning` to supply both running and polling states.
|
|
131
141
|
|
|
132
142
|
### `consumer.updateOption(option, value)`
|
|
133
143
|
|
package/dist/consumer.d.ts
CHANGED
|
@@ -51,9 +51,13 @@ export declare class Consumer extends TypedEventEmitter {
|
|
|
51
51
|
*/
|
|
52
52
|
private waitForPollingToComplete;
|
|
53
53
|
/**
|
|
54
|
-
* Returns the current
|
|
54
|
+
* Returns the current status of the consumer.
|
|
55
|
+
* This includes whether it is running or currently polling.
|
|
55
56
|
*/
|
|
56
|
-
get
|
|
57
|
+
get status(): {
|
|
58
|
+
isRunning: boolean;
|
|
59
|
+
isPolling: boolean;
|
|
60
|
+
};
|
|
57
61
|
/**
|
|
58
62
|
* Validates and then updates the provided option to the provided value.
|
|
59
63
|
* @param option The option to validate and then update
|
package/dist/consumer.js
CHANGED
|
@@ -12,10 +12,11 @@ const logger_1 = require("./logger");
|
|
|
12
12
|
*/
|
|
13
13
|
class Consumer extends emitter_1.TypedEventEmitter {
|
|
14
14
|
constructor(options) {
|
|
15
|
-
var _a, _b, _c, _d, _e, _f;
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
16
16
|
super();
|
|
17
17
|
this.pollingTimeoutId = undefined;
|
|
18
18
|
this.stopped = true;
|
|
19
|
+
this.isPolling = false;
|
|
19
20
|
(0, validation_1.assertOptions)(options);
|
|
20
21
|
this.queueUrl = options.queueUrl;
|
|
21
22
|
this.handleMessage = options.handleMessage;
|
|
@@ -40,6 +41,7 @@ class Consumer extends emitter_1.TypedEventEmitter {
|
|
|
40
41
|
this.sqs =
|
|
41
42
|
options.sqs ||
|
|
42
43
|
new client_sqs_1.SQSClient({
|
|
44
|
+
useQueueUrlAsEndpoint: (_g = options.useQueueUrlAsEndpoint) !== null && _g !== void 0 ? _g : true,
|
|
43
45
|
region: options.region || process.env.AWS_REGION || 'eu-west-1'
|
|
44
46
|
});
|
|
45
47
|
(0, bind_1.autoBind)(this);
|
|
@@ -108,18 +110,22 @@ class Consumer extends emitter_1.TypedEventEmitter {
|
|
|
108
110
|
const exceededTimeout = Date.now() - this.stopRequestedAtTimestamp >
|
|
109
111
|
this.pollingCompleteWaitTimeMs;
|
|
110
112
|
if (exceededTimeout) {
|
|
111
|
-
|
|
113
|
+
this.emit('waiting_for_polling_to_complete_timeout_exceeded');
|
|
112
114
|
this.emit('stopped');
|
|
113
115
|
return;
|
|
114
116
|
}
|
|
115
|
-
|
|
117
|
+
this.emit('waiting_for_polling_to_complete');
|
|
116
118
|
setTimeout(this.waitForPollingToComplete, 1000);
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
119
|
-
* Returns the current
|
|
121
|
+
* Returns the current status of the consumer.
|
|
122
|
+
* This includes whether it is running or currently polling.
|
|
120
123
|
*/
|
|
121
|
-
get
|
|
122
|
-
return
|
|
124
|
+
get status() {
|
|
125
|
+
return {
|
|
126
|
+
isRunning: !this.stopped,
|
|
127
|
+
isPolling: this.isPolling
|
|
128
|
+
};
|
|
123
129
|
}
|
|
124
130
|
/**
|
|
125
131
|
* Validates and then updates the provided option to the provided value.
|
|
@@ -221,18 +227,12 @@ class Consumer extends emitter_1.TypedEventEmitter {
|
|
|
221
227
|
*/
|
|
222
228
|
async handleSqsResponse(response) {
|
|
223
229
|
if ((0, validation_1.hasMessages)(response)) {
|
|
224
|
-
const handlerProcessingDebugger = setInterval(() => {
|
|
225
|
-
logger_1.logger.debug('handler_processing', {
|
|
226
|
-
detail: 'The handler is still processing the message(s)...'
|
|
227
|
-
});
|
|
228
|
-
}, 1000);
|
|
229
230
|
if (this.handleMessageBatch) {
|
|
230
231
|
await this.processMessageBatch(response.Messages);
|
|
231
232
|
}
|
|
232
233
|
else {
|
|
233
234
|
await Promise.all(response.Messages.map(this.processMessage));
|
|
234
235
|
}
|
|
235
|
-
clearInterval(handlerProcessingDebugger);
|
|
236
236
|
this.emit('response_processed');
|
|
237
237
|
}
|
|
238
238
|
else if (response) {
|
package/dist/errors.js
CHANGED
|
@@ -32,7 +32,8 @@ function isConnectionError(err) {
|
|
|
32
32
|
return (err.statusCode === 403 ||
|
|
33
33
|
err.code === 'CredentialsError' ||
|
|
34
34
|
err.code === 'UnknownEndpoint' ||
|
|
35
|
-
err.code === 'AWS.SimpleQueueService.NonExistentQueue'
|
|
35
|
+
err.code === 'AWS.SimpleQueueService.NonExistentQueue' ||
|
|
36
|
+
err.code === 'CredentialsProviderError');
|
|
36
37
|
}
|
|
37
38
|
return false;
|
|
38
39
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -75,6 +75,11 @@ export interface ConsumerOptions {
|
|
|
75
75
|
* @defaultValue process.env.AWS_REGION || `eu-west-1`
|
|
76
76
|
*/
|
|
77
77
|
region?: string;
|
|
78
|
+
/**
|
|
79
|
+
* If false uses the QueueUrl hostname as the endpoint.
|
|
80
|
+
* @defaultValue `true`
|
|
81
|
+
*/
|
|
82
|
+
useQueueUrlAsEndpoint?: boolean;
|
|
78
83
|
/**
|
|
79
84
|
* Time in ms to wait for `handleMessage` to process a message before timing out.
|
|
80
85
|
*
|
|
@@ -189,6 +194,14 @@ export interface Events {
|
|
|
189
194
|
* Fired when an option is updated
|
|
190
195
|
*/
|
|
191
196
|
option_updated: [UpdatableOptions, ConsumerOptions[UpdatableOptions]];
|
|
197
|
+
/**
|
|
198
|
+
* Fired when the Consumer is waiting for polling to complete before stopping.
|
|
199
|
+
*/
|
|
200
|
+
waiting_for_polling_to_complete: [];
|
|
201
|
+
/**
|
|
202
|
+
* Fired when the Consumer has waited for polling to complete and is stopping due to a timeout.
|
|
203
|
+
*/
|
|
204
|
+
waiting_for_polling_to_complete_timeout_exceeded: [];
|
|
192
205
|
}
|
|
193
206
|
export type AWSError = {
|
|
194
207
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqs-consumer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Build SQS-based Node applications without the boilerplate",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"lcov": "c8 mocha && c8 report --reporter=lcov",
|
|
22
22
|
"lint": "eslint . --ext .ts",
|
|
23
23
|
"lint:fix": "eslint . --fix",
|
|
24
|
-
"format": "prettier --
|
|
24
|
+
"format": "prettier --log-level warn --write \"**/*.{js,json,jsx,md,ts,tsx,html}\"",
|
|
25
25
|
"format:check": "prettier --check \"**/*.{js,json,jsx,md,ts,tsx,html}\"",
|
|
26
26
|
"posttest": "npm run lint && npm run format:check",
|
|
27
27
|
"generate-docs": "typedoc"
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
{
|
|
58
58
|
"preset": "conventionalcommits",
|
|
59
59
|
"releaseRules": [
|
|
60
|
+
{
|
|
61
|
+
"type": "breaking",
|
|
62
|
+
"release": "major"
|
|
63
|
+
},
|
|
60
64
|
{
|
|
61
65
|
"type": "feat",
|
|
62
66
|
"release": "minor"
|
|
@@ -124,39 +128,39 @@
|
|
|
124
128
|
]
|
|
125
129
|
},
|
|
126
130
|
"devDependencies": {
|
|
127
|
-
"@cucumber/cucumber": "10.
|
|
131
|
+
"@cucumber/cucumber": "10.3.1",
|
|
128
132
|
"@semantic-release/changelog": "^6.0.3",
|
|
129
133
|
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
130
134
|
"@semantic-release/git": "^10.0.1",
|
|
131
135
|
"@semantic-release/github": "^9.2.6",
|
|
132
|
-
"@semantic-release/npm": "
|
|
136
|
+
"@semantic-release/npm": "11.0.3",
|
|
133
137
|
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
134
|
-
"@types/chai": "^4.3.
|
|
135
|
-
"@types/mocha": "^10.0.
|
|
136
|
-
"@types/node": "^20.
|
|
137
|
-
"@types/sinon": "^
|
|
138
|
-
"c8": "^
|
|
138
|
+
"@types/chai": "^4.3.12",
|
|
139
|
+
"@types/mocha": "^10.0.6",
|
|
140
|
+
"@types/node": "^20.11.25",
|
|
141
|
+
"@types/sinon": "^17.0.3",
|
|
142
|
+
"c8": "^9.1.0",
|
|
139
143
|
"chai": "^4.3.10",
|
|
140
144
|
"conventional-changelog-conventionalcommits": "^7.0.2",
|
|
141
|
-
"eslint": "^8.
|
|
142
|
-
"eslint-config-iplayer": "^9.
|
|
143
|
-
"eslint-config-prettier": "^9.
|
|
144
|
-
"mocha": "^10.
|
|
145
|
+
"eslint": "^8.57.0",
|
|
146
|
+
"eslint-config-iplayer": "^9.2.0",
|
|
147
|
+
"eslint-config-prettier": "^9.1.0",
|
|
148
|
+
"mocha": "^10.3.0",
|
|
145
149
|
"p-event": "^4.2.0",
|
|
146
|
-
"prettier": "^3.
|
|
147
|
-
"semantic-release": "^23.0.
|
|
148
|
-
"sinon": "^17.0.
|
|
149
|
-
"sqs-producer": "^
|
|
150
|
-
"ts-node": "^10.9.
|
|
151
|
-
"typedoc": "^0.25.
|
|
152
|
-
"typescript": "^5.
|
|
150
|
+
"prettier": "^3.2.5",
|
|
151
|
+
"semantic-release": "^23.0.2",
|
|
152
|
+
"sinon": "^17.0.1",
|
|
153
|
+
"sqs-producer": "^5.0.0",
|
|
154
|
+
"ts-node": "^10.9.2",
|
|
155
|
+
"typedoc": "^0.25.12",
|
|
156
|
+
"typescript": "^5.4.2"
|
|
153
157
|
},
|
|
154
158
|
"dependencies": {
|
|
155
|
-
"@aws-sdk/client-sqs": "^3.
|
|
159
|
+
"@aws-sdk/client-sqs": "^3.529.1",
|
|
156
160
|
"debug": "^4.3.4"
|
|
157
161
|
},
|
|
158
162
|
"peerDependencies": {
|
|
159
|
-
"@aws-sdk/client-sqs": "^3.
|
|
163
|
+
"@aws-sdk/client-sqs": "^3.529.1"
|
|
160
164
|
},
|
|
161
165
|
"mocha": {
|
|
162
166
|
"spec": "test/tests/**/**/*.test.ts",
|
package/src/consumer.ts
CHANGED
|
@@ -56,7 +56,7 @@ export class Consumer extends TypedEventEmitter {
|
|
|
56
56
|
private pollingWaitTimeMs: number;
|
|
57
57
|
private pollingCompleteWaitTimeMs: number;
|
|
58
58
|
private heartbeatInterval: number;
|
|
59
|
-
private isPolling
|
|
59
|
+
private isPolling = false;
|
|
60
60
|
private stopRequestedAtTimestamp: number;
|
|
61
61
|
public abortController: AbortController;
|
|
62
62
|
|
|
@@ -86,6 +86,7 @@ export class Consumer extends TypedEventEmitter {
|
|
|
86
86
|
this.sqs =
|
|
87
87
|
options.sqs ||
|
|
88
88
|
new SQSClient({
|
|
89
|
+
useQueueUrlAsEndpoint: options.useQueueUrlAsEndpoint ?? true,
|
|
89
90
|
region: options.region || process.env.AWS_REGION || 'eu-west-1'
|
|
90
91
|
});
|
|
91
92
|
autoBind(this);
|
|
@@ -164,20 +165,27 @@ export class Consumer extends TypedEventEmitter {
|
|
|
164
165
|
Date.now() - this.stopRequestedAtTimestamp >
|
|
165
166
|
this.pollingCompleteWaitTimeMs;
|
|
166
167
|
if (exceededTimeout) {
|
|
167
|
-
|
|
168
|
+
this.emit('waiting_for_polling_to_complete_timeout_exceeded');
|
|
168
169
|
this.emit('stopped');
|
|
169
170
|
return;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
|
|
173
|
+
this.emit('waiting_for_polling_to_complete');
|
|
173
174
|
setTimeout(this.waitForPollingToComplete, 1000);
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
/**
|
|
177
|
-
* Returns the current
|
|
178
|
+
* Returns the current status of the consumer.
|
|
179
|
+
* This includes whether it is running or currently polling.
|
|
178
180
|
*/
|
|
179
|
-
public get
|
|
180
|
-
|
|
181
|
+
public get status(): {
|
|
182
|
+
isRunning: boolean;
|
|
183
|
+
isPolling: boolean;
|
|
184
|
+
} {
|
|
185
|
+
return {
|
|
186
|
+
isRunning: !this.stopped,
|
|
187
|
+
isPolling: this.isPolling
|
|
188
|
+
};
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
/**
|
|
@@ -297,20 +305,12 @@ export class Consumer extends TypedEventEmitter {
|
|
|
297
305
|
response: ReceiveMessageCommandOutput
|
|
298
306
|
): Promise<void> {
|
|
299
307
|
if (hasMessages(response)) {
|
|
300
|
-
const handlerProcessingDebugger = setInterval(() => {
|
|
301
|
-
logger.debug('handler_processing', {
|
|
302
|
-
detail: 'The handler is still processing the message(s)...'
|
|
303
|
-
});
|
|
304
|
-
}, 1000);
|
|
305
|
-
|
|
306
308
|
if (this.handleMessageBatch) {
|
|
307
309
|
await this.processMessageBatch(response.Messages);
|
|
308
310
|
} else {
|
|
309
311
|
await Promise.all(response.Messages.map(this.processMessage));
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
clearInterval(handlerProcessingDebugger);
|
|
313
|
-
|
|
314
314
|
this.emit('response_processed');
|
|
315
315
|
} else if (response) {
|
|
316
316
|
this.emit('empty');
|
package/src/errors.ts
CHANGED
|
@@ -46,7 +46,8 @@ function isConnectionError(err: Error): boolean {
|
|
|
46
46
|
err.statusCode === 403 ||
|
|
47
47
|
err.code === 'CredentialsError' ||
|
|
48
48
|
err.code === 'UnknownEndpoint' ||
|
|
49
|
-
err.code === 'AWS.SimpleQueueService.NonExistentQueue'
|
|
49
|
+
err.code === 'AWS.SimpleQueueService.NonExistentQueue' ||
|
|
50
|
+
err.code === 'CredentialsProviderError'
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
return false;
|
package/src/types.ts
CHANGED
|
@@ -76,6 +76,11 @@ export interface ConsumerOptions {
|
|
|
76
76
|
* @defaultValue process.env.AWS_REGION || `eu-west-1`
|
|
77
77
|
*/
|
|
78
78
|
region?: string;
|
|
79
|
+
/**
|
|
80
|
+
* If false uses the QueueUrl hostname as the endpoint.
|
|
81
|
+
* @defaultValue `true`
|
|
82
|
+
*/
|
|
83
|
+
useQueueUrlAsEndpoint?: boolean;
|
|
79
84
|
/**
|
|
80
85
|
* Time in ms to wait for `handleMessage` to process a message before timing out.
|
|
81
86
|
*
|
|
@@ -197,6 +202,14 @@ export interface Events {
|
|
|
197
202
|
* Fired when an option is updated
|
|
198
203
|
*/
|
|
199
204
|
option_updated: [UpdatableOptions, ConsumerOptions[UpdatableOptions]];
|
|
205
|
+
/**
|
|
206
|
+
* Fired when the Consumer is waiting for polling to complete before stopping.
|
|
207
|
+
*/
|
|
208
|
+
waiting_for_polling_to_complete: [];
|
|
209
|
+
/**
|
|
210
|
+
* Fired when the Consumer has waited for polling to complete and is stopping due to a timeout.
|
|
211
|
+
*/
|
|
212
|
+
waiting_for_polling_to_complete_timeout_exceeded: [];
|
|
200
213
|
}
|
|
201
214
|
|
|
202
215
|
export type AWSError = {
|