Skip to content

Cloudflare Queues

Cloudflare Queues is a message queue. The integration provisions a queue and gives you an IQueueClient to send and pull messages from .NET (using the HTTP push producer and pull consumer).

builder.AddCloudflareEnvironment();
var jobs = builder.AddQueue("jobs").RunAsEmulator();
  • aspire run → with .RunAsEmulator(), an in-process in-memory queue backs it (with lease/visibility semantics). No credentials needed.
  • aspire deploy → the queue is provisioned in real Queues via the Cloudflare API.
builder.AddProject<Projects.Api>("api").WithReference(jobs);
builder.AddQueueClient("jobs");

This registers an IQueueClient bound to the queue. Send messages, then pull and acknowledge them:

// Producer
app.MapPost("/enqueue", async (string job, IQueueClient queue, CancellationToken ct) =>
{
await queue.SendAsync(job, ct);
return Results.Accepted();
});
// Consumer
app.MapPost("/process", async (IQueueClient queue, CancellationToken ct) =>
{
var messages = await queue.PullAsync(batchSize: 10, cancellationToken: ct);
foreach (var message in messages)
{
// ... handle message.Body ...
}
await queue.AckAsync(messages.Select(m => m.LeaseId), ct);
return Results.Ok(new { processed = messages.Count });
});

Pulled messages are leased (hidden from other pulls) until you AckAsync (remove) or RetryAsync (return to the queue) them, or the lease expires.

Provider Backend When
Local In-process in-memory queue aspire run with .RunAsEmulator()
Queues The Queues HTTP API (push + pull) Deployed
  • API token: needs Queues: Edit — see API Tokens. The client reuses the environment’s token by default; scope it with .WithAccessToken(parameter) if you prefer.
  • Local dev with .RunAsEmulator(): none.