{"id":18376970,"url":"https://github.com/bbc/cloudflare-queue-consumer","last_synced_at":"2025-04-06T20:31:59.528Z","repository":{"id":229912430,"uuid":"777967871","full_name":"bbc/cloudflare-queue-consumer","owner":"bbc","description":"Build Cloudflare Queues based applications without the boilerplate (based on SQS Consumer)","archived":false,"fork":false,"pushed_at":"2024-04-14T00:30:15.000Z","size":149,"stargazers_count":17,"open_issues_count":6,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-22T05:10:35.549Z","etag":null,"topics":["cloudflare","cloudflare-queues","node"],"latest_commit_sha":null,"homepage":"https://bbc.github.io/cloudflare-queue-consumer/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-26T20:44:57.000Z","updated_at":"2024-04-29T08:53:43.791Z","dependencies_parsed_at":"2024-04-13T22:32:49.625Z","dependency_job_id":"7540a8f8-f372-48a9-8237-5a518ddd4421","html_url":"https://github.com/bbc/cloudflare-queue-consumer","commit_stats":null,"previous_names":["bbc/cloudflare-queue-consumer","bbc/cloudflare-queue-producer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fcloudflare-queue-consumer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fcloudflare-queue-consumer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fcloudflare-queue-consumer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fcloudflare-queue-consumer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbc","download_url":"https://codeload.github.com/bbc/cloudflare-queue-consumer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223263795,"owners_count":17115980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-queues","node"],"created_at":"2024-11-06T00:25:43.083Z","updated_at":"2024-11-06T00:25:43.632Z","avatar_url":"https://github.com/bbc.png","language":"TypeScript","readme":"# cloudflare-queue-consumer\n\n[![NPM downloads](https://img.shields.io/npm/dm/@bbc/cloudflare-queue-consumer.svg?style=flat)](https://npmjs.org/package/@bbc/cloudflare-queue-consumer)\n[![Build Status](https://github.com/bbc/cloudflare-queue-consumer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/bbc/cloudflare-queue-consumer/actions/workflows/test.yml)\n[![Maintainability](https://api.codeclimate.com/v1/badges/a0fcd77021e4f54ffdd4/maintainability)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/a0fcd77021e4f54ffdd4/test_coverage)](https://codeclimate.com/github/bbc/cloudflare-queue-consumer/test_coverage)\n\nBuild [Cloudflare Queues](https://developers.cloudflare.com/queues/) applications without the boilerplate. Just define an async function that handles the message processing.\n\nBased on [sqs-consumer](https://github.com/bbc/sqs-consumer).\n\n\u003e **Note:** This package is still in development and should be used with caution.\n\n## Installation\n\nTo install this package, simply enter the following command into your terminal (or the variant of whatever package manager you are using):\n\n```bash\nnpm install @bbc/cloudflare-queue-consumer\n```\n\n## Documentation\n\nVisit [https://bbc.github.io/cloudflare-queue-consumer/](https://bbc.github.io/cloudflare-queue-consumer/) for the full API documentation.\n\n## Usage\n\n```js\nimport { Consumer } from \"@bbc/cloudflare-queue-consumer\";\n\nconst consumer = new Consumer({\n  accountId: process.env.ACCOUNT_ID, // Your Cloudflare account ID\n  queueId: process.env.QUEUE_ID, // The Queue ID that you want to use.\n  handleMessage: async (message) =\u003e {\n    // Your message handling code...\n  },\n});\n\nconsumer.on(\"error\", (err) =\u003e {\n  console.error(err.message);\n});\n\nconsumer.on(\"processing_error\", (err) =\u003e {\n  console.error(err.message);\n});\n\nconsumer.start();\n```\n\nSome implementation notes:\n\n- [Pull consumers](https://developers.cloudflare.com/queues/reference/pull-consumers/) are designed to use a \"short polling\" approach, this means that the API from Cloudflare will respond immediately with any messages that are available, or an empty response if there are no messages available, this is different from SQS which will wait an amount of time before responding with an empty response.\n- `handleMessage` will send one message to the handler at a time, if you would prefer to receive multiple messages at once, use the `handleMessageBatch` method instead.\n  - It is important to await any processing that you are doing to ensure that the next action only happens after your processing has completed.\n  - By default, messages that are sent to the functions will be considered as processed if they return without an error.\n    - To acknowledge, you can return a promise that resolves the message or messages that you want to acknowledge.\n      - Returning an empty object or an empty array will be considered an acknowledgment of no message(s). If you would like to change this behaviour, you can set the `alwaysAcknowledge` option to `true`.\n      - By default, if an object or an array is not returned, all messages will be acknowledged.\n    - Any message that errors will not be retried until the end of the visibility timeout, if you would like to trigger an immediate retry, you can set the `retryMessagesOnError` option to `true`.\n      - You can set a delay for this retry with the `retryMessageDelay` option.\n\n### Credentials\n\nIn order to authenticate with the Cloudflare API, you will need to create an API token with read and write access to Cloudflare Queues, more information can be found [here](https://developers.cloudflare.com/queues/reference/pull-consumers/#create-api-tokens).\n\nCopy that token and set it as the value for an environment variable named `QUEUES_API_TOKEN`.\n\n### Example project\n\nYou'll also find an example project in the folder `./example`, set the variables `ACCOUNT_ID` and `QUEUE_ID` and then run this with the command `pnpm dev`.\n\n## API\n\n### `Consumer.create(options)`\n\nCreates a new SQS consumer using the [defined options](https://bbc.github.io/cloudflare-queue-consumer/interfaces/ConsumerOptions.html).\n\n### `consumer.start()`\n\nStart polling the queue for messages.\n\n### `consumer.stop(options)`\n\nStop polling the queue for messages. [You can find the options definition here](https://bbc.github.io/cloudflare-queue-consumer/interfaces/StopOptions.html).\n\nBy default, the value of `abort` is set to `false` which means pre existing requests to Cloudflare will still be made until they have concluded. If you would like to abort these requests instead, pass the abort value as `true`, like so:\n\n`consumer.stop({ abort: true })`\n\n### `consumer.status`\n\nReturns the current status of the consumer.\n\n- `isRunning` - `true` if the consumer has been started and not stopped, `false` if was not started or if it was stopped.\n- `isPolling` - `true` if the consumer is actively polling, `false` if it is not.\n\n### `consumer.updateOption(option, value)`\n\nUpdates the provided option with the provided value.\n\nPlease note that any update of the option `pollingWaitTimeMs` will take effect only on next polling cycle.\n\nYou can [find out more about this here](https://bbc.github.io/cloudflare-queue-consumer/classes/Consumer.html#updateOption).\n\n### Events\n\nEach consumer is an [`EventEmitter`](https://nodejs.org/api/events.html) and [emits these events](https://bbc.github.io/cloudflare-queue-consumer/interfaces/Events.html).\n\n## Contributing\n\nWe welcome and appreciate contributions for anyone who would like to take the time to fix a bug or implement a new feature.\n\nBut before you get started, [please read the contributing guidelines](https://github.com/bbc/cloudflare-queue-consumer/blob/main/.github/CONTRIBUTING.md) and [code of conduct](https://github.com/bbc/cloudflare-queue-consumer/blob/main/.github/CODE_OF_CONDUCT.md).\n\n## License\n\nCloudflare Queue Consumer is distributed under the Apache License, Version 2.0, see [LICENSE](https://github.com/bbc/cloudflare-queue-consumer/blob/main/LICENSE) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fcloudflare-queue-consumer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbc%2Fcloudflare-queue-consumer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fcloudflare-queue-consumer/lists"}