https://github.com/ntsd/cloudflare-queues-example
example of how to use Cloudflare Worker with Queue to handle async tasks
https://github.com/ntsd/cloudflare-queues-example
cloudflare cloudflare-queues cloudflare-workers
Last synced: 10 months ago
JSON representation
example of how to use Cloudflare Worker with Queue to handle async tasks
- Host: GitHub
- URL: https://github.com/ntsd/cloudflare-queues-example
- Owner: ntsd
- License: mit
- Created: 2024-04-08T12:44:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-12T22:45:31.000Z (over 1 year ago)
- Last Synced: 2025-01-23T19:47:53.205Z (12 months ago)
- Topics: cloudflare, cloudflare-queues, cloudflare-workers
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudflare Worker Queues Example
This is a basic example of how to use Cloudflare Worker with Queue to handle async tasks.
The example is pushing messages to a queue and the worker is consuming the messages and executing the task.
1. The producer will receive HTTP request to push the message to the queue
2. The consumer will consume the message and run the async task
Cloudflare Queue (Producer) -> Cloudflare Worker (Consumer) -> Async task
## Requirements
- Node
## Instructions
Follow the steps below to deploy the Cloudflare Worker Queue.
### 1. Install packages
`npm install`
### 2. Add Secret
To add or update your Queue Auth Secret to can run the command below, or you can use the Cloudflare Web UI
`npx wrangler secret put QUEUE_AUTH_SECRET`
### 3. Deploy worker
to deploy the worker, run the command below.
`npm run deploy`
If you found the queue not found error you need to create a queue name `my-queue` on your Cloudflare.
## Log worker
to log the worker, run the command below.
`npm run log`
## Send test message
```sh
POST / HTTP/1.1
Host: your-worker-name.your-username.workers.dev
Authorization: your_queue_auth_key
Content-Type: application/json
{
"data": "foo",
}
```