..
2024-10-13 19:01:02 +02:00
2024-10-13 19:01:02 +02:00
2024-10-13 19:01:02 +02:00
2024-11-10 00:30:25 +09:00
2024-11-20 11:41:31 +01:00

queues

An example of using Cloudflare Workers that interact with Cloudflare Queues.

Running

Requirements

This project requires these tools to be installed globally.

  • wrangler
  • tinygo

Supported commands

make dev     # run dev server
make build   # build Go Wasm binary
make deploy # deploy worker

Interacting with the local queue

NOTE: Wrangler does not support running multiple workers interacting with the same local queue. Therefore, for the demostrational purposes, we use the same worker to both produce and consume messages from the queue. For a real-world scenario, please consider the differences between queues.Consume and (queues.ConsumeNonBlock)(https://github.com/syumai/workers/blob/main/cloudflare/queues/consumer.go#L75) functions.

  1. Start the dev server.
make dev
  1. Send a message to the queue.
curl -v -X POST http://localhost:8787/ -d '{"message": "Hello, World!"}' -H "Content-Type: application/json"
  1. Observe the response and server logs

  2. You can pass text/plain content type to write queue message as the string or omit the Content-Type header to write queue message as byte array.