Backbone Queues
FIFO message queues. A queue springs into existence the first time you push to it, no separate declaration required. Push from anywhere; process messages with a queue-triggered function:
drift.Backbone.Queue("orders").Push(map[string]any{"item": "widget", "qty": 3})A message body must be a JSON object. A bare string, number or array is rejected with 400 queue and body required. Queue names take alphanumerics plus ., _ and -, first character alphanumeric, up to 255 bytes. A push past the queue's depth answers 429.
The depth is the depth of the queue's block in the Driftfile; a queue whose block leaves it out, or that has no block, takes the slice's limits.queue_depth.
slice "shop" {
limits {
queue_depth = 500
}
}
backbone {
queue "orders" {
depth = 1000
}
queue "emails" {}
}Here orders holds 1000 messages and emails holds the slice's 500. A queue the file stops naming is removed with its messages, so the plan lists it as a removal and as a possible data loss, and drift apply asks about each.
drift backbone queue push orders '{"item":"widget","qty":3}'
drift backbone queue peek orders # look without removing
drift backbone queue pop orders # take the next message
drift backbone queue len orders
drift backbone queue drop orders # delete the queue and every message in itQueue-triggered functions
Declaring a function "QUEUE orders" in the Driftfile binds it to that queue; see Atomic triggers. A background poller pops the queue every 500 ms and invokes the function once per message.
The function receives the message's inner body object, not the {id, body, timestamp} envelope that queue peek and queue pop return. Read your own fields straight off the payload.
Retries and the dead-letter queue
An invocation that fails puts the message back with a _drift_retries counter. After three attempts the message moves to a queue named <queue>-dlq, created on the first dead letter. It is an ordinary queue, so inspect and drain it like any other:
drift backbone queue len orders-dlq
drift backbone queue peek orders-dlq
drift backbone queue pop orders-dlq