Claims
The routes that claim a queue's messages, settle each claim, replay dead letters, and purge.
A claim is a message lent to one worker until a deadline. The worker
settles it: an ack says the work is done, a nack says the attempt
failed. These routes claim and settle one call at a time, over HTTP or gRPC,
as the methods of nova.v1.QueueService. A worker built on an SDK uses a
work session instead.
Delivery and claims
Deadlines, attempts, and when a message is delivered twice
Run a worker with an SDK
Workers and one-shot claims in Go and TypeScript
Retries and dead letters
Backoff, terminal nacks, and replays
Queue commands
Purge and replay from the nova CLI
| Operation | HTTP | gRPC |
|---|---|---|
| Claim | POST /v1/queues/{bucket}/{key}/claims | Claim |
| Ack | POST /v1/queues/{bucket}/{key}/claims/ack | Ack |
| Nack | POST /v1/queues/{bucket}/{key}/claims/nack | Nack |
| Extend | POST /v1/queues/{bucket}/{key}/claims/extend | Extend |
| Replay dead letters | POST /v1/queues/{bucket}/{key}/dead-letters/replay | ReplayDeadLetters |
| Purge | POST /v1/queues/{bucket}/{key}/purge | Purge |
| Work session | None | WorkSession |
Any node answers these routes for the whole queue, and so does the Gateway. A
claim is not tied to the connection that received it, so a worker can claim
through one connection and settle through another. The examples use the
quickstart cluster's Gateway at localhost:8080 and the
queue demo/emails from Queues.
Claim messages
POST /v1/queues/{bucket}/{key}/claimsgRPC: QueueService.Claim. Takes up to max messages, waiting up to wait
for the first, and returns them with 200.
curl -s -X POST 'localhost:8080/v1/queues/demo/emails/claims?max=2&wait=5s'{
"claims": [
{
"claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAAAAAAAAQAAAAAAAAABAAABogR3yZY=",
"message_id": "01a20475-f2a7-77b8-86fa-a90915aaf2c1",
"body": "welcome",
"routing_key": "user-42",
"attempt": 1,
"deadline_ms": 1795371288982,
"max_deadline_ms": 1795414368982,
"range": "01a20475-f1b5-7c19-b19f-03824f0d47b8",
"seq": 0
},
{
"claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAABAAAAAQAAAAAAAAABAAABogR3yZY=",
"message_id": "01a20475-f2a7-77c8-a0ea-6ce58a156a27",
"body": "receipt",
"headers": [
{
"name": "content-type",
"value": "text/plain"
}
],
"routing_key": "user-42",
"attempt": 1,
"deadline_ms": 1795371288982,
"max_deadline_ms": 1795414368982,
"range": "01a20475-f1b5-7c19-b19f-03824f0d47b8",
"seq": 1
}
]
}Call claim in a loop with a wait of 20 to 30 seconds, and settle each claim
before you take more. When nothing arrives within the wait, the answer is
{"claims": []}.
| Situation | What happens |
|---|---|
| Which messages | The node asked takes from one delivering node at a time, so one answer's messages all come from one node. Ordinary ranges come first; an isolated range's backlog only when no node has other work |
| When it returns | With max messages, when that node has no more after at least one, or when wait runs out |
wait runs out mid-delivery | Up to 5 more seconds to collect what a node already started to deliver |
| No node delivers the queue yet | With a wait, the request waits for the first node to start, checking every 250 ms. Without one, it fails with 503 |
| The caller has gone when the answer is ready | The messages are delivered again at once, without spending an attempt |
| The caller disconnects while the answer is written | Not noticed. The messages stay claimed until their deadline, then count as a failed attempt |
| The node or Gateway you reached freezes | Nothing ends the request from that side |
Always send a wait. A node starts reading a queue's range only when a
consumer first asks for it. So on a queue nobody has consumed since the node
started, a claim without a wait returns nothing. Set your HTTP client's
timeout above the wait plus 5 seconds, such as 40 seconds for a 30-second
wait.
| Status | When | Retry |
|---|---|---|
| 400 | A wait or claim_ttl that is not a duration, a claim_ttl above 12 h, or an unknown format | No. Fix the request |
| 404 | No queue at the address | No |
429 with limit: max_claim_waits | The node already holds 128 waiting claims | Yes, after a pause, or at another node |
| 503 | The nodes that deliver the queue could not be reached | Yes |
Over gRPC the request is ClaimRequest with max, wait_ms, claim_ttl_ms
and worker_id, and the answer is claims, a list of Delivery. A
Delivery carries the message as a Message beside the same claim fields.
Acknowledge claims
POST /v1/queues/{bucket}/{key}/claims/ackgRPC: QueueService.Ack. Marks messages done. One request can settle many
claims, and the answer lists those it refused.
curl -s localhost:8080/v1/queues/demo/emails/claims/ack -d '{
"claims": [
"AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAAAAAAAAQAAAAAAAAABAAABogR3yZY="
]
}'{
"refused": []
}The same ack sent again is refused, because the claim is no longer held:
{
"refused": [
{
"claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAAAAAAAAQAAAAAAAAABAAABogR3yZY=",
"refusal": "not_held",
"reason": "queue: the claim is not held: range 01a20475-f1b5-7c19-b19f-03824f0d47b8 position 0"
}
]
}An empty refused means every claim was settled. Each refused claim names its
refusal. The node asked passes each claim to the node that
delivered it, so you can ack through any node.
Fail a claim
POST /v1/queues/{bucket}/{key}/claims/nackgRPC: QueueService.Nack. Hands one message back as a failed attempt and
returns 204. The message is retried or dead-lettered
by the queue's retry policy.
curl -s localhost:8080/v1/queues/demo/emails/claims/nack -d '{
"claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAABAAAAAQAAAAAAAAABAAABogR3yZY=",
"terminal": true
}'An unattempted hand-back spends the attempt after all when the message keeps
coming back. Three hand-backs in a minute are free, and the fourth spends one.
After 15 minutes from the first, every hand-back spends one. The queue's
attempt limit then ends the loop.
| Status | When | Retry |
|---|---|---|
400 with reason: claim_refused, refusal: malformed | Bytes that are not a claim, a retry_after_ms past 14 days, or unattempted with a wait or terminal | No. Fix the request |
409 with reason: claim_refused | The claim is no longer held; refusal says why | No |
Extend a claim
POST /v1/queues/{bucket}/{key}/claims/extendgRPC: QueueService.Extend. Moves a claim's deadline to ttl_ms from now,
earlier or later, and returns the new deadline.
curl -s localhost:8080/v1/queues/demo/emails/claims/extend -d '{
"claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAAAAAAAAQAAAAAAAAABAAABogR3yZY=",
"ttl_ms": 300000
}'{
"deadline_ms": 1795371469084
}A worker that lets the deadline pass loses the claim, and Nova counts that as a failed attempt. Extend a claim for work that runs long. An extend of a claim already settled is refused:
{
"error": "queue: the claim is not held: range 01a20475-f1b5-7c19-b19f-03824f0d47b8 position 0",
"reason": "claim_refused",
"refusal": "not_held"
}| Status | When | Retry |
|---|---|---|
400 with reason: claim_refused, refusal: malformed | Bytes that are not a claim, or a ttl_ms past 12 hours or negative | No. Fix the request |
409 with reason: claim_refused | The claim is no longer held, or refusal: past_max_deadline: the extend would pass the max deadline, and the claim keeps the deadline it had | No |
Refusals
A refused ack, nack, or extend names one of these:
refusal | Means | Can the work run twice? |
|---|---|---|
not_held | Settled already, or expired and delivered again | Yes, if it expired |
seat_moved | The range moved to another node, which delivers the message again | Yes |
claim_gone | The message was settled or purged, or, on a queue with persisted claims, the claim passed its deadline and was delivered again | Only if the deadline passed |
past_max_deadline | An extend would pass max_deadline_ms. The claim keeps its deadline | No |
malformed | Not a claim, or a value out of bounds. Nothing was done | No |
Over gRPC, a refusal is FailedPrecondition with a WorkRefused detail
holding claim, reason and the refusal as WORK_REFUSAL_NOT_HELD and
so on; a malformed one is InvalidArgument with the same detail. An ack
returns its refusals in AckResponse.refused instead.
Refusals while a range moves
When a range moves to another node, the old node can take a moment to learn that it was replaced. On a queue with persisted claims, an ack or nack that reaches the old node in that time can be refused before the claim's deadline:
| Call | refusal | Because |
|---|---|---|
| Ack | claim_gone | The new node took the claim over, or the claim failed and its message was retried |
| Nack | seat_moved | The new node has recorded the claim, so the old node fails nothing |
| Nack | claim_gone | The claim was settled already, or it failed and its message was retried |
The ack lists the refusal in refused. The nack answers 409 with
reason: claim_refused. In each case the queue settles or delivers the
message without this worker, so do not send the call again. An ack that was
answered is kept, and the new node does not deliver that message again.
Replay dead letters
POST /v1/queues/{bucket}/{key}/dead-letters/replaygRPC: QueueService.ReplayDeadLetters. Sends the oldest dead letters to the
queue again, each as a first attempt whose age starts now, and removes them
from the dead letters.
curl -s -X POST 'localhost:8080/v1/queues/demo/emails/dead-letters/replay?limit=100'{
"replayed": 1,
"more": false
}more is true while dead letters remain. One replay of a queue runs at a
time: a second one sends nothing and fails with 503. A letter is sent before
it is removed, so a replay that fails part way may send a letter twice and
never loses one. Reading the dead letters themselves needs gRPC; see
Retries and dead letters.
Replaying needs the append grant. Today it can also need the admin grant:
when the dead letters are stored on another node than the one that delivers
the queue, the replay sends them, then fails with 403 and
admin verb requires the nova:admin marker. The letters it sent stay in the
dead letters, so a second run sends them again. Replay with an admin token on
such a queue.
Purge a queue
POST /v1/queues/{bucket}/{key}/purgegRPC: QueueService.Purge. Removes every message sent before the purge and not
yet settled, those waiting on a retry or a delay included, and returns how
many it removed. The queue, its settings, and its dead letters stay.
curl -s -X POST localhost:8080/v1/queues/demo/emails/purge{
"purged": 1
}A claim in flight is taken back, so settling it afterwards is refused with
claim_gone. A purge that cannot reach every range empties those it can and
fails with 503 and purged, the count it removed. Run it again: it converges,
and each call counts only what it removed. Over gRPC the same failure carries a
PurgeResponse detail, and PurgeRequest.ranges stays empty: a node fills it
only when it passes part of a purge to another node. Purging needs the trim
grant. Today it can also need the admin grant: when a range's messages are
stored on another node than the one that delivers them, the purge fails with
403 and admin verb requires the nova:admin marker.
Work sessions
A work session is a long-lived gRPC stream with one node: the worker grants credit, and the node delivers one message per credit. It is how the Go and TypeScript workers consume. It is gRPC only. The Gateway does not carry it, so over HTTP use the claim route above. Work sessions documents the protocol for writing a worker in another language. Statuses every route shares are on Errors.