Claims

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.

OperationHTTPgRPC
ClaimPOST /v1/queues/{bucket}/{key}/claimsClaim
AckPOST /v1/queues/{bucket}/{key}/claims/ackAck
NackPOST /v1/queues/{bucket}/{key}/claims/nackNack
ExtendPOST /v1/queues/{bucket}/{key}/claims/extendExtend
Replay dead lettersPOST /v1/queues/{bucket}/{key}/dead-letters/replayReplayDeadLetters
PurgePOST /v1/queues/{bucket}/{key}/purgePurge
Work sessionNoneWorkSession

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}/claims

gRPC: QueueService.Claim. Takes up to max messages, waiting up to wait for the first, and returns them with 200.

maxintegerDefault1
The most messages to take. A value above 256 is treated as 256
waitdurationDefault0, answer with what is ready
How long to wait for the first message, such as 20s. A value above 30 s is treated as 30 s
claim_ttldurationDefaultThe queue's claim_ttl_ms
How long the claims are held. Above 12 h is refused
workerstringDefaultNone
Your worker's name, for the node's logs. At most 256 bytes
formatstringDefaultraw
raw or base64, as for a read
curl -s -X POST 'localhost:8080/v1/queues/demo/emails/claims?max=2&wait=5s'
200 OK
{
  "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
    }
  ]
}
claimstring
The token you settle the message with: base64 over HTTP, bytes over gRPC. Only the node that delivered it can read it
message_idstring
The message's id, the same on every attempt
body, body_b64, headers
The message, as you sent it. Absent headers means none
routing_keystring
The key it was sent under; absent if none
not_before_ms, ttl_msinteger
As sent; absent when not set
attemptinteger
1 on the first delivery, one more on each retry
deadline_msinteger
Unix milliseconds. After it, the message is delivered again unless you settle or extend the claim
max_deadline_msinteger
12 hours after the delivery. No extend moves the deadline past it
range, seq
Where this copy of the message is stored

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": []}.

SituationWhat happens
Which messagesThe 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 returnsWith max messages, when that node has no more after at least one, or when wait runs out
wait runs out mid-deliveryUp to 5 more seconds to collect what a node already started to deliver
No node delivers the queue yetWith 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 readyThe messages are delivered again at once, without spending an attempt
The caller disconnects while the answer is writtenNot noticed. The messages stay claimed until their deadline, then count as a failed attempt
The node or Gateway you reached freezesNothing 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.

StatusWhenRetry
400A wait or claim_ttl that is not a duration, a claim_ttl above 12 h, or an unknown formatNo. Fix the request
404No queue at the addressNo
429 with limit: max_claim_waitsThe node already holds 128 waiting claimsYes, after a pause, or at another node
503The nodes that deliver the queue could not be reachedYes

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/ack

gRPC: 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="
  ]
}'
200 OK
{
  "refused": []
}

The same ack sent again is refused, because the claim is no longer held:

200 OK
{
  "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/nack

gRPC: 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.

claimstringRequired
The claim
retry_after_msintegerDefaultThe queue's backoff for the attempt
How long until the message is delivered again. At most 14 days
terminalbooleanDefaultfalse
Give the message up now: it goes to the dead letters
unattemptedbooleanDefaultfalse
The message was never worked on: deliver it again at once without spending the attempt. Goes with neither field above
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.

StatusWhenRetry
400 with reason: claim_refused, refusal: malformedBytes that are not a claim, a retry_after_ms past 14 days, or unattempted with a wait or terminalNo. Fix the request
409 with reason: claim_refusedThe claim is no longer held; refusal says whyNo

Extend a claim

POST /v1/queues/{bucket}/{key}/claims/extend

gRPC: QueueService.Extend. Moves a claim's deadline to ttl_ms from now, earlier or later, and returns the new deadline.

claimstringRequired
The claim
ttl_msintegerDefaultThe TTL the claim was delivered with
The new deadline, from now. At most 12 hours, and never past max_deadline_ms
curl -s localhost:8080/v1/queues/demo/emails/claims/extend -d '{
  "claim": "AaIEdfG1fBmxnwOCTw1HuAAAAAAAAAAAAAAAAQAAAAAAAAABAAABogR3yZY=",
  "ttl_ms": 300000
}'
200 OK
{
  "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:

409 Conflict
{
  "error": "queue: the claim is not held: range 01a20475-f1b5-7c19-b19f-03824f0d47b8 position 0",
  "reason": "claim_refused",
  "refusal": "not_held"
}
StatusWhenRetry
400 with reason: claim_refused, refusal: malformedBytes that are not a claim, or a ttl_ms past 12 hours or negativeNo. Fix the request
409 with reason: claim_refusedThe claim is no longer held, or refusal: past_max_deadline: the extend would pass the max deadline, and the claim keeps the deadline it hadNo

Refusals

A refused ack, nack, or extend names one of these:

refusalMeansCan the work run twice?
not_heldSettled already, or expired and delivered againYes, if it expired
seat_movedThe range moved to another node, which delivers the message againYes
claim_goneThe message was settled or purged, or, on a queue with persisted claims, the claim passed its deadline and was delivered againOnly if the deadline passed
past_max_deadlineAn extend would pass max_deadline_ms. The claim keeps its deadlineNo
malformedNot a claim, or a value out of bounds. Nothing was doneNo

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:

CallrefusalBecause
Ackclaim_goneThe new node took the claim over, or the claim failed and its message was retried
Nackseat_movedThe new node has recorded the claim, so the old node fails nothing
Nackclaim_goneThe 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/replay

gRPC: 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.

limitintegerDefault100
The most to replay, at most 1,000. A larger value is treated as 1,000
curl -s -X POST 'localhost:8080/v1/queues/demo/emails/dead-letters/replay?limit=100'
200 OK
{
  "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}/purge

gRPC: 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
200 OK
{
  "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.

On this page