Queues

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.

OperationHTTPgRPC
CreatePOST /v1/queues/{bucket}/{key}CreateQueue
GetGET /v1/queues/{bucket}/{key}GetQueue
Replace settingsPUT /v1/queues/{bucket}/{key}UpdateQueue
ListGET /v1/queues/{bucket}ListQueues
DeleteDELETE /v1/queues/{bucket}/{key}DeleteQueue
SendPOST /v1/queues/{bucket}/{key}/messagesSend

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
}
configobject
The queue's settings, every default filled in
dead_letter_rangestring
The id of the stream that keeps the queue's dead letters
rangesarray
The open ranges, each with its id and its dispatcher, the address of the node that delivers it. dispatcher is empty while no node does
dispatchersarray
The distinct nodes that deliver the queue. A worker holds a session with each
ring_versioninteger
Equal on two reads that name the same nodes. It orders nothing

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:

kindstringRequired
standard, or key_ordered to deliver each routing key's messages one at a time, in order. Fixed at creation
claimsstringDefaultmemory
Where claims live: memory, or persisted to keep them across a node's restart. Fixed at creation. See Delivery and claims
dedupstringDefaultmemory
How a repeated idempotent send is caught: memory, or durable. See Send
concurrencyintegerDefault0, no limit
Claims in progress across the queue. See Fairness
key_concurrencyintegerDefault0, no limit
Claims in progress per routing key. Always 1 on a key-ordered queue
retry.max_attemptsintegerDefault5
Deliveries before a message is dead-lettered
retry.min_backoff_msintegerDefault1000
The wait after the first failed attempt
retry.max_backoff_msintegerDefault60000
The longest wait. It is at least the minimum
retry.factornumberDefault2
How much the wait grows per attempt. A value above 0 and up to 1 keeps it constant
claim_ttl_msintegerDefault30000
How long a claim is held before its message is delivered again. At most 12 hours
message_ttl_msintegerDefault345600000, 4 days
How long a message is kept, settled or not. At most 14 days
dead_letter_ttl_msintegerDefault1209600000, 14 days
How long a dead letter is kept
initial_rangesintegerDefault1
The queue's ranges at creation. Create only: refused on an update, and never returned

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.

SettingAfter an update
kind, claimsCannot change. Naming another value is refused with 400
claim_ttl_msApplies to claims delivered afterwards. A claim already out keeps its deadline, and an extend with no TTL uses the TTL it was delivered with
retryApplies to the next failed attempt
concurrency, key_concurrencyCounted against claims already out. Lowered below them, the queue delivers nothing more until enough are settled
dedupApplies 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_msApply 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.

configobjectRequired
The settings. kind is required
creation_tokenstringDefaultNone
Makes a retried create safe: the same token returns 201 and the queue the first attempt made
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.

StatusWhenRetry
400No kind, an unknown word, or a setting out of boundsNo. Fix the request
404The bucket does not existAfter you create it
409A stream or a queue already holds the address. Nothing is writtenOnly 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
StatusWhenRetry
404No queue at the address. A plain stream's address counts as no queueNo

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:

400 Bad Request
{
  "error": "queue: demo/emails: a queue's kind is fixed at creation"
}
StatusWhenRetry
400Another kind or claims, an initial_ranges, or a setting out of boundsNo. Fix the request
404No queue at the addressNo
503Another update changed the queue at the same momentYes

List a bucket's queues

GET /v1/queues/{bucket}

gRPC: QueueService.ListQueues. Returns one page of a bucket's queues, in key order.

key_prefixstringDefaultNone
Only queues whose key starts with this
limitintegerDefault100
The most queues on the page, at most 100
afterstringDefaultNone
The next of the page before
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
StatusWhenRetry
404No queue ever existed at the addressNo

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

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

messagesarrayRequired
The messages: one batch, at most 1,000 messages and 1 MiB of bodies and headers, the queue's added headers included
messages[].bodystringDefaultEmpty
The body as text. Send this or body_b64, as for a record
messages[].body_b64stringDefaultEmpty
The body as base64
messages[].headersarrayDefaultNone
Your own headers. A name starting nova- is refused
messages[].message_idstringDefaultOne Nova makes
Your id for the message
messages[].not_before_msintegerDefault0, at once
Unix milliseconds before which the message is not delivered. Refused on a key-ordered queue
messages[].ttl_msintegerDefaultThe queue's message_ttl_ms
How long after the send the message may still be delivered
routing_keystringDefaultNone
The key that picks the range, at most 1 MiB. Without one, the send lands on a range picked at random
idempotency_keystringDefaultNone
1 to 256 bytes. Makes the send idempotent: see below
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"
        }
      ]
    }
  ]
}'
201 Created
{
  "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 dedup is durable, the repeat is not stored. Its answer carries the first send's range, seq and id, and "deduplicated": true.
  • On a memory queue, 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"
    }
  ]
}'
201 Created, the second time
{
  "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.

StatusWhenRetry
400A 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 batchNo. Fix the request
400 with reason: delay_on_key_orderedA not_before_ms on a key-ordered queue. Nothing was sentNo. Send it without the delay
404No queue at the addressNo
413The body is past about 6.3 MiB, or one message's JSON past about 1.36 MiBNo. Send fewer messages, or the body as body_b64
503The node cannot reach the queue's rangeYes, 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:

HeaderHolds
nova-message-idThe message id
nova-attemptWhich attempt this copy is, in decimal
nova-routing-keyThe routing key
nova-not-beforenot_before_ms
nova-ttlttl_ms
nova-idempotency-keyThe key of an idempotent send
nova-sent-atOn 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.

GrantAllows
createCreate a queue, replace its settings
readGet a queue. Claim, ack, nack, extend. Open a work session
appendSend. Replay dead letters
trimPurge
deleteDelete a queue
listList 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.

On this page