Skip to content
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
/src/content/release-notes/kv.yaml @elithrar @thomasgauvin @rts-rob @oxyjun @cloudflare/pcx-technical-writing
/src/content/partials/kv/ @elithrar @thomasgauvin @rts-rob @oxyjun @cloudflare/pcx-technical-writing
/src/content/docs/pub-sub/ @elithrar @dcpena @cloudflare/pcx-technical-writing
/src/content/docs/queues/ @elithrar @maheshwarip @harshil1712 @cloudflare/pcx-technical-writing
/src/content/docs/queues/ @elithrar @jonesphillip @harshil1712 @cloudflare/pcx-technical-writing
/src/content/release-notes/queues.yaml @elithrar @maheshwarip @cloudflare/pcx-technical-writing
/src/content/docs/r2/ @oxyjun @elithrar @jonesphillip @aninibread @harshil1712 @cloudflare/workers-docs @cloudflare/pcx-technical-writing
/src/content/release-notes/r2.yaml @oxyjun @elithrar @aninibread @cloudflare/workers-docs @cloudflare/pcx-technical-writing
Expand Down
165 changes: 0 additions & 165 deletions src/content/docs/queues/examples/publish-to-a-queue-over-http.mdx

This file was deleted.

40 changes: 40 additions & 0 deletions src/content/docs/queues/examples/publish-to-a-queue-via-http.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Publish to a Queue via HTTP
summary: Publish to a Queue directly via HTTP.
pcx_content_type: example
sidebar:
order: 31
head:
- tag: title
content: Queues - Publish Directly via HTTP
description: Publish to a Queue directly via HTTP and Workers.
---

The following example shows you how to publish messages to a Queue from any HTTP client, using a Cloudflare API token to authenticate.

This allows you to write to a Queue from any service or programming language that supports HTTP, including Go, Rust, Python or even a Bash script.

### Prerequisites

- A [queue created](/queues/get-started/#3-create-a-queue) via the [Cloudflare dashboard](https://dash.cloudflare.com) or the [wrangler CLI](/workers/wrangler/install-and-update/).
- A Cloudflare API token with the `Queues Edit` permission.


### 1. Send a test message

To make sure you successfully authenticate and write a message to your queue, use `curl` on the command line:

```sh
# Make sure to replace the placeholder with your shared secret
curl -XPOST -H "Authorization: Bearer <paste-your-api-token-here>" "https://api.cloudflare.com/client/v4/accounts/<paste-your-account-id-here>/queues/<paste-your-queue-id-here>/messages" --data '{ "body": { "greeting": "hello" } }'
```

```sh output
{"success":true}
```

This will issue a HTTP POST request, and if successful, return a HTTP 200 with a `success: true` response body.

- If you receive a HTTP 403, this is because your API token is invalid or does not have the `Queues Edit` permission.

For full documentation about the HTTP Push API, refer to the [Cloudflare API documentation](https://developers.cloudflare.com/api/resources/queues/subresources/messages/).
101 changes: 101 additions & 0 deletions src/content/docs/queues/examples/publish-to-a-queue-via-workers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Publish to a Queue via Workers
summary: Publish to a Queue directly from your Worker.
pcx_content_type: example
sidebar:
order: 30
head:
- tag: title
content: Queues - Publish Directly via a Worker
description: Publish to a Queue directly from your Worker.
---

import { WranglerConfig } from "~/components";

The following example shows you how to publish messages to a Queue from a Worker. The example uses a Worker that receives a JSON payload from the request body and writes it as-is to the Queue, but in a real application you might have more logic before you queue a message.

### Prerequisites

- A [queue created](/queues/get-started/#3-create-a-queue) via the [Cloudflare dashboard](https://dash.cloudflare.com) or the [wrangler CLI](/workers/wrangler/install-and-update/).
- A [configured **producer** binding](/queues/configuration/configure-queues/#producer-worker-configuration) in the Cloudflare dashboard or Wrangler file.

Configure your Wrangler file as follows:

<WranglerConfig>

```toml
name = "my-worker"

[[queues.producers]]
queue = "my-queue"
binding = "YOUR_QUEUE"

```

</WranglerConfig>

### 1. Create the Worker

The following Worker script:

1. Validates that the request body is valid JSON.
2. Publishes the payload to the queue.

```ts
interface Env {
YOUR_QUEUE: Queue;
}

export default {
async fetch(req, env): Promise<Response> {
// Validate the payload is JSON
// In a production application, we may more robustly validate the payload
// against a schema using a library like 'zod'
let messages;
try {
messages = await req.json();
} catch (e) {
// Return a HTTP 400 (Bad Request) if the payload isn't JSON
return Response.json({ err: "payload not valid JSON" }, { status: 400 });
}

// Publish to the Queue
try {
await env.YOUR_QUEUE.send(messages);
} catch (e: any) {
console.log(`failed to send to the queue: ${e}`);
// Return a HTTP 500 (Internal Error) if our publish operation fails
return Response.json({ error: e.message }, { status: 500 });
}

// Return a HTTP 200 if the send succeeded!
return Response.json({ success: true });
},
} satisfies ExportedHandler<Env>;
```

To deploy this Worker:

```sh
npx wrangler deploy
```

### 2. Send a test message

To make sure you successfully write a message to your queue, use `curl` on the command line:

```sh
# Make sure to replace the placeholder with your shared secret
curl -XPOST "https://YOUR_WORKER.YOUR_ACCOUNT.workers.dev" --data '{"messages": [{"msg":"hello world"}]}'
```

```sh output
{"success":true}
```

This will issue a HTTP POST request, and if successful, return a HTTP 200 with a `success: true` response body.

- If you receive a HTTP 400, this is because you attempted to send malformed JSON to your queue.
- If you receive a HTTP 500, this is because the message was not written to your Queue successfully.

You can use [`wrangler tail`](/workers/observability/logs/real-time-logs/) to debug the output of `console.log`.
6 changes: 6 additions & 0 deletions src/content/release-notes/queues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ productLink: "/queues/"
productArea: Developer platform
productAreaLink: /workers/platform/changelog/platform/
entries:
- publish_date: "2025-05-09"
title: HTTP Push for Queues
description: |-
You can now write messages to your Queues from any client that can speak HTTP, without having to use a Worker. This means all your Go, Rust, Python or Bash applications can now benefit from a globally distributed queueing system and no egress charges.

Reading from a Queue via an HTTP client is also possible. Refer to the [documentation on pull consumers](/queues/configuration/pull-consumers/) to learn how to setup a pull consumer, acknowledge / retry messages, and setup multiple consumers.
- publish_date: "2025-04-17"
title: Improved limits for pull consumers
description: |-
Expand Down
2 changes: 1 addition & 1 deletion src/util/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwaggerParser from "@apidevtools/swagger-parser";
import type { OpenAPI } from "openapi-types";

const COMMIT = "8eb3957331e18523cca24d1f4ef388197defb6bc";
const COMMIT = "884e422cd4cb0895b5b7e6cf7f0a0fd7f8b043b2";
let schema: OpenAPI.Document | undefined;

export const getSchema = async () => {
Expand Down