sqs-consumer 6.0.0-alpha.1 → 6.0.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 CHANGED
@@ -71,8 +71,8 @@ const app = Consumer.create({
71
71
  sqs: new SQSClient({
72
72
  region: 'my-region',
73
73
  credentials: {
74
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
75
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
74
+ accessKeyId: 'yourAccessKey',
75
+ secretAccessKey: 'yourSecret'
76
76
  }
77
77
  })
78
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqs-consumer",
3
- "version": "6.0.0-alpha.1",
3
+ "version": "6.0.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",
package/dist/bind.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function autoBind(obj: object): void;
package/dist/bind.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.autoBind = void 0;
4
- function isMethod(propertyName, value) {
5
- return propertyName !== 'constructor' && typeof value === 'function';
6
- }
7
- function autoBind(obj) {
8
- const propertyNames = Object.getOwnPropertyNames(obj.constructor.prototype);
9
- propertyNames.forEach((propertyName) => {
10
- const value = obj[propertyName];
11
- if (isMethod(propertyName, value)) {
12
- obj[propertyName] = value.bind(obj);
13
- }
14
- });
15
- }
16
- exports.autoBind = autoBind;
@@ -1,72 +0,0 @@
1
- /// <reference types="node" />
2
- import { SQSClient, Message } from '@aws-sdk/client-sqs';
3
- import { EventEmitter } from 'events';
4
- export interface ConsumerOptions {
5
- queueUrl?: string;
6
- attributeNames?: string[];
7
- messageAttributeNames?: string[];
8
- stopped?: boolean;
9
- batchSize?: number;
10
- visibilityTimeout?: number;
11
- waitTimeSeconds?: number;
12
- authenticationErrorTimeout?: number;
13
- pollingWaitTimeMs?: number;
14
- terminateVisibilityTimeout?: boolean;
15
- heartbeatInterval?: number;
16
- sqs?: SQSClient;
17
- region?: string;
18
- handleMessageTimeout?: number;
19
- shouldDeleteMessages?: boolean;
20
- handleMessage?(message: Message): Promise<void>;
21
- handleMessageBatch?(messages: Message[]): Promise<void>;
22
- }
23
- interface Events {
24
- response_processed: [];
25
- empty: [];
26
- message_received: [Message];
27
- message_processed: [Message];
28
- error: [Error, void | Message | Message[]];
29
- timeout_error: [Error, Message];
30
- processing_error: [Error, Message];
31
- stopped: [];
32
- }
33
- export declare class Consumer extends EventEmitter {
34
- private queueUrl;
35
- private handleMessage;
36
- private handleMessageBatch;
37
- private handleMessageTimeout;
38
- private attributeNames;
39
- private messageAttributeNames;
40
- private stopped;
41
- private batchSize;
42
- private visibilityTimeout;
43
- private waitTimeSeconds;
44
- private authenticationErrorTimeout;
45
- private pollingWaitTimeMs;
46
- private terminateVisibilityTimeout;
47
- private heartbeatInterval;
48
- private sqs;
49
- private shouldDeleteMessages;
50
- constructor(options: ConsumerOptions);
51
- emit<T extends keyof Events>(event: T, ...args: Events[T]): boolean;
52
- on<T extends keyof Events>(event: T, listener: (...args: Events[T]) => void): this;
53
- once<T extends keyof Events>(event: T, listener: (...args: Events[T]) => void): this;
54
- get isRunning(): boolean;
55
- static create(options: ConsumerOptions): Consumer;
56
- start(): void;
57
- stop(): void;
58
- private handleSqsResponse;
59
- private processMessage;
60
- private receiveMessage;
61
- private deleteMessage;
62
- private executeHandler;
63
- private changeVisibilityTimeout;
64
- private emitError;
65
- private poll;
66
- private processMessageBatch;
67
- private deleteMessageBatch;
68
- private executeBatchHandler;
69
- private changeVisibilityTimeoutBatch;
70
- private startHeartbeat;
71
- }
72
- export {};
package/dist/consumer.js DELETED
@@ -1,342 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Consumer = void 0;
4
- const client_sqs_1 = require("@aws-sdk/client-sqs");
5
- const debug_1 = require("debug");
6
- const events_1 = require("events");
7
- const bind_1 = require("./bind");
8
- const errors_1 = require("./errors");
9
- const debug = (0, debug_1.default)('sqs-consumer');
10
- const requiredOptions = [
11
- 'queueUrl',
12
- // only one of handleMessage / handleMessagesBatch is required
13
- 'handleMessage|handleMessageBatch'
14
- ];
15
- function createTimeout(duration) {
16
- let timeout;
17
- const pending = new Promise((_, reject) => {
18
- timeout = setTimeout(() => {
19
- reject(new errors_1.TimeoutError());
20
- }, duration);
21
- });
22
- return [timeout, pending];
23
- }
24
- function assertOptions(options) {
25
- requiredOptions.forEach((option) => {
26
- const possibilities = option.split('|');
27
- if (!possibilities.find((p) => options[p])) {
28
- throw new Error(`Missing SQS consumer option [ ${possibilities.join(' or ')} ].`);
29
- }
30
- });
31
- if (options.batchSize > 10 || options.batchSize < 1) {
32
- throw new Error('SQS batchSize option must be between 1 and 10.');
33
- }
34
- if (options.heartbeatInterval &&
35
- !(options.heartbeatInterval < options.visibilityTimeout)) {
36
- throw new Error('heartbeatInterval must be less than visibilityTimeout.');
37
- }
38
- }
39
- function isConnectionError(err) {
40
- if (err instanceof errors_1.SQSError) {
41
- return (err.statusCode === 403 ||
42
- err.code === 'CredentialsError' ||
43
- err.code === 'UnknownEndpoint');
44
- }
45
- return false;
46
- }
47
- function toSQSError(err, message) {
48
- var _a, _b;
49
- const sqsError = new errors_1.SQSError(message);
50
- sqsError.code = err.name;
51
- sqsError.statusCode = (_a = err.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode;
52
- sqsError.retryable = (_b = err.$retryable) === null || _b === void 0 ? void 0 : _b.throttling;
53
- sqsError.service = err.$service;
54
- sqsError.fault = err.$fault;
55
- sqsError.time = new Date();
56
- return sqsError;
57
- }
58
- function hasMessages(response) {
59
- return response.Messages && response.Messages.length > 0;
60
- }
61
- class Consumer extends events_1.EventEmitter {
62
- constructor(options) {
63
- var _a, _b, _c, _d;
64
- super();
65
- assertOptions(options);
66
- this.queueUrl = options.queueUrl;
67
- this.handleMessage = options.handleMessage;
68
- this.handleMessageBatch = options.handleMessageBatch;
69
- this.handleMessageTimeout = options.handleMessageTimeout;
70
- this.attributeNames = options.attributeNames || [];
71
- this.messageAttributeNames = options.messageAttributeNames || [];
72
- this.stopped = true;
73
- this.batchSize = options.batchSize || 1;
74
- this.visibilityTimeout = options.visibilityTimeout;
75
- this.terminateVisibilityTimeout =
76
- options.terminateVisibilityTimeout || false;
77
- this.heartbeatInterval = options.heartbeatInterval;
78
- this.waitTimeSeconds = (_a = options.waitTimeSeconds) !== null && _a !== void 0 ? _a : 20;
79
- this.authenticationErrorTimeout =
80
- (_b = options.authenticationErrorTimeout) !== null && _b !== void 0 ? _b : 10000;
81
- this.pollingWaitTimeMs = (_c = options.pollingWaitTimeMs) !== null && _c !== void 0 ? _c : 0;
82
- this.shouldDeleteMessages = (_d = options.shouldDeleteMessages) !== null && _d !== void 0 ? _d : true;
83
- this.sqs =
84
- options.sqs ||
85
- new client_sqs_1.SQSClient({
86
- region: options.region || process.env.AWS_REGION || 'eu-west-1'
87
- });
88
- (0, bind_1.autoBind)(this);
89
- }
90
- emit(event, ...args) {
91
- return super.emit(event, ...args);
92
- }
93
- on(event, listener) {
94
- return super.on(event, listener);
95
- }
96
- once(event, listener) {
97
- return super.once(event, listener);
98
- }
99
- get isRunning() {
100
- return !this.stopped;
101
- }
102
- static create(options) {
103
- return new Consumer(options);
104
- }
105
- start() {
106
- if (this.stopped) {
107
- debug('Starting consumer');
108
- this.stopped = false;
109
- this.poll();
110
- }
111
- }
112
- stop() {
113
- debug('Stopping consumer');
114
- this.stopped = true;
115
- }
116
- async handleSqsResponse(response) {
117
- debug('Received SQS response');
118
- debug(response);
119
- if (response) {
120
- if (hasMessages(response)) {
121
- if (this.handleMessageBatch) {
122
- // prefer handling messages in batch when available
123
- await this.processMessageBatch(response.Messages);
124
- }
125
- else {
126
- await Promise.all(response.Messages.map(this.processMessage));
127
- }
128
- this.emit('response_processed');
129
- }
130
- else {
131
- this.emit('empty');
132
- }
133
- }
134
- }
135
- async processMessage(message) {
136
- this.emit('message_received', message);
137
- let heartbeat;
138
- try {
139
- if (this.heartbeatInterval) {
140
- heartbeat = this.startHeartbeat(async () => {
141
- return this.changeVisibilityTimeout(message, this.visibilityTimeout);
142
- });
143
- }
144
- await this.executeHandler(message);
145
- await this.deleteMessage(message);
146
- this.emit('message_processed', message);
147
- }
148
- catch (err) {
149
- this.emitError(err, message);
150
- if (this.terminateVisibilityTimeout) {
151
- await this.changeVisibilityTimeout(message, 0);
152
- }
153
- }
154
- finally {
155
- clearInterval(heartbeat);
156
- }
157
- }
158
- async receiveMessage(params) {
159
- try {
160
- return await this.sqs.send(new client_sqs_1.ReceiveMessageCommand(params));
161
- }
162
- catch (err) {
163
- throw toSQSError(err, `SQS receive message failed: ${err.message}`);
164
- }
165
- }
166
- async deleteMessage(message) {
167
- if (!this.shouldDeleteMessages) {
168
- debug('Skipping message delete since shouldDeleteMessages is set to false');
169
- return;
170
- }
171
- debug('Deleting message %s', message.MessageId);
172
- const deleteParams = {
173
- QueueUrl: this.queueUrl,
174
- ReceiptHandle: message.ReceiptHandle
175
- };
176
- try {
177
- await this.sqs.send(new client_sqs_1.DeleteMessageCommand(deleteParams));
178
- }
179
- catch (err) {
180
- throw toSQSError(err, `SQS delete message failed: ${err.message}`);
181
- }
182
- }
183
- async executeHandler(message) {
184
- let timeout;
185
- let pending;
186
- try {
187
- if (this.handleMessageTimeout) {
188
- [timeout, pending] = createTimeout(this.handleMessageTimeout);
189
- await Promise.race([this.handleMessage(message), pending]);
190
- }
191
- else {
192
- await this.handleMessage(message);
193
- }
194
- }
195
- catch (err) {
196
- if (err instanceof errors_1.TimeoutError) {
197
- err.message = `Message handler timed out after ${this.handleMessageTimeout}ms: Operation timed out.`;
198
- }
199
- else if (err instanceof Error) {
200
- err.message = `Unexpected message handler failure: ${err.message}`;
201
- }
202
- throw err;
203
- }
204
- finally {
205
- clearTimeout(timeout);
206
- }
207
- }
208
- async changeVisibilityTimeout(message, timeout) {
209
- try {
210
- const input = {
211
- QueueUrl: this.queueUrl,
212
- ReceiptHandle: message.ReceiptHandle,
213
- VisibilityTimeout: timeout
214
- };
215
- return await this.sqs.send(new client_sqs_1.ChangeMessageVisibilityCommand(input));
216
- }
217
- catch (err) {
218
- this.emit('error', toSQSError(err, `Error changing visibility timeout: ${err.message}`), message);
219
- }
220
- }
221
- emitError(err, message) {
222
- if (err.name === errors_1.SQSError.name) {
223
- this.emit('error', err, message);
224
- }
225
- else if (err instanceof errors_1.TimeoutError) {
226
- this.emit('timeout_error', err, message);
227
- }
228
- else {
229
- this.emit('processing_error', err, message);
230
- }
231
- }
232
- poll() {
233
- if (this.stopped) {
234
- this.emit('stopped');
235
- return;
236
- }
237
- debug('Polling for messages');
238
- const receiveParams = {
239
- QueueUrl: this.queueUrl,
240
- AttributeNames: this.attributeNames,
241
- MessageAttributeNames: this.messageAttributeNames,
242
- MaxNumberOfMessages: this.batchSize,
243
- WaitTimeSeconds: this.waitTimeSeconds,
244
- VisibilityTimeout: this.visibilityTimeout
245
- };
246
- let currentPollingTimeout = this.pollingWaitTimeMs;
247
- this.receiveMessage(receiveParams)
248
- .then(this.handleSqsResponse)
249
- .catch((err) => {
250
- this.emit('error', err);
251
- if (isConnectionError(err)) {
252
- debug('There was an authentication error. Pausing before retrying.');
253
- currentPollingTimeout = this.authenticationErrorTimeout;
254
- }
255
- return;
256
- })
257
- .then(() => {
258
- setTimeout(this.poll, currentPollingTimeout);
259
- })
260
- .catch((err) => {
261
- this.emit('error', err);
262
- });
263
- }
264
- async processMessageBatch(messages) {
265
- messages.forEach((message) => {
266
- this.emit('message_received', message);
267
- });
268
- let heartbeat;
269
- try {
270
- if (this.heartbeatInterval) {
271
- heartbeat = this.startHeartbeat(async () => {
272
- return this.changeVisibilityTimeoutBatch(messages, this.visibilityTimeout);
273
- });
274
- }
275
- await this.executeBatchHandler(messages);
276
- await this.deleteMessageBatch(messages);
277
- messages.forEach((message) => {
278
- this.emit('message_processed', message);
279
- });
280
- }
281
- catch (err) {
282
- this.emit('error', err, messages);
283
- if (this.terminateVisibilityTimeout) {
284
- await this.changeVisibilityTimeoutBatch(messages, 0);
285
- }
286
- }
287
- finally {
288
- clearInterval(heartbeat);
289
- }
290
- }
291
- async deleteMessageBatch(messages) {
292
- if (!this.shouldDeleteMessages) {
293
- debug('Skipping message delete since shouldDeleteMessages is set to false');
294
- return;
295
- }
296
- debug('Deleting messages %s', messages.map((msg) => msg.MessageId).join(' ,'));
297
- const deleteParams = {
298
- QueueUrl: this.queueUrl,
299
- Entries: messages.map((message) => ({
300
- Id: message.MessageId,
301
- ReceiptHandle: message.ReceiptHandle
302
- }))
303
- };
304
- try {
305
- await this.sqs.send(new client_sqs_1.DeleteMessageBatchCommand(deleteParams));
306
- }
307
- catch (err) {
308
- throw toSQSError(err, `SQS delete message failed: ${err.message}`);
309
- }
310
- }
311
- async executeBatchHandler(messages) {
312
- try {
313
- await this.handleMessageBatch(messages);
314
- }
315
- catch (err) {
316
- err.message = `Unexpected message handler failure: ${err.message}`;
317
- throw err;
318
- }
319
- }
320
- async changeVisibilityTimeoutBatch(messages, timeout) {
321
- const params = {
322
- QueueUrl: this.queueUrl,
323
- Entries: messages.map((message) => ({
324
- Id: message.MessageId,
325
- ReceiptHandle: message.ReceiptHandle,
326
- VisibilityTimeout: timeout
327
- }))
328
- };
329
- try {
330
- return await this.sqs.send(new client_sqs_1.ChangeMessageVisibilityBatchCommand(params));
331
- }
332
- catch (err) {
333
- this.emit('error', toSQSError(err, `Error changing visibility timeout: ${err.message}`), messages);
334
- }
335
- }
336
- startHeartbeat(heartbeatFn) {
337
- return setInterval(() => {
338
- heartbeatFn();
339
- }, this.heartbeatInterval * 1000);
340
- }
341
- }
342
- exports.Consumer = Consumer;
package/dist/errors.d.ts DELETED
@@ -1,13 +0,0 @@
1
- declare class SQSError extends Error {
2
- code: string;
3
- statusCode: number;
4
- service: string;
5
- time: Date;
6
- retryable: boolean;
7
- fault: 'client' | 'server';
8
- constructor(message: string);
9
- }
10
- declare class TimeoutError extends Error {
11
- constructor(message?: string);
12
- }
13
- export { SQSError, TimeoutError };
package/dist/errors.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeoutError = exports.SQSError = void 0;
4
- class SQSError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = this.constructor.name;
8
- }
9
- }
10
- exports.SQSError = SQSError;
11
- class TimeoutError extends Error {
12
- constructor(message = 'Operation timed out.') {
13
- super(message);
14
- this.message = message;
15
- this.name = 'TimeoutError';
16
- }
17
- }
18
- exports.TimeoutError = TimeoutError;
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { Consumer, ConsumerOptions } from './consumer';
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Consumer = void 0;
4
- var consumer_1 = require("./consumer");
5
- Object.defineProperty(exports, "Consumer", { enumerable: true, get: function () { return consumer_1.Consumer; } });
package/dist/types.d.ts DELETED
@@ -1,59 +0,0 @@
1
- export type AWSError = {
2
- /**
3
- * Name, eg. ConditionalCheckFailedException
4
- */
5
- name: string;
6
- /**
7
- * Human-readable error response message
8
- */
9
- message: string;
10
- /**
11
- * Non-standard stacktrace
12
- */
13
- stack?: string;
14
- /**
15
- * Whether the client or server are at fault.
16
- */
17
- readonly $fault?: 'client' | 'server';
18
- /**
19
- * The service that encountered the exception.
20
- */
21
- readonly $service?: string;
22
- /**
23
- * Indicates that an error MAY be retried by the client.
24
- */
25
- readonly $retryable?: {
26
- /**
27
- * Indicates that the error is a retryable throttling error.
28
- */
29
- readonly throttling?: boolean;
30
- };
31
- $metadata?: {
32
- /**
33
- * The status code of the last HTTP response received for this operation.
34
- */
35
- httpStatusCode?: number;
36
- /**
37
- * A unique identifier for the last request sent for this operation. Often
38
- * requested by AWS service teams to aid in debugging.
39
- */
40
- requestId?: string;
41
- /**
42
- * A secondary identifier for the last request sent. Used for debugging.
43
- */
44
- extendedRequestId?: string;
45
- /**
46
- * A tertiary identifier for the last request sent. Used for debugging.
47
- */
48
- cfId?: string;
49
- /**
50
- * The number of times this operation was attempted.
51
- */
52
- attempts?: number;
53
- /**
54
- * The total amount of time (in milliseconds) that was spent waiting between
55
- * retry attempts.
56
- */
57
- totalRetryDelay?: number;
58
- };
59
- };
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- declare const express: any;
2
- declare const consumer: any;
3
- declare const producer: any;
4
- declare const expressApp: any;
@@ -1,97 +0,0 @@
1
- const express = require('express');
2
- const { consumer } = require('./utils/consumer');
3
- const { producer } = require('./utils/producer');
4
- const expressApp = express();
5
- expressApp.get('/', (_, res) => {
6
- res.send('Hello! Send me a request to one of my other endpoints to test SQS Consumer!');
7
- });
8
- expressApp.get('/queue-size', async (_, res) => {
9
- // get the current size of the queue
10
- const size = await producer.queueSize();
11
- res.send({
12
- message: 'Queue size retrieved!',
13
- data: size
14
- });
15
- });
16
- expressApp.post('/sample', async (_, res) => {
17
- // send messages to the queue
18
- const messages = await producer.send(['msg1', 'msg2']);
19
- res.send({
20
- message: 'Sample messages sent successfully!',
21
- data: messages
22
- });
23
- });
24
- expressApp.post('/sample-with-id', async (_, res) => {
25
- // send a message to the queue with a specific ID (by default the body is used as the ID)
26
- const messages = await producer.send([
27
- {
28
- id: 'id1',
29
- body: 'Hello world'
30
- }
31
- ]);
32
- res.send({
33
- message: 'Sample messages sent successfully!',
34
- data: messages
35
- });
36
- });
37
- expressApp.post('/sample-with-attributes', async (_, res) => {
38
- // send a message to the queue with
39
- // - messageAttributes
40
- const messages = await producer.send([
41
- {
42
- id: 'id1',
43
- body: 'Hello world with two string attributes: attr1 and attr2',
44
- messageAttributes: {
45
- attr1: { DataType: 'String', StringValue: 'stringValue' },
46
- attr2: { DataType: 'String', StringValue: 'stringValue2' },
47
- }
48
- }
49
- ]);
50
- res.send({
51
- message: 'Sample messages sent successfully!',
52
- data: messages
53
- });
54
- });
55
- expressApp.post('/sample-with-delay', async (_, res) => {
56
- // send a message to the queue with
57
- // - delaySeconds (must be an number contained within 0 and 900)
58
- const messages = await producer.send([
59
- {
60
- id: 'id1',
61
- body: 'Hello world delayed by 5 seconds',
62
- delaySeconds: 5
63
- }
64
- ]);
65
- res.send({
66
- message: 'Sample messages sent successfully!',
67
- data: messages
68
- });
69
- });
70
- expressApp.post('/sample-with-fido', async (_, res) => {
71
- // send a message to a FIFO queue
72
- //
73
- // note that AWS FIFO queues require two additional params:
74
- // - groupId (string)
75
- // - deduplicationId (string)
76
- //
77
- // deduplicationId can be excluded if content-based deduplication is enabled
78
- //
79
- // http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queue-recommendations.html
80
- const messages = await producer.send({
81
- id: 'testId',
82
- body: 'Hello world from our FIFO queue!',
83
- groupId: 'group1234',
84
- deduplicationId: 'abcdef123456' // typically a hash of the message body
85
- });
86
- res.send({
87
- message: 'Sample messages sent successfully!',
88
- data: messages
89
- });
90
- });
91
- expressApp.listen(3026, () => {
92
- // eslint-disable-next-line no-console
93
- console.log('STARTING SQS CONSUMER');
94
- consumer.start();
95
- // eslint-disable-next-line no-console
96
- console.log('EXPRESS APP LISTENING ON: http://localhost:3026');
97
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { Consumer } = require('../../../dist/index');
4
- const { QUEUE_URL, sqs } = require('./sqs');
5
- const consumer = Consumer.create({
6
- queueUrl: QUEUE_URL,
7
- sqs,
8
- handleMessage: async (message) => {
9
- // eslint-disable-next-line no-console
10
- console.log('RECEIVED SQS MESSAGE:');
11
- // eslint-disable-next-line no-console
12
- console.log(message);
13
- }
14
- });
15
- consumer.on('error', (err) => {
16
- // eslint-disable-next-line no-console
17
- console.log('RECEIVED SQS ERROR:');
18
- // eslint-disable-next-line no-console
19
- console.error(err.message);
20
- });
21
- consumer.on('processing_error', (err) => {
22
- // eslint-disable-next-line no-console
23
- console.log('RECEIVED SQS PROCESSING ERROR:');
24
- // eslint-disable-next-line no-console
25
- console.error(err.message);
26
- });
27
- consumer.on('timeout_error', (err) => {
28
- // eslint-disable-next-line no-console
29
- console.log('RECEIVED SQS TIMEOUT ERROR:');
30
- // eslint-disable-next-line no-console
31
- console.error(err.message);
32
- });
33
- consumer.on('timeout_error', (err) => {
34
- // eslint-disable-next-line no-console
35
- console.log('RECEIVED SQS TIMEOUT ERROR:');
36
- // eslint-disable-next-line no-console
37
- console.error(err.message);
38
- });
39
- consumer.on('message_received', (message) => {
40
- // eslint-disable-next-line no-console
41
- console.log('RECEIVED SQS MESSAGE:');
42
- // eslint-disable-next-line no-console
43
- console.error(message);
44
- });
45
- consumer.on('message_processed', (message) => {
46
- // eslint-disable-next-line no-console
47
- console.log('RECEIVED SQS MESSAGE PROCESSED:');
48
- // eslint-disable-next-line no-console
49
- console.error(message);
50
- });
51
- consumer.on('response_processed', () => {
52
- // eslint-disable-next-line no-console
53
- console.log('RECEIVED SQS RESPONSE PROCESSED:');
54
- });
55
- consumer.on('stopped', () => {
56
- // eslint-disable-next-line no-console
57
- console.log('RECEIVED SQS STOPPED:');
58
- });
59
- consumer.on('empty', () => {
60
- // eslint-disable-next-line no-console
61
- console.log('RECEIVED SQS EMPTY:');
62
- });
63
- exports.consumer = consumer;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { Producer } = require('sqs-producer');
4
- const { QUEUE_URL, sqsConfig, sqs } = require('./sqs');
5
- const producer = Producer.create({
6
- queueUrl: QUEUE_URL,
7
- region: sqsConfig.region,
8
- sqs
9
- });
10
- exports.producer = producer;
@@ -1 +0,0 @@
1
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const { Endpoint, SQS } = require('aws-sdk');
4
- const sqsConfig = {
5
- region: 'eu-west-1',
6
- };
7
- if (process.env.SQS_ENDPOINT) {
8
- sqsConfig.endpoint = new Endpoint(process.env.SQS_ENDPOINT);
9
- }
10
- else if (process.env.NODE_ENV === 'development') {
11
- sqsConfig.endpoint = new Endpoint('http://localhost:4566');
12
- }
13
- if (process.env.SQS_ACCESS_KEY_ID) {
14
- sqsConfig.accessKeyId = process.env.SQS_ACCESS_KEY_ID;
15
- }
16
- else if (process.env.NODE_ENV === 'development') {
17
- sqsConfig.accessKeyId = 'na';
18
- }
19
- if (process.env.SQS_SECRET_ACCESS_KEY) {
20
- sqsConfig.secretAccessKey = process.env.SQS_SECRET_ACCESS_KEY;
21
- }
22
- else if (process.env.NODE_ENV === 'development') {
23
- sqsConfig.secretAccessKey = 'na';
24
- }
25
- exports.sqs =
26
- !sqsConfig.endpoint && process.env.NODE_ENV === 'development'
27
- ? null
28
- : new SQS(sqsConfig);
29
- exports.QUEUE_NAME = process.env.SQS_QUEUE_NAME || 'sqs-consumer-data';
30
- exports.QUEUE_URL =
31
- process.env.SQS_QUEUE_URL ||
32
- 'http://localhost:4566/000000000000/sqs-consumer-data';
33
- exports.sqsConfig = sqsConfig;