Note: You must use wrangler 1.19.3 or newer to deploy this project.
An edge message queue service that runs on Cloudflare Workers using Durable Objects and KV. It is implemented as a simple REST API.
This demo uses:
git clone https://github.com/ryan-mars/workers-queue-demo.git
- Install wrangler
cd workers-queue-demo
npm install
wrangler login
wrangler kv:namespace create QUEUES_KV
You should see something like:
🌀 Creating namespace with title "workers-queue-demo-QUEUES_KV"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{ binding = "QUEUES_KV", id = "baf085c23c..." }
- Add the KV config to
wrangler.toml
wrangler publish
will build, run tests, and deploy to Cloudflare
You should see something like:
✨ Build completed successfully!`
✨ Successfully published your script to
https://workers-queue-demo.you1234.workers.dev
Note the URL 👆🏻
Copy/paste the contents of schema.yaml
into Swagger Editor. Change the servers
key to match your deployed URL.
Have fun!
- REST API spec is in
schema.yaml
. - Worker code is in
src/
. The Durable ObjectQueue
class is insrc/queue.ts
, and the Worker script is insrc/index.ts
. - esbuild is configured to output a bundled ES Module to
dist/index.mjs
. - Unit tests in
src/index.spec.ts
, which will run as part ofwrangler build
. To run tests on their own usenpm test
.