Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queues wrangler dev example #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2022-09-queues/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
37 changes: 37 additions & 0 deletions 2022-09-queues/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Queues Blog Demo

This repo contains an early preview of Cloudflare Queues running in `wrangler dev` local mode.

In this example, the worker script accepts incoming HTTP requests via the `fetch()` handler, and places the request bodies onto a Queue.
The Queue batches messages (up to a configured time or size limit), and then invokes the script's `queue()` handler with the messages.
See `wrangler.toml` for the configuration.

In this example, the `queue()` handler simply logs the messages, and invokes a simulated `slowRunningTask()`.
The `slowRunningTask()` is hard-coded to fail 25% of the time, to illustrate the Queue's ability to redeliver messages upon failures.

## Getting Started

First install the dependencies via `npm`. This includes a custom version of a `wrangler` containing the Queues preview.

```bash
npm ci
```

## Running the local dev server

```bash
npx wrangler dev -l
```

## Sending requests

Send a single request to the server via curl:

```
curl localhost:8787 -d "hello"
```

Send requests with an incrementing counter once per second:
```
npm run simple_load
```
Loading