{"_id":"@edonadei/sqs-consumer","_rev":"2-e8b723f89a834d390eced79c7145ed74","name":"@edonadei/sqs-consumer","dist-tags":{"latest":"5.8.0"},"versions":{"5.7.0":{"name":"@edonadei/sqs-consumer","version":"5.7.0","description":"Build SQS-based Node applications without the boilerplate","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","watch":"tsc --watch","clean":"rm -fr dist/*","prepublish":"npm run build","pretest":"npm run build","test":"mocha --recursive --full-trace --exit","lint":"eslint . --ext .ts","lint:fix":"eslint . --fix","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lcov":"nyc mocha && nyc report --reporter=lcov","posttest":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/edonadei/sqs-consumer.git"},"bugs":{"url":"https://github.com/edonadei/sqs-consumer/issues"},"homepage":"https://github.com/edonadei/sqs-consumer","keywords":["sqs","queue","consumer"],"license":"Apache-2.0","devDependencies":{"@types/chai":"^4.2.11","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/node":"^14.0.13","@types/sinon":"^9.0.4","@types/typescript":"^2.0.0","chai":"^4.2.0","codeclimate-test-reporter":"^0.5.1","eslint":"^7.2.0","eslint-config-iplayer-ts":"^2.0.0","mocha":"^8.0.1","nyc":"^15.1.0","p-event":"^4.2.0","sinon":"^9.0.2","ts-node":"^8.10.2","tslint-config-airbnb":"^5.11.2","tslint-microsoft-contrib":"^6.2.0","typescript":"^3.9.5","aws-sdk":"^2.699.0"},"dependencies":{"debug":"^4.1.1"},"peerDependencies":{"aws-sdk":"^2.699.0"},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"sourceMap":true,"instrument":true},"eslintConfig":{"extends":"iplayer-ts","parserOptions":{"ecmaVersion":2017,"sourceType":"module"}},"mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"gitHead":"143bdc6949f5e57e5946239e5cda38a88cdc67ec","_id":"@edonadei/sqs-consumer@5.7.0","_nodeVersion":"16.8.0","_npmVersion":"7.21.0","dist":{"integrity":"sha512-Boi2EBgC4Y/r1Y6jss7ZnnKGzWOP+tYhHIokagkTaGQjslvYWNvCbJ1bc+l3j2zY9KzS/HVJjNuDiepjHPj45A==","shasum":"7b7eabb93e7f51126a9ed5eff046387a3492d753","tarball":"https://registry.npmjs.org/@edonadei/sqs-consumer/-/sqs-consumer-5.7.0.tgz","fileCount":17,"unpackedSize":55651,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6NIECRA9TVsSAnZWagAAZnMP/ikS+PC/WtCEhVh1BnDi\nBi7eMdkk6JkEsLATDRPfTNtQDu51MMTd2UwX6GRm+QHgKfcH0wqSHRgJawfC\nDewCO37POadbNjEj/8kqGg6xrKH7q3kjH2MXrqXLbZqjKFUo4qIfs6di7yKC\nEBNsnEbwBiWGLnzncf2Q6kVH498WhFJxdhWK/AyR0m3LltO77Z5ydsyDYh7H\n8/UdY2SOtzK7AGoW/kv9jUbFCgdUNKGDE8W5NdV17Ooplpxp7EO3iRKtTH3H\nVAMf2v5q+2WJ53rp0Y+YqncQ+8VayA6NJBcW0MLRT87za+f5i0RvAwSO9dA2\nz54n5GJae5f4TuHLiDMkhqUMwsbYna5Y+4ynav/sUx13CNRXtNyPexWMmT47\nrz1LWdV1jZ6mQbhPSZLf0GS47B2Jd0JbQps0Zv6t+T42JvzIEYcw7LrAV4F9\nRGZTiBPdoABueXWEoMvSG3NmoLBkqzl4e0idulaG7bXevRHLFW3lX8pu8iIf\n0I9/BN6xjZdOtKGu3OE6JA5S/j1FiUFhZ9OaB3sJlm+ci3XttPg+e8x1vJkF\n85shVphJqfm7maYWpTUXJPqacyGVmBb1nw7P711Bpp8ns7bh+652tg+hoMd5\n3jmxHOdyGs+Swwg4wSYSCmvnr2zRSvqt3sLTgLN/2IOJQrirqvN1Wuy2Mk5U\nA+YP\r\n=6aVx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEI4t5aRM/8W25Gikd7wlauBG7WcJhOWxmEQD0uN/4/TAiEAsMqDsmG2vFhKUKMO39HlfDosY/8M5CXDRuBURPUQATo="}]},"_npmUser":{"name":"edonadei","email":"emrick.donadei@hotmail.fr"},"directories":{},"maintainers":[{"name":"edonadei","email":"emrick.donadei@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sqs-consumer_5.7.0_1642648067935_0.5156926619155979"},"_hasShrinkwrap":false},"5.8.0":{"name":"@edonadei/sqs-consumer","version":"5.8.0","description":"Build SQS-based Node applications without the boilerplate","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","watch":"tsc --watch","clean":"rm -fr dist/*","prepublish":"npm run build","pretest":"npm run build","test":"mocha --recursive --full-trace --exit","lint":"eslint . --ext .ts","lint:fix":"eslint . --fix","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lcov":"nyc mocha && nyc report --reporter=lcov","posttest":"npm run lint"},"repository":{"type":"git","url":"git+https://github.com/BBC/sqs-consumer.git"},"bugs":{"url":"https://github.com/BBC/sqs-consumer/issues"},"homepage":"https://github.com/BBC/sqs-consumer","keywords":["sqs","queue","consumer"],"license":"Apache-2.0","devDependencies":{"@types/chai":"^4.2.11","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/node":"^14.0.13","@types/sinon":"^9.0.4","@types/typescript":"^2.0.0","chai":"^4.2.0","codeclimate-test-reporter":"^0.5.1","eslint":"^7.2.0","eslint-config-iplayer-ts":"^2.0.0","mocha":"^8.0.1","nyc":"^15.1.0","p-event":"^4.2.0","sinon":"^9.0.2","ts-node":"^8.10.2","tslint-config-airbnb":"^5.11.2","tslint-microsoft-contrib":"^6.2.0","typescript":"^3.9.5","aws-sdk":"^2.699.0"},"dependencies":{"debug":"^4.1.1"},"peerDependencies":{"aws-sdk":"^2.699.0"},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"sourceMap":true,"instrument":true},"eslintConfig":{"extends":"iplayer-ts","parserOptions":{"ecmaVersion":2017,"sourceType":"module"}},"mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"gitHead":"143bdc6949f5e57e5946239e5cda38a88cdc67ec","_id":"@edonadei/sqs-consumer@5.8.0","_nodeVersion":"16.8.0","_npmVersion":"7.21.0","dist":{"integrity":"sha512-+g4rKbs/l71LPDgXLkofsiBSdzPTEPiT0LoIHeeTqPhL03b6uihNaJiGFOuCQedoZR7AKjSicsV/4lc4b7bW8g==","shasum":"0c906705edaca8d6afa01ef01af8c24cd2fe47ee","tarball":"https://registry.npmjs.org/@edonadei/sqs-consumer/-/sqs-consumer-5.8.0.tgz","fileCount":25,"unpackedSize":71553,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh7eYHCRA9TVsSAnZWagAADqgP/2V5UlzEJe+IQUTKe1Bn\nJKn0PgBnKRsDRuEXzmhNd6eGsKJLYtPS5ma/a3/7ksVRCluSgd37s/8blsFo\n1Dac4VtNmc9NUTv6CSryxWrR7InSa8Bi+uwxZGkbvYvY5W0vutwAOmYr7UKn\nhhdJsCsk1qFbDgqv17bF0XPhlX5DbccCo1Lmdm/+tKEdUlvgyhN6ksLocYBv\nYNbbp/FHFfB5CThTg37lOY2JzfQU11HznRNxqtRQjdRjKADHdY6YlwlrhwT8\nCVY9yeIDaRaE0326Bs+gyRH3jy1e+AAPzEtcY3kiY8etMODmbl+JF7AohStR\nkufD5i/9gHigVSw3sXNdS6DF/4tONO/WC2DgNNymiy1FHmpCGoEwvE/BwW3Q\nD2cHh1Xzpw8IAGbLRwPaBEMSR0bQgnv7JWC76kWE7knZAztcd+lROrCH0Vdq\nbHKu0Y/969gS9dZ2t3QGYpujg3QCmuYlGK5TP77xJbS7hEIVaSr++Y5uYkUo\nYbkV7YSwaS/pwr5HUIKCPuzm43yJ3zmQVaBamH6AqPUKaMGVT898xF6l35qn\n++7BfT2M3I9KgRwJ24dm4q+cIwiVpFP+97O9YWxx2nxEO5K3c1e2LIHMfLLw\n6hwRkIz0O14k1qZ3xnAwmxzAmnIT7x6d/DI/z9TyGhCvIGX3h2bRJaGxkd3C\ngPQu\r\n=Ybyw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE+A7mf+T9sa08TKM/PYF4PN15rUMTWbLq4z0qq6iwJnAiEAwhsiIyWHJ5jG0JHkm+vKYu72sMRO2Sij6DTLqyp5XWE="}]},"_npmUser":{"name":"edonadei","email":"emrick.donadei@hotmail.fr"},"directories":{},"maintainers":[{"name":"edonadei","email":"emrick.donadei@hotmail.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sqs-consumer_5.8.0_1642980871197_0.03345874571183649"},"_hasShrinkwrap":false}},"time":{"created":"2022-01-20T03:07:47.877Z","5.7.0":"2022-01-20T03:07:48.062Z","modified":"2022-04-05T06:42:51.910Z","5.8.0":"2022-01-23T23:34:31.323Z"},"maintainers":[{"name":"edonadei","email":"emrick.donadei@hotmail.fr"}],"description":"Build SQS-based Node applications without the boilerplate","homepage":"https://github.com/BBC/sqs-consumer","keywords":["sqs","queue","consumer"],"repository":{"type":"git","url":"git+https://github.com/BBC/sqs-consumer.git"},"bugs":{"url":"https://github.com/BBC/sqs-consumer/issues"},"license":"Apache-2.0","readme":"# sqs-consumer\r\n\r\n[![NPM downloads](https://img.shields.io/npm/dm/sqs-consumer.svg?style=flat)](https://npmjs.org/package/sqs-consumer)\r\n[![Build Status](https://travis-ci.org/bbc/sqs-consumer.svg)](https://travis-ci.org/bbc/sqs-consumer) \r\n[![Code Climate](https://codeclimate.com/github/BBC/sqs-consumer/badges/gpa.svg)](https://codeclimate.com/github/BBC/sqs-consumer) \r\n[![Test Coverage](https://codeclimate.com/github/BBC/sqs-consumer/badges/coverage.svg)](https://codeclimate.com/github/BBC/sqs-consumer)\r\n\r\nBuild SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install sqs-consumer --save\r\n```\r\n\r\n## Usage\r\n\r\n```js\r\nconst { Consumer } = require('sqs-consumer');\r\n\r\nconst app = Consumer.create({\r\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\r\n  handleMessage: async (message) => {\r\n    // do some work with `message`\r\n  }\r\n});\r\n\r\napp.on('error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.on('processing_error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.start();\r\n```\r\n\r\n* The queue is polled continuously for messages using [long polling](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).\r\n* Messages are deleted from the queue once the handler function has completed successfully.\r\n* 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.\r\n* 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).\r\n* By default, the default Node.js HTTP/HTTPS SQS agent creates a new TCP connection for every new request ([AWS SQS documentation](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html)). To avoid the cost of establishing a new connection, you can reuse an existing connection by passing a new SQS instance with `keepAlive: true`.\r\n```js\r\nconst { Consumer } = require('sqs-consumer');\r\nconst AWS = require('aws-sdk');\r\n\r\nconst app = Consumer.create({\r\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\r\n  handleMessage: async (message) => {\r\n    // do some work with `message`\r\n  },\r\n  sqs: new AWS.SQS({\r\n    httpOptions: {\r\n      agent: new https.Agent({\r\n        keepAlive: true\r\n      })\r\n    }\r\n  })\r\n});\r\n\r\napp.on('error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.on('processing_error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.start();\r\n```\r\n\r\n### Credentials\r\n\r\nBy 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:\r\n\r\n```bash\r\nexport AWS_SECRET_ACCESS_KEY=...\r\nexport AWS_ACCESS_KEY_ID=...\r\n```\r\n\r\nIf you need to specify your credentials manually, you can use a pre-configured instance of the [AWS SQS](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html) client:\r\n\r\n\r\n```js\r\nconst { Consumer } = require('sqs-consumer');\r\nconst AWS = require('aws-sdk');\r\n\r\nAWS.config.update({\r\n  region: 'eu-west-1',\r\n  accessKeyId: '...',\r\n  secretAccessKey: '...'\r\n});\r\n\r\nconst app = Consumer.create({\r\n  queueUrl: 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',\r\n  handleMessage: async (message) => {\r\n    // ...\r\n  },\r\n  sqs: new AWS.SQS()\r\n});\r\n\r\napp.on('error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.on('processing_error', (err) => {\r\n  console.error(err.message);\r\n});\r\n\r\napp.on('timeout_error', (err) => {\r\n console.error(err.message);\r\n});\r\n\r\napp.start();\r\n```\r\n\r\n## API\r\n\r\n### `Consumer.create(options)`\r\n\r\nCreates a new SQS consumer.\r\n\r\n#### Options\r\n\r\n* `queueUrl` - _String_ - The SQS queue URL\r\n* `region` - _String_ - The AWS region (default `eu-west-1`)\r\n* `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.\r\n* `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`**.\r\n* `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.\r\n* `attributeNames` - _Array_ - List of queue attributes to retrieve (i.e. `['All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount']`).\r\n* `messageAttributeNames` - _Array_ - List of message attributes to retrieve (i.e. `['name', 'address']`).\r\n* `batchSize` - _Number_ - The number of messages to request from SQS when polling (default `1`). This cannot be higher than the AWS limit of 10.\r\n* `visibilityTimeout` - _Number_ - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.\r\n* `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`.\r\n* `terminateVisibilityTimeout` - _Boolean_ - If true, sets the message visibility timeout to 0 after a `processing_error` (defaults to `false`).\r\n* `waitTimeSeconds` - _Number_ - The duration (in seconds) for which the call will wait for a message to arrive in the queue before returning.\r\n* `authenticationErrorTimeout` - _Number_ - The duration (in milliseconds) to wait before retrying after an authentication error (defaults to `10000`).\r\n* `pollingWaitTimeMs` - _Number_ - The duration (in milliseconds) to wait before repolling the queue (defaults to `0`).\r\n* `sqs` - _Object_ - An optional [AWS SQS](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html) object to use if you need to configure the client manually\r\n\r\n### `consumer.start()`\r\n\r\nStart polling the queue for messages.\r\n\r\n### `consumer.stop()`\r\n\r\nStop polling the queue for messages.\r\n\r\n### `consumer.isRunning`  \r\n\r\nReturns the current polling state of the consumer: `true` if it is actively polling, `false` if it is not.\r\n\r\n### Events\r\n\r\nEach consumer is an [`EventEmitter`](http://nodejs.org/api/events.html) and emits the following events:\r\n\r\n|Event|Params|Description|\r\n|-----|------|-----------|\r\n|`error`|`err`, `[message]`|Fired when an error occurs interacting with the queue. If the error correlates to a message, that error is included in Params|\r\n|`processing_error`|`err`, `message`|Fired when an error occurs processing the message.|\r\n|`timeout_error`|`err`, `message`|Fired when `handleMessageTimeout` is supplied as an option and if `handleMessage` times out.|\r\n|`message_received`|`message`|Fired when a message is received.|\r\n|`message_processed`|`message`|Fired when a message is successfully processed and removed from the queue.|\r\n|`response_processed`|None|Fired after one batch of items (up to `batchSize`) has been successfully processed.|\r\n|`stopped`|None|Fired when the consumer finally stops its work.|\r\n|`empty`|None|Fired when the queue is empty (All messages have been consumed).|\r\n\r\n### AWS IAM Permissions\r\n\r\nConsumer will receive and delete messages from the SQS queue. Ensure `sqs:ReceiveMessage` and `sqs:DeleteMessage` access is granted on the queue being consumed.\r\n\r\n\r\n### Contributing \r\nSee contributing [guidelines](https://github.com/bbc/sqs-consumer/blob/master/.github/CONTRIBUTING.md).\r\n","readmeFilename":"README.md"}