{"_id":"@april9/sqs-consumer","_rev":"15-b8b55810742172d6bcf1873888631da7","name":"@april9/sqs-consumer","dist-tags":{"latest":"6.1.0"},"versions":{"6.0.0":{"name":"@april9/sqs-consumer","version":"6.0.0","keywords":["sqs","storageQueue","queue","consumer"],"license":"Apache-2.0","_id":"@april9/sqs-consumer@6.0.0","maintainers":[{"name":"clempe.april9","email":"allan@april9.com.au"},{"name":"thiagopxp","email":"thiagopxp@gmail.com"}],"homepage":"https://github.com/april9-digital-consulting/sqs-consumer","bugs":{"url":"https://github.com/april9-digital-consulting/sqs-consumer/issues"},"nyc":{"include":["src/**/*.ts"],"require":["ts-node/register"],"extension":[".ts"],"sourceMap":true,"instrument":true},"dist":{"shasum":"93e984b0ba54097c6bc2c4276acadc204dd214fa","tarball":"https://registry.npmjs.org/@april9/sqs-consumer/-/sqs-consumer-6.0.0.tgz","fileCount":43,"integrity":"sha512-lMTRWNVZWMHG2r3eEd+ubkwUa189X2Cae40uYBDCpMpst1rKEEsXvSY2Y2bjUyQyalfdADnyYK2Xr6L90sB+5g==","signatures":[{"sig":"MEUCIHSBCItQK0h4y3bgnqGHeWUaiGKbaeSWUAszD3vTPMEBAiEAsHFHVDDZlRlCY5nRfD4PmThqcmFDMAoieo5yLt2dE5g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":186281,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg7lCYCRA9TVsSAnZWagAAbUQQAIDezSQQHdi8/JSTa1ZJ\n/nup0Cjw48k1mxlukjT5nc05GvoQGUU4plJOr+YqytRKAy/CgGiguSLTbsms\n4yiyrEIQj31VCQ23kweBgDWllj4O066vkb01GISJK4B3OYrI9lb+QAU0l9JH\nor9uu2iwNWmtaFvrBvFFsr/o1kZatc6c7WMPWJOKCMZlabyBYPKto3EPDHJe\nlAFzhK7kREEsiXrD6jQ1U6zUCFCXdG2XoPK54V++c8+Et6He5kLjaf51jfhY\nqnhFifwr5QXd2uua1KzPLwuj5TW61lcwmON2bNc4vZ+Co4wppcy0vXOSaAgX\nqCeQxP8tU6KhA0z82MV+asFn4LOfZgixhtZlNpZJrQIm/O8dyPG5bvxiHbge\nE5Y1Ta8fWUJnE2bVd8D6TjimgKjcmPni1bfjqi2MGVaJ1NfcHaiVr7sotcRt\nHQty0QsAVTlG0+IkWe1x+XoHFkYlq63knIwQaYCsLLWwMMf4GnoWbprlVWEO\n4HF+ZamVxvE8I5yO5yb1KlbB0lLfjp107ix80zqmb/kyg/OrT264x2aecJZ6\n3rbKvEtgk0v49kKKYGfzOtjGjXC0IWn3SVNcUtHrNBY+Kfl+Y5q1MQM7dNtw\nzpwRsGoWbbqpk0VmGUfOv0OHeMPFozuwL9lQX5Uv0jo1/ENKcUpWjFWANmfn\nCAJZ\r\n=ztmm\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"types":"dist/index.d.ts","gitHead":"f01ae79bbeaa0ea8a068b38d3151f3de7ab9d628","scripts":{"lcov":"nyc mocha && nyc report --reporter=lcov","lint":"eslint . --ext .ts","test":"mocha --recursive --full-trace --exit","build":"npm run clean && tsc","clean":"rm -fr dist/*","watch":"tsc --watch","pretest":"npm run build","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lint:fix":"eslint . --fix","posttest":"npm run lint","prepublish":"npm run build"},"_npmUser":{"name":"clempe.april9","email":"allan@april9.com.au"},"repository":{"url":"git+https://github.com/april9-digital-consulting/sqs-consumer.git","type":"git"},"_npmVersion":"6.14.8","description":"Build SQS-based Node applications without the boilerplate","directories":{},"_nodeVersion":"14.15.1","dependencies":{"debug":"^4.1.1"},"eslintConfig":{"rules":{"quotes":["error","single",{"avoidEscape":true}]},"extends":"iplayer-ts","parserOptions":{"sourceType":"module","ecmaVersion":2017}},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","chai":"^4.2.0","mocha":"^8.0.1","sinon":"^9.0.2","eslint":"^7.2.0","aws-sdk":"^2.699.0","p-event":"^4.2.0","ts-node":"^8.10.2","prettier":"^2.3.2","typescript":"^3.9.5","@types/chai":"^4.2.11","@types/node":"^14.0.13","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","@types/typescript":"^2.0.0","@azure/storage-queue":"^12.5.0","tslint-config-airbnb":"^5.11.2","eslint-plugin-prettier":"^3.4.0","eslint-config-iplayer-ts":"^2.0.0","tslint-microsoft-contrib":"^6.2.0","codeclimate-test-reporter":"^0.5.1"},"peerDependencies":{"aws-sdk":"^2.699.0"},"_npmOperationalInternal":{"tmp":"tmp/sqs-consumer_6.0.0_1626230935794_0.005729126431285092","host":"s3://npm-registry-packages"}},"6.1.0":{"name":"@april9/sqs-consumer","version":"6.1.0","keywords":["sqs","storageQueue","queue","consumer"],"license":"Apache-2.0","_id":"@april9/sqs-consumer@6.1.0","maintainers":[{"name":"clempe.april9","email":"allan@april9.com.au"},{"name":"thiagopxp","email":"thiagopxp@gmail.com"}],"homepage":"https://github.com/april9-digital-consulting/sqs-consumer","bugs":{"url":"https://github.com/april9-digital-consulting/sqs-consumer/issues"},"nyc":{"include":["src/**/*.ts"],"require":["ts-node/register"],"extension":[".ts"],"sourceMap":true,"instrument":true},"dist":{"shasum":"70f18960ae0f613c95a7da210061ef9c54772ea8","tarball":"https://registry.npmjs.org/@april9/sqs-consumer/-/sqs-consumer-6.1.0.tgz","fileCount":43,"integrity":"sha512-COIz6JszUjqxCd15X0yY29JkS9UxFQ1ndgBs1xjQOxVjg8R157h2DKKDszJRFNxBASiycxdXW0bzsitiOCXY5w==","signatures":[{"sig":"MEQCIQCRvKsLLJ1nPFBWRkbuuCw4IDMkNsPS+wyRJQBIaeeOTAIfHbUPM0pC/fy69Xn7+q4czSJxWo3vSc0k2sNM7OiZnA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":185248,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg7m6jCRA9TVsSAnZWagAA67kP/14nzU6hiVsaqmZj/rlS\nWtV7t1sSbJfZGf+LVuqYEx42j+Oq7USg0WGZ+ogrOrsKT+2eeI+aVPUOyZ5R\nXQU0R37AVPxYEgGErl1K11jvRM1+nGpw8Dzjo/4Iyd24PCcVVSjM/75y8yj5\nAaEtVcSSi4Ct4m8DBeKVOimsVOt9rgls7F8sEq0OprgyiZ06hxqSYJIDCe6Z\nf+N3k9FllrXoXrtg9nTISaVM3IRCh9Kse0ckjDBSxhr/WrqD7i6Zvyvld6Om\nhuQtxjlcmeWskHChb/kKL1Mc6+5SngAiexocQI8b289eAlvY4aNTuLVokIJ+\nLobxU3Gw3dQnslQgg9RWPuq25pe9jnLs9J9VyxFeDBqJ5rQk2XREjYatD/rT\nP03JvmxZ27+rs0dmQWH4JCCMY/tnDWHpSFbHfV3bkg/ecKgLAd+248JOiBgg\nNSOC2EeecRIRLwpXrdVPDOXnXQMwh9gtaNAY9QcHdw/mZO1DYefazrtZRhS1\n8BsP0DZo3Db+3PTcgyKnV3MSw4G/+CID58cr41qKpRnECBu0Ltr2jNepS2vC\nRnch5EAl6RWGTYrYk5k23Lgb9xDF3sp26LdXvfmuO1IG8bN/4X0Cs2V7rcBC\n2mdXql+CRAYbk/zBrGzwTN9CE1FzuYpRMnFuFJRCuohqDayl7Yzd4ziNtTvr\nzkwE\r\n=oB+p\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","mocha":{"spec":"test/**/**/*.ts","require":"ts-node/register"},"types":"dist/index.d.ts","gitHead":"454a5ba164aca6c7763a2cc5e9f3789aa7dfc82c","scripts":{"lcov":"nyc mocha && nyc report --reporter=lcov","lint":"eslint . --ext .ts","test":"mocha --recursive --full-trace --exit","build":"npm run clean && tsc","clean":"rm -fr dist/*","watch":"tsc --watch","pretest":"npm run build","coverage":"nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary","lint:fix":"eslint . --fix","posttest":"npm run lint","prepublish":"npm run build"},"_npmUser":{"name":"clempe.april9","email":"allan@april9.com.au"},"repository":{"url":"git+https://github.com/april9-digital-consulting/sqs-consumer.git","type":"git"},"_npmVersion":"6.14.8","description":"Build SQS-based Node applications without the boilerplate","directories":{},"_nodeVersion":"14.15.1","dependencies":{"debug":"^4.1.1"},"eslintConfig":{"rules":{"quotes":["error","single",{"avoidEscape":true}]},"extends":"iplayer-ts","parserOptions":{"sourceType":"module","ecmaVersion":2017}},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","chai":"^4.2.0","mocha":"^8.0.1","sinon":"^9.0.2","eslint":"^7.2.0","aws-sdk":"^2.699.0","p-event":"^4.2.0","ts-node":"^8.10.2","prettier":"^2.3.2","typescript":"^3.9.5","@types/chai":"^4.2.11","@types/node":"^14.0.13","@types/debug":"^4.1.5","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","@types/typescript":"^2.0.0","@azure/storage-queue":"^12.5.0","tslint-config-airbnb":"^5.11.2","eslint-plugin-prettier":"^3.4.0","eslint-config-iplayer-ts":"^2.0.0","tslint-microsoft-contrib":"^6.2.0","codeclimate-test-reporter":"^0.5.1"},"peerDependencies":{"aws-sdk":"^2.699.0"},"_npmOperationalInternal":{"tmp":"tmp/sqs-consumer_6.1.0_1626238626572_0.5206214314877946","host":"s3://npm-registry-packages"}}},"time":{"created":"2021-07-14T02:48:55.394Z","modified":"2025-12-14T01:11:11.946Z","6.0.0":"2021-07-14T02:48:55.939Z","6.1.0":"2021-07-14T04:57:06.700Z"},"bugs":{"url":"https://github.com/april9-digital-consulting/sqs-consumer/issues"},"license":"Apache-2.0","homepage":"https://github.com/april9-digital-consulting/sqs-consumer","keywords":["sqs","storageQueue","queue","consumer"],"repository":{"url":"git+https://github.com/april9-digital-consulting/sqs-consumer.git","type":"git"},"description":"Build SQS-based Node applications without the boilerplate","maintainers":[{"email":"thiagopxp@gmail.com","name":"thiagopxp"},{"email":"anderson.noguez+npm@april9.com.au","name":"a9-noguez"}],"readme":"# sqs-consumer\n\n[![NPM downloads](https://img.shields.io/npm/dm/sqs-consumer.svg?style=flat)](https://npmjs.org/package/sqs-consumer)\n[![Build Status](https://travis-ci.org/bbc/sqs-consumer.svg)](https://travis-ci.org/bbc/sqs-consumer)\n[![Code Climate](https://codeclimate.com/github/BBC/sqs-consumer/badges/gpa.svg)](https://codeclimate.com/github/BBC/sqs-consumer)\n[![Test Coverage](https://codeclimate.com/github/BBC/sqs-consumer/badges/coverage.svg)](https://codeclimate.com/github/BBC/sqs-consumer)\n\nBuild SQS-based applications without the boilerplate. Just define an async function that handles the SQS message processing.\n\n## Installation\n\n```bash\nnpm install sqs-consumer --save\n```\n\n## Usage\n\n```js\nconst { Consumer, AwsQueueProvider } = require('sqs-consumer');\nconst provider = new AwsQueueProvider('https://sqs.eu-west-1.amazonaws.com/account-id/queue-name');\nconst app = Consumer.create(provider, {\n  handleMessage: async (message) => {\n    // do some work with `message`\n  }\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.start();\n```\n\n- The queue is polled continuously for messages using [long polling](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html).\n- Messages are deleted from the queue once the handler function has completed successfully.\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.\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).\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`.\n\n```js\nconst { Consumer, AwsQueueProvider } = require('sqs-consumer');\nconst AWS = require('aws-sdk');\nconst sqs = new AWS.SQS({\n  httpOptions: {\n    agent: new https.Agent({\n      keepAlive: true\n    })\n  }\n});\n\nconst provider = new AwsQueueProvider('https://sqs.eu-west-1.amazonaws.com/account-id/queue-name', { sqs });\nconst app = Consumer.create(provider, {\n  handleMessage: async (message) => {\n    // do some work with `message`\n  }\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.start();\n```\n\n### Credentials\n\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:\n\n```bash\nexport AWS_SECRET_ACCESS_KEY=...\nexport AWS_ACCESS_KEY_ID=...\n```\n\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:\n\n```js\nconst { Consumer } = require('sqs-consumer');\nconst AWS = require('aws-sdk');\n\nAWS.config.update({\n  region: 'eu-west-1',\n  accessKeyId: '...',\n  secretAccessKey: '...'\n});\n\nconst provider = new AwsQueueProvider('https://sqs.eu-west-1.amazonaws.com/account-id/queue-name', {\n  sqs: new AWS.SQS()\n});\nconst app = Consumer.create(provider, {\n  handleMessage: async (message) => {\n    // ...\n  }\n});\n\napp.on('error', (err) => {\n  console.error(err.message);\n});\n\napp.on('processing_error', (err) => {\n  console.error(err.message);\n});\n\napp.on('timeout_error', (err) => {\n  console.error(err.message);\n});\n\napp.start();\n```\n\n## API\n\n### `Consumer.create(provider, options)`\n\nCreates a new SQS consumer.\n\n#### Provider\n\n- Choose between AWS or Azure as queue provider by initialising `AwsQueueProvider` or `AzureQueueProvider`\n\n#### Options\n\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.\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`**.\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.\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.\n- `visibilityTimeout` - _Number_ - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.\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`.\n- `terminateVisibilityTimeout` - _Boolean_ - If true, sets the message visibility timeout to 0 after a `processing_error` (defaults to `false`).\n- `authenticationErrorTimeout` - _Number_ - The duration (in milliseconds) to wait before retrying after an authentication error (defaults to `10000`).\n- `pollingWaitTimeMs` - _Number_ - The duration (in milliseconds) to wait before repolling the queue (defaults to `10000`).\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\n- `receiveOptions` - _Object_ - Extra parameters to be passed in ReceiveMessage. For more information check [SQS](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html) or [StorageQueue](https://docs.microsoft.com/en-us/azure/storage/queues/storage-nodejs-how-to-use-queues?tabs=javascript#additional-options-for-dequeuing-messages) documentation.\n\n### `consumer.start()`\n\nStart polling the queue for messages.\n\n### `consumer.stop()`\n\nStop polling the queue for messages.\n\n### `consumer.isRunning`\n\nReturns the current polling state of the consumer: `true` if it is actively polling, `false` if it is not.\n\n### Events\n\nEach consumer is an [`EventEmitter`](http://nodejs.org/api/events.html) and emits the following events:\n\n| Event                | Params             | Description                                                                                                                   |\n| -------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- |\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 |\n| `processing_error`   | `err`, `message`   | Fired when an error occurs processing the message.                                                                            |\n| `timeout_error`      | `err`, `message`   | Fired when `handleMessageTimeout` is supplied as an option and if `handleMessage` times out.                                  |\n| `message_received`   | `message`          | Fired when a message is received.                                                                                             |\n| `message_processed`  | `message`          | Fired when a message is successfully processed and removed from the queue.                                                    |\n| `response_processed` | None               | Fired after one batch of items (up to `batchSize`) has been successfully processed.                                           |\n| `stopped`            | None               | Fired when the consumer finally stops its work.                                                                               |\n| `empty`              | None               | Fired when the queue is empty (All messages have been consumed).                                                              |\n\n### AWS IAM Permissions\n\nConsumer will receive and delete messages from the SQS queue. Ensure `sqs:ReceiveMessage` and `sqs:DeleteMessage` access is granted on the queue being consumed.\n\n### Contributing\n\nSee contributing [guidelines](https://github.com/bbc/sqs-consumer/blob/master/.github/CONTRIBUTING.md).\n","readmeFilename":"README.md"}