QueueSubscription
Source:
src/Cloudflare/Queue/Subscription.ts
A Cloudflare Queues event subscription — delivers platform events (R2 bucket events, KV namespace events, Workers Builds, Workflows, etc.) into a Queue as messages.
The source selects which product emits the events and is fixed at
creation (changing it replaces the subscription). name, events,
enabled, and the destination queueId are all mutable in place.
Cloudflare allows at most one subscription per source per account.
Creating a Subscription
Section titled “Creating a Subscription”R2 bucket events into a Queue
const queue = yield* Cloudflare.Queue("EventsQueue");
const subscription = yield* Cloudflare.QueueSubscription("R2Events", { source: { type: "r2" }, events: ["bucket.created", "bucket.deleted"], queueId: queue.queueId,});KV namespace events with an explicit name
const subscription = yield* Cloudflare.QueueSubscription("KvEvents", { name: "kv-events", source: { type: "kv" }, events: ["namespace.created"], queueId: queue.queueId,});Workers Builds events for one Worker
const subscription = yield* Cloudflare.QueueSubscription("BuildEvents", { source: { type: "workersBuilds.worker", workerName: "my-worker" }, events: ["build.started", "build.completed"], queueId: queue.queueId,});Pausing delivery
Section titled “Pausing delivery”const subscription = yield* Cloudflare.QueueSubscription("R2Events", { source: { type: "r2" }, events: ["bucket.created"], queueId: queue.queueId, enabled: false,});