sqs-consumer 6.0.2 → 6.2.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.
@@ -34,6 +34,16 @@ Follow the setup instructions in the [README](../README.md).
34
34
 
35
35
  Ensure all your code is thoroughly tested and that this testing is detailed in the pull request.
36
36
 
37
+ ## Contributors Licence Agreement
38
+
39
+ In order to accept contributions, we need all contributors grant Us a licence to the intellectual
40
+ property rights in their Contributions. This Agreement (“Agreement”) is intended to protect your
41
+ rights as a contributor, and to help ensure that the intellectual property contained
42
+ within is available to the whole community, to use and build on.
43
+
44
+ When you raise a pull request and you haven't previously signed a CLA, the bot will automatically
45
+ ask you to do this. You must complete this step in order for your PR to be merged.
46
+
37
47
  ## Pull Request Process
38
48
 
39
49
  1. Make sure you have opened an issue and it was approved by a project maintainer before working on a PR
@@ -0,0 +1,115 @@
1
+ name: 'Bug report'
2
+ title: "[Bug]: "
3
+ labels: ["bug", "triage"]
4
+ description: Report a reproducible bug or regression
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thank you for reporting an issue!
10
+
11
+ This issue tracker is for reporting reproducible bugs or regression's found in this package, if you have a question or feature request, please report it within the [Discussions tab](https://github.com/bbc/sqs-consumer/discussions) instead.
12
+
13
+ Before submitting a new bug/issue, please check the links below to see if there is a solution or question posted there already:
14
+
15
+ - [Discussions](https://github.com/bbc/sqs-consumer/discussions)
16
+ - [Open Issues](https://github.com/bbc/sqs-consumer/issues?q=is%3Aopen+is%3Aissue)
17
+ - [Closed Issues](https://github.com/bbc/sqs-consumer/issues?q=is%3Aissue+is%3Aclosed)
18
+
19
+ The more information you fill in, the better the community can help you.
20
+ - type: textarea
21
+ id: description
22
+ attributes:
23
+ label: Describe the bug
24
+ description: Provide a clear and concise description of what the bug is.
25
+ validations:
26
+ required: true
27
+ - type: input
28
+ id: link
29
+ attributes:
30
+ label: Your minimal, reproducible example
31
+ description: |
32
+ Please add a link to a minimal reproduction.
33
+ Note:
34
+ - Please keep your example as simple and reproduceable as possible, try leaving out dependencies that are not required for reproduction.
35
+ - To create a shareable code example for web, you can use CodeSandbox (https://codesandbox.io/s/new) or Stackblitz (https://stackblitz.com/).
36
+ - Please make sure the example is complete and runnable - e.g. avoid localhost URLs.
37
+ placeholder: |
38
+ e.g. Code Sandbox, Stackblitz, Expo Snack or TypeScript playground
39
+ validations:
40
+ required: true
41
+ - type: textarea
42
+ id: steps
43
+ attributes:
44
+ label: Steps to reproduce
45
+ description: Describe the steps we have to take to reproduce the behavior.
46
+ placeholder: |
47
+ 1. Go to '...'
48
+ 2. Click on '....'
49
+ 3. Scroll down to '....'
50
+ 4. See error
51
+ validations:
52
+ required: true
53
+ - type: textarea
54
+ id: expected
55
+ attributes:
56
+ label: Expected behavior
57
+ description: Provide a clear and concise description of what you expected to happen.
58
+ placeholder: |
59
+ As a user, I expected ___ behavior but i am seeing ___
60
+ validations:
61
+ required: true
62
+ - type: dropdown
63
+ attributes:
64
+ label: How often does this bug happen?
65
+ description: |
66
+ Following the repro steps above, how easily are you able to reproduce this bug?
67
+ options:
68
+ - Every time
69
+ - Often
70
+ - Sometimes
71
+ - Only once
72
+ - type: textarea
73
+ id: screenshots_or_videos
74
+ attributes:
75
+ label: Screenshots or Videos
76
+ description: |
77
+ If applicable, add screenshots or a video to help explain your problem.
78
+ For more information on the supported file image/file types and the file size limits, please refer
79
+ to the following link: https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/attaching-files
80
+ placeholder: |
81
+ You can drag your video or image files inside of this editor ↓
82
+ - type: textarea
83
+ id: platform
84
+ attributes:
85
+ label: Platform
86
+ description: |
87
+ Please let us know which Operating System and Node version you were using when the issue occurred.
88
+ placeholder: |
89
+ - OS: [e.g. macOS, Windows, Linux, iOS, Android]
90
+ - Node Version: [e.g. 16.6.0]
91
+ validations:
92
+ required: true
93
+ - type: input
94
+ id: package-version
95
+ attributes:
96
+ label: Package version
97
+ description: |
98
+ Please let us know the exact version of the package you were using when the issue occurred. Please don't just put in "latest", as this is subject to change.
99
+ placeholder: |
100
+ e.g. v6.0.0
101
+ validations:
102
+ required: true
103
+ - type: input
104
+ id: ts-version
105
+ attributes:
106
+ label: AWS SDK version
107
+ description: |
108
+ Please include what version of the AWS SDK you are using
109
+ placeholder: |
110
+ e.g. v3.226.0
111
+ - type: textarea
112
+ id: additional
113
+ attributes:
114
+ label: Additional context
115
+ description: Add any other context about the problem here.
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Feature Requests & Questions
4
+ url: https://github.com/bbc/sqs-consumer/discussions
5
+ about: Please ask and answer questions here.
@@ -0,0 +1,25 @@
1
+ name: "CLA Check"
2
+ on:
3
+ issue_comment:
4
+ types: [created]
5
+ pull_request_target:
6
+ types: [opened,closed,synchronize]
7
+
8
+ jobs:
9
+ CLAAssistant:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: "CLA Check"
13
+ if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
14
+ uses: contributor-assistant/github-action@v2.2.0
15
+ env:
16
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17
+ PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
18
+ with:
19
+ path-to-signatures: 'sqs-consumer/v1/cla.json'
20
+ remote-organization-name: 'bbc'
21
+ remote-repository-name: 'cla-signatures'
22
+ path-to-document: 'https://bbc.github.io/cla-signatures/cla/v1/cla.html'
23
+ branch: 'main'
24
+ allowlist: bot*
25
+ custom-allsigned-prcomment: '**CLA CHECK** All Contributors have signed the CLA'
@@ -0,0 +1,76 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ "main" ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ "main" ]
20
+ schedule:
21
+ - cron: '43 21 * * 2'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'javascript' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Use only 'java' to analyze code written in Java, Kotlin or both
38
+ # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
39
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
40
+
41
+ steps:
42
+ - name: Checkout repository
43
+ uses: actions/checkout@v3
44
+
45
+ # Initializes the CodeQL tools for scanning.
46
+ - name: Initialize CodeQL
47
+ uses: github/codeql-action/init@v2
48
+ with:
49
+ languages: ${{ matrix.language }}
50
+ # If you wish to specify custom queries, you can do so here or in a config file.
51
+ # By default, queries listed here will override any specified in a config file.
52
+ # Prefix the list here with "+" to use these queries and those in the config file.
53
+
54
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
55
+ # queries: security-extended,security-and-quality
56
+
57
+
58
+ # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
59
+ # If this step fails, then you should remove it and run the build manually (see below)
60
+ - name: Autobuild
61
+ uses: github/codeql-action/autobuild@v2
62
+
63
+ # ℹ️ Command-line programs to run using the OS shell.
64
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
65
+
66
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
67
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
68
+
69
+ # - run: |
70
+ # echo "Run, Build Application using script"
71
+ # ./location_of_script_within_repo/buildscript.sh
72
+
73
+ - name: Perform CodeQL Analysis
74
+ uses: github/codeql-action/analyze@v2
75
+ with:
76
+ category: "/language:${{matrix.language}}"
@@ -30,6 +30,6 @@ jobs:
30
30
  - name: Report Coverage
31
31
  uses: paambaati/codeclimate-action@v3.2.0
32
32
  env:
33
- CC_TEST_REPORTER_ID: 2d851f8f3a9348ac4f43262305037f80a730c2660fda50af8ae4d445fd89333b
33
+ CC_TEST_REPORTER_ID: 760097cb88b4c685dce427cf94a8e12a5f082774d06b4f4f5daef839ffc07821
34
34
  with:
35
35
  coverageCommand: npm run lcov
@@ -0,0 +1,55 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy static content to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches: ["main"]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions:
14
+ contents: read
15
+ pages: write
16
+ id-token: write
17
+
18
+ # Allow one concurrent deployment
19
+ concurrency:
20
+ group: "pages"
21
+ cancel-in-progress: true
22
+
23
+ jobs:
24
+ # Single deploy job since we're just deploying
25
+ deploy:
26
+ environment:
27
+ name: github-pages
28
+ url: ${{ steps.deployment.outputs.page_url }}
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - name: Checkout
32
+ uses: actions/checkout@v3
33
+
34
+ - name: Setup Node.js
35
+ uses: actions/setup-node@v3
36
+ with:
37
+ node-version: 16.x
38
+
39
+ - name: Install Node Modules
40
+ run: npm ci
41
+
42
+ - name: Build Docs
43
+ run: npm run generate-docs
44
+
45
+ - name: Setup Pages
46
+ uses: actions/configure-pages@v2
47
+
48
+ - name: Upload artifact
49
+ uses: actions/upload-pages-artifact@v1
50
+ with:
51
+ path: './public'
52
+
53
+ - name: Deploy to GitHub Pages
54
+ id: deployment
55
+ uses: actions/deploy-pages@v1
package/.prettierignore CHANGED
@@ -1,4 +1,5 @@
1
1
  node_modules
2
2
  coverage
3
3
  bake-scripts
4
- dist
4
+ dist
5
+ public
package/README.md CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  [![NPM downloads](https://img.shields.io/npm/dm/sqs-consumer.svg?style=flat)](https://npmjs.org/package/sqs-consumer)
4
4
  [![Build Status](https://github.com/bbc/sqs-consumer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/bbc/sqs-consumer/actions/workflows/test.yml)
5
- [![Code Climate](https://codeclimate.com/github/BBC/sqs-consumer/badges/gpa.svg)](https://codeclimate.com/github/BBC/sqs-consumer)
6
- [![Test Coverage](https://codeclimate.com/github/BBC/sqs-consumer/badges/coverage.svg)](https://codeclimate.com/github/BBC/sqs-consumer)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/16ec3f59e73bc898b7ff/maintainability)](https://codeclimate.com/github/bbc/sqs-consumer/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/16ec3f59e73bc898b7ff/test_coverage)](https://codeclimate.com/github/bbc/sqs-consumer/test_coverage)
7
7
 
8
8
  Build SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing.
9
9
 
10
10
  ## Installation
11
11
 
12
+ To install this package, simply enter the following command into your terminal (or the variant of whatever package manager you are using):
13
+
12
14
  ```bash
13
- npm install sqs-consumer --save-dev
15
+ npm install --save-dev sqs-consumer
14
16
  ```
15
17
 
16
18
  > **Note**
@@ -43,14 +45,16 @@ app.on('processing_error', (err) => {
43
45
  app.start();
44
46
  ```
45
47
 
46
- - The queue is polled continuously for messages using [long polling](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).
48
+ - The queue is polled continuously for messages using [long polling](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).
47
49
  - Messages are deleted from the queue once the handler function has completed successfully.
48
- - Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An [SQS redrive policy](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/SQSDeadLetterQueue.html) can be used to move messages that cannot be processed to a dead letter queue.
50
+ - Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An [SQS redrive policy](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/SQSDeadLetterQueue.html) can be used to move messages that cannot be processed to a dead letter queue.
49
51
  - By default messages are processed one at a time – a new message won't be received until the first one has been processed. To process messages in parallel, use the `batchSize` option [detailed below](#options).
50
52
 
53
+ You can also find some examples of sqs-consumer implemented in various ways within the [examples directory](./examples/).
54
+
51
55
  ### Credentials
52
56
 
53
- By default the consumer will look for AWS credentials in the places [specified by the AWS SDK](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials). The simplest option is to export your credentials as environment variables:
57
+ By default the consumer will look for AWS credentials in the places [specified by the AWS SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials). The simplest option is to export your credentials as environment variables:
54
58
 
55
59
  ```bash
56
60
  export AWS_SECRET_ACCESS_KEY=...
@@ -92,30 +96,15 @@ app.on('timeout_error', (err) => {
92
96
  app.start();
93
97
  ```
94
98
 
99
+ ### AWS IAM Permissions
100
+
101
+ Consumer will receive and delete messages from the SQS queue. Ensure `sqs:ReceiveMessage`, `sqs:DeleteMessage`, `sqs:DeleteMessageBatch`, `sqs:ChangeMessageVisibility` and `sqs:ChangeMessageVisibilityBatch` access is granted on the queue being consumed.
102
+
95
103
  ## API
96
104
 
97
105
  ### `Consumer.create(options)`
98
106
 
99
- Creates a new SQS consumer.
100
-
101
- #### Options
102
-
103
- - `queueUrl` - _String_ - The SQS queue URL
104
- - `region` - _String_ - The AWS region (default `eu-west-1`)
105
- - `handleMessage` - _Function_ - An `async` function (or function that returns a `Promise`) to be called whenever a message is received. Receives an SQS message object as it's first argument.
106
- - `handleMessageBatch` - _Function_ - An `async` function (or function that returns a `Promise`) to be called whenever a batch of messages is received. Similar to `handleMessage` but will receive the list of messages, not each message individually. **If both are set, `handleMessageBatch` overrides `handleMessage`**.
107
- - `handleMessageTimeout` - _Number_ - Time in ms to wait for `handleMessage` to process a message before timing out. Emits `timeout_error` on timeout. By default, if `handleMessage` times out, the unprocessed message returns to the end of the queue.
108
- - `attributeNames` - _Array_ - List of queue attributes to retrieve (i.e. `['All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount']`).
109
- - `messageAttributeNames` - _Array_ - List of message attributes to retrieve (i.e. `['name', 'address']`).
110
- - `batchSize` - _Number_ - The number of messages to request from SQS when polling (default `1`). This cannot be higher than the AWS limit of 10.
111
- - `visibilityTimeout` - _Number_ - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.
112
- - `heartbeatInterval` - _Number_ - The interval (in seconds) between requests to extend the message visibility timeout. On each heartbeat the visibility is extended by adding `visibilityTimeout` to the number of seconds since the start of the handler function. This value must less than `visibilityTimeout`.
113
- - `terminateVisibilityTimeout` - _Boolean_ - If true, sets the message visibility timeout to 0 after a `processing_error` (defaults to `false`).
114
- - `waitTimeSeconds` - _Number_ - The duration (in seconds) for which the call will wait for a message to arrive in the queue before returning (defaults to `20`).
115
- - `authenticationErrorTimeout` - _Number_ - The duration (in milliseconds) to wait before retrying after an authentication error (defaults to `10000`).
116
- - `pollingWaitTimeMs` - _Number_ - The duration (in milliseconds) to wait before repolling the queue (defaults to `0`).
117
- - `sqs` - _Object_ - An optional [SQS Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/classes/sqsclient.html) object to use if you need to configure the client manually
118
- - `shouldDeleteMessages` - _Boolean_ - Default to `true`, if you don't want the package to delete messages from sqs set this to `false`
107
+ Creates a new SQS consumer using the [defined options](https://bbc.github.io/sqs-consumer/interfaces/ConsumerOptions.html).
119
108
 
120
109
  ### `consumer.start()`
121
110
 
@@ -123,7 +112,7 @@ Start polling the queue for messages.
123
112
 
124
113
  ### `consumer.stop()`
125
114
 
126
- Stop polling the queue for messages.
115
+ Stop polling the queue for messages (pre existing requests will still be made until concluded).
127
116
 
128
117
  ### `consumer.isRunning`
129
118
 
@@ -131,23 +120,14 @@ Returns the current polling state of the consumer: `true` if it is actively poll
131
120
 
132
121
  ### Events
133
122
 
134
- Each consumer is an [`EventEmitter`](http://nodejs.org/api/events.html) and emits the following events:
123
+ Each consumer is an [`EventEmitter`](https://nodejs.org/api/events.html) and [emits these events](https://bbc.github.io/sqs-consumer/interfaces/Events.html).
135
124
 
136
- | Event | Params | Description |
137
- | -------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
138
- | `error` | `err`, `[message]` | Fired when an error occurs interacting with the queue. If the error correlates to a message, that message is included in Params |
139
- | `processing_error` | `err`, `message` | Fired when an error occurs processing the message. |
140
- | `timeout_error` | `err`, `message` | Fired when `handleMessageTimeout` is supplied as an option and if `handleMessage` times out. |
141
- | `message_received` | `message` | Fired when a message is received. |
142
- | `message_processed` | `message` | Fired when a message is successfully processed and removed from the queue. |
143
- | `response_processed` | None | Fired after one batch of items (up to `batchSize`) has been successfully processed. |
144
- | `stopped` | None | Fired when the consumer finally stops its work. |
145
- | `empty` | None | Fired when the queue is empty (All messages have been consumed). |
125
+ ## Contributing
146
126
 
147
- ### AWS IAM Permissions
127
+ We welcome and appreciate contributions for anyone who would like to take the time to fix a bug or implement a new feature.
148
128
 
149
- Consumer will receive and delete messages from the SQS queue. Ensure `sqs:ReceiveMessage`, `sqs:DeleteMessage`, `sqs:DeleteMessageBatch`, `sqs:ChangeMessageVisibility` and `sqs:ChangeMessageVisibilityBatch` access is granted on the queue being consumed.
129
+ But before you get started, [please read the contributing guidelines](https://github.com/bbc/sqs-consumer/blob/main/.github/CONTRIBUTING.md) and [code of conduct](https://github.com/bbc/sqs-consumer/blob/main/.github/CODE_OF_CONDUCT.md).
150
130
 
151
- ### Contributing
131
+ ## License
152
132
 
153
- See contributing [guidelines](https://github.com/bbc/sqs-consumer/blob/main/.github/CONTRIBUTING.md).
133
+ SQS Consumer is distributed under the Apache License, Version 2.0, see [LICENSE](https://github.com/bbc/sqs-consumer/blob/main/LICENSE) for more information.
package/dist/bind.d.ts CHANGED
@@ -1 +1,5 @@
1
+ /**
2
+ * Auto binds the provided properties
3
+ * @param obj an object containing the available properties
4
+ */
1
5
  export declare function autoBind(obj: object): void;
package/dist/bind.js CHANGED
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.autoBind = void 0;
4
+ /**
5
+ * Determines if the property is a method
6
+ * @param propertyName the name of the property
7
+ * @param value the value of the property
8
+ */
4
9
  function isMethod(propertyName, value) {
5
10
  return propertyName !== 'constructor' && typeof value === 'function';
6
11
  }
12
+ /**
13
+ * Auto binds the provided properties
14
+ * @param obj an object containing the available properties
15
+ */
7
16
  function autoBind(obj) {
8
17
  const propertyNames = Object.getOwnPropertyNames(obj.constructor.prototype);
9
18
  propertyNames.forEach((propertyName) => {
@@ -1,72 +1,111 @@
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 {
1
+ import { ConsumerOptions, TypedEventEmitter } from './types';
2
+ /**
3
+ * [Usage](https://bbc.github.io/sqs-consumer/index.html#usage)
4
+ */
5
+ export declare class Consumer extends TypedEventEmitter {
6
+ private pollingTimeoutId;
7
+ private heartbeatTimeoutId;
8
+ private handleMessageTimeoutId;
9
+ private stopped;
34
10
  private queueUrl;
35
11
  private handleMessage;
36
12
  private handleMessageBatch;
13
+ private sqs;
37
14
  private handleMessageTimeout;
38
15
  private attributeNames;
39
16
  private messageAttributeNames;
40
- private stopped;
17
+ private shouldDeleteMessages;
41
18
  private batchSize;
42
19
  private visibilityTimeout;
20
+ private terminateVisibilityTimeout;
43
21
  private waitTimeSeconds;
44
22
  private authenticationErrorTimeout;
45
23
  private pollingWaitTimeMs;
46
- private terminateVisibilityTimeout;
47
24
  private heartbeatInterval;
48
- private sqs;
49
- private shouldDeleteMessages;
50
25
  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;
26
+ /**
27
+ * Creates a new SQS consumer.
28
+ */
55
29
  static create(options: ConsumerOptions): Consumer;
30
+ /**
31
+ * Start polling the queue for messages.
32
+ */
56
33
  start(): void;
34
+ /**
35
+ * Stop polling the queue for messages (pre existing requests will still be made until concluded).
36
+ */
57
37
  stop(): void;
58
- private handleSqsResponse;
59
- private processMessage;
60
- private receiveMessage;
61
- private deleteMessage;
62
- private executeHandler;
63
- private changeVisibilityTimeout;
38
+ /**
39
+ * Returns the current polling state of the consumer: `true` if it is actively polling, `false` if it is not.
40
+ */
41
+ get isRunning(): boolean;
42
+ /**
43
+ * Emit one of the consumer's error events depending on the error received.
44
+ * @param err The error object to forward on
45
+ * @param message The message that the error occurred on
46
+ */
64
47
  private emitError;
48
+ /**
49
+ * Poll for new messages from SQS
50
+ */
65
51
  private poll;
52
+ /**
53
+ * Send a request to SQS to retrieve messages
54
+ * @param params The required params to receive messages from SQS
55
+ */
56
+ private receiveMessage;
57
+ /**
58
+ * Handles the response from AWS SQS, determining if we should proceed to
59
+ * the message handler.
60
+ * @param response The output from AWS SQS
61
+ */
62
+ private handleSqsResponse;
63
+ /**
64
+ * Process a message that has been received from SQS. This will execute the message
65
+ * handler and delete the message once complete.
66
+ * @param message The message that was delivered from SQS
67
+ */
68
+ private processMessage;
69
+ /**
70
+ * Process a batch of messages from the SQS queue.
71
+ * @param messages The messages that were delivered from SQS
72
+ */
66
73
  private processMessageBatch;
67
- private deleteMessageBatch;
68
- private executeBatchHandler;
69
- private changeVisibilityTimeoutBatch;
74
+ /**
75
+ * Trigger a function on a set interval
76
+ * @param heartbeatFn The function that should be triggered
77
+ */
70
78
  private startHeartbeat;
79
+ /**
80
+ * Change the visibility timeout on a message
81
+ * @param message The message to change the value of
82
+ * @param timeout The new timeout that should be set
83
+ */
84
+ private changeVisibilityTimeout;
85
+ /**
86
+ * Change the visibility timeout on a batch of messages
87
+ * @param messages The messages to change the value of
88
+ * @param timeout The new timeout that should be set
89
+ */
90
+ private changeVisibilityTimeoutBatch;
91
+ /**
92
+ * Trigger the applications handleMessage function
93
+ * @param message The message that was received from SQS
94
+ */
95
+ private executeHandler;
96
+ /**
97
+ * Execute the application's message batch handler
98
+ * @param messages The messages that should be forwarded from the SQS queue
99
+ */
100
+ private executeBatchHandler;
101
+ /**
102
+ * Delete a single message from SQS
103
+ * @param message The message to delete from the SQS queue
104
+ */
105
+ private deleteMessage;
106
+ /**
107
+ * Delete a batch of messages from the SQS queue.
108
+ * @param messages The messages that should be deleted from SQS
109
+ */
110
+ private deleteMessageBatch;
71
111
  }
72
- export {};