Queues
The routes that create, read, replace, list, and delete queues, and send messages to them.
A queue holds messages that workers claim and settle one by one. These
routes manage queues and send messages; claiming and settling are on
Claims. Each route is also a method of the gRPC service
nova.v1.QueueService, defined in proto/nova/v1/queue.proto.
Queues
Messages, claims, and delivery
Manage queues with an SDK
Create, update, list, delete, and purge
Send messages with an SDK
Routing keys, idempotency, and delays
Queue commands
List, show, purge, and replay from the CLI
| Operation | HTTP | gRPC |
|---|---|---|
| Create | POST /v1/queues/{bucket}/{key} | CreateQueue |
| Get | GET /v1/queues/{bucket}/{key} | GetQueue |
| Replace settings | PUT /v1/queues/{bucket}/{key} | UpdateQueue |
| List | GET /v1/queues/{bucket} | ListQueues |
| Delete | DELETE /v1/queues/{bucket}/{key} | DeleteQueue |
| Send | POST /v1/queues/{bucket}/{key}/messages | Send |
A queue lives at a stream address: a bucket and a key, the key one
percent-encoded path segment. The examples use the
quickstart cluster's Gateway at localhost:8080, the
bucket demo, and the queue emails.
The queue object
{
"bucket": "demo",
"key": "emails",
"config": {
"kind": "standard",
"claims": "memory",
"dedup": "memory",
"concurrency": 0,
"key_concurrency": 0,
"retry": {
"max_attempts": 3,
"min_backoff_ms": 1000,
"max_backoff_ms": 60000,
"factor": 2
},
"claim_ttl_ms": 60000,
"message_ttl_ms": 345600000,
"dead_letter_ttl_ms": 1209600000
},
"dead_letter_range": "01a20475-f1b5-7c11-be83-3a9b287fd609",
"ranges": [
{
"id": "01a20475-f1b5-7c19-b19f-03824f0d47b8",
"dispatcher": "127.0.0.1:8301"
}
],
"dispatchers": [
"127.0.0.1:8301"
],
"ring_version": 17797662004759048621
}ring_version is a 64-bit number and can be larger than a JavaScript number
holds exactly; read it as a big integer or compare it as text.
Settings
QueueConfig over gRPC, the config object over HTTP:
A setting sent as 0, or left out, takes its default, each on its own. A
negative TTL, wait, or factor, a max_backoff_ms below min_backoff_ms, and
a message_ttl_ms past 14 days are refused with 400. A queue's messages are
stored in its bucket's default class.
Over gRPC the enums are QUEUE_KIND_STANDARD, QUEUE_KIND_KEY_ORDERED,
CLAIMS_MODE_MEMORY, CLAIMS_MODE_PERSISTED, DEDUP_POLICY_MEMORY and
DEDUP_POLICY_DURABLE. The SDKs use the same names in their own style, such
as ClaimTTL in Go and claimTtlMs in TypeScript; Go takes durations, and
HTTP and TypeScript take milliseconds.
When a change applies
The nodes that deliver a queue pick up a change within about 5 seconds, without restarting delivery.
| Setting | After an update |
|---|---|
kind, claims | Cannot change. Naming another value is refused with 400 |
claim_ttl_ms | Applies to claims delivered afterwards. A claim already out keeps its deadline, and an extend with no TTL uses the TTL it was delivered with |
retry | Applies to the next failed attempt |
concurrency, key_concurrency | Counted against claims already out. Lowered below them, the queue delivers nothing more until enough are settled |
dedup | Applies to the next idempotent message a node reads. A repeat whose original came in under the other policy may be delivered |
message_ttl_ms, dead_letter_ttl_ms | Apply to stored messages and dead letters by their age |
Create a queue
POST /v1/queues/{bucket}/{key}gRPC: QueueService.CreateQueue. Creates a queue at an address that holds
nothing yet, and returns it with 201.
curl -s -X POST localhost:8080/v1/queues/demo/emails -d '{
"config": {
"kind": "standard",
"retry": {
"max_attempts": 3
},
"claim_ttl_ms": 60000
}
}'The response is the queue object above, with every default filled in.
| Status | When | Retry |
|---|---|---|
| 400 | No kind, an unknown word, or a setting out of bounds | No. Fix the request |
| 404 | The bucket does not exist | After you create it |
| 409 | A stream or a queue already holds the address. Nothing is written | Only with the first attempt's creation_token |
Get a queue
GET /v1/queues/{bucket}/{key}gRPC: QueueService.GetQueue. Returns the queue object.
curl -s localhost:8080/v1/queues/demo/emails| Status | When | Retry |
|---|---|---|
| 404 | No queue at the address. A plain stream's address counts as no queue | No |
Replace a queue's settings
PUT /v1/queues/{bucket}/{key}gRPC: QueueService.UpdateQueue. Replaces every setting and returns the queue
as it now stands. The body is {"config": {…}}. A setting you leave out takes
its default again, except kind, claims, and dedup, which keep the
queue's own. Here the queue keeps 3 attempts only because the request repeats
them:
curl -s -X PUT localhost:8080/v1/queues/demo/emails -d '{
"config": {
"retry": {
"max_attempts": 3
},
"claim_ttl_ms": 120000
}
}'The response is the queue object with claim_ttl_ms now 120000. Naming
another kind is refused:
{
"error": "queue: demo/emails: a queue's kind is fixed at creation"
}| Status | When | Retry |
|---|---|---|
| 400 | Another kind or claims, an initial_ranges, or a setting out of bounds | No. Fix the request |
| 404 | No queue at the address | No |
| 503 | Another update changed the queue at the same moment | Yes |
List a bucket's queues
GET /v1/queues/{bucket}gRPC: QueueService.ListQueues. Returns one page of a bucket's queues, in key
order.
curl -s 'localhost:8080/v1/queues/demo?limit=1'The response is {"queues": […], "next": "…"}, each entry a queue object.
Pass next as after for the following page; a response without next is
the last page. A listing needs the list grant on the bucket.
Delete a queue
DELETE /v1/queues/{bucket}/{key}gRPC: QueueService.DeleteQueue. Deletes the queue, its messages, and its
dead letters, and returns 204. A second delete also returns 204, so it is
safe to retry.
curl -s -X DELETE localhost:8080/v1/queues/demo/emails| Status | When | Retry |
|---|---|---|
| 404 | No queue ever existed at the address | No |
Nova reclaims the queue's storage later, in the background. Until then the queue still counts against its bucket, so a bucket delete right after it is refused.
Send messages
POST /v1/queues/{bucket}/{key}/messagesgRPC: QueueService.Send. Sends messages under one routing key and returns
201 with where each one landed. They land on one range together, in order,
or not at all.
curl -s localhost:8080/v1/queues/demo/emails/messages -d '{
"routing_key": "user-42",
"messages": [
{
"body": "welcome"
},
{
"body": "receipt",
"headers": [
{
"name": "content-type",
"value": "text/plain"
}
]
}
]
}'{
"range": "01a20475-f1b5-7c19-b19f-03824f0d47b8",
"sent": [
{
"message_id": "01a20475-f2a7-77b8-86fa-a90915aaf2c1",
"seq": 0
},
{
"message_id": "01a20475-f2a7-77c8-a0ea-6ce58a156a27",
"seq": 1
}
]
}range is the range every message landed on, and seq each message's place
in it.
The server does not retry a send, and a send that fails after the request
left may still have been stored. To make a
retry safe, send one message with an idempotency_key. Its id is derived from
the key, and a repeat within 5 minutes is delivered once:
- On a queue whose
dedupisdurable, the repeat is not stored. Its answer carries the first send's range,seqand id, and"deduplicated": true. - On a
memoryqueue, the repeat is stored and dropped before delivery. A repeat that arrives after the range moved to another node, or split, is delivered again.
curl -s localhost:8080/v1/queues/demo/receipts/messages -d '{
"routing_key": "user-42",
"idempotency_key": "order-7",
"messages": [
{
"body": "paid"
}
]
}'{
"range": "688e9fc2-9719-5584-80a9-b88b379d7ec8",
"sent": [
{
"message_id": "2b8eb85e-652d-5c5e-b0a6-fdecfdbb2409",
"seq": 0,
"deduplicated": true
}
]
}An idempotent send carries exactly one message, and leaves message_id
unset. Without a routing_key, the idempotency key picks the range.
| Status | When | Retry |
|---|---|---|
| 400 | A header starting nova-, a priority field, an idempotent send with more than one message, an idempotency_key past 256 bytes, a routing_key past 1 MiB, or a send past one batch | No. Fix the request |
400 with reason: delay_on_key_ordered | A not_before_ms on a key-ordered queue. Nothing was sent | No. Send it without the delay |
| 404 | No queue at the address | No |
| 413 | The body is past about 6.3 MiB, or one message's JSON past about 1.36 MiB | No. Send fewer messages, or the body as body_b64 |
| 503 | The node cannot reach the queue's range | Yes, with an idempotency_key |
A message is stored as a record, so the record limits
apply to each message and the batch limits to each send. The queue adds up to
six nova- headers of its own to each message. Keep a message to 64 headers
of yours: today a send with more fails over gRPC with Internal, and through
the Gateway with 500.
What a message carries
A read of the queue's address shows each message as a record, with these headers beside your own:
| Header | Holds |
|---|---|
nova-message-id | The message id |
nova-attempt | Which attempt this copy is, in decimal |
nova-routing-key | The routing key |
nova-not-before | not_before_ms |
nova-ttl | ttl_ms |
nova-idempotency-key | The key of an idempotent send |
nova-sent-at | On a retry or a delayed copy, the first send's time in Unix milliseconds. On a replayed dead letter, the replay's time |
Names starting nova- belong to the queue. A send that sets one is refused,
and a delivery leaves them out of the message's headers.
Grants
Queue routes use the stream grants on the queue's address. A token needs no queue-specific scope.
| Grant | Allows |
|---|---|
create | Create a queue, replace its settings |
read | Get a queue. Claim, ack, nack, extend. Open a work session |
append | Send. Replay dead letters |
trim | Purge |
delete | Delete a queue |
list | List a bucket's queues |
A sender needs only append, and a worker only read. A credential that can
claim can settle any claim of that queue. The node checks the grant first, so
a refused request gets the same answer from every node.
A queue's address refuses the stream routes that would break delivery:
trim, fence,
delete and
reconfigure answer 409 with
reason: queue_address. Use the queue's own routes instead. Statuses every
route shares are on Errors.