Overview
A queue holds messages until a worker takes them. If the worker fails, the message comes back and is tried again, so nothing is lost.
When to use it
- Emails, image resizing or payments in the background.
- Smoothing out bursts.
- Handing work between services.
How it works
- NATS JetStream
- One broker per machine (NATS 2.15), its store on a volume, memory capped at 512 MiB.
- A user per queue
- Each queue has its own user and managed password.
A received message stays hidden for the visibility timeout; if it isn’t deleted by then, it comes back. After its last try it goes to the dead-letter queue, if you set one.
Architecture
- API to NATS JetStream: send
- NATS JetStream to Worker: receive
- NATS JetStream to Dead-letter queue: after max tries
Flows
A message’s life
- The API sends a message.
- A worker receives it; it is hidden for 30 seconds.
- The worker deletes it once done — or it comes back to be tried again.
Set it up
In the console
- Open Queues and choose New queue.
- Set the visibility timeout, tries and retention.
- Use the Messages tab to send and receive by hand.
With the CLI
enclave queue create emails --waitWith OpenTofu
OpenTofu configuration
resource "enclave_queue" "emails" {
name = "emails"
}Settings reference
Every setting and output of the OpenTofu resource; the console and the CLI use the same names in their own words. Generated from platform 4d30582.
| Name | Type | Use | What it does |
|---|---|---|---|
name | text | required | Name of the queue: 3–40 lowercase letters, digits or hyphens, starting with a letter. Changing it replaces the queue. |
dead_letter_queue | text | optional | Queue that takes messages past max_receives. |
max_message_bytes | number | optional | Largest body, 1024–1048576 (default 262144). |
max_receives | number | optional | Receives before a message is dead-lettered, 0–1000 (default 0: no limit). |
project | text | optional | The project to create it in. Defaults to the provider's project (ENCLAVE_PROJECT, else default). Changing it replaces the resource. |
retention_hours | number | optional | How long a message is kept, 1–336 (default 96). |
visibility_timeout_seconds | number | optional | How long a received message stays hidden, 1–43200 (default 30). |
broker_url | text | output | The broker on this machine, nats://127.0.0.1:<port>. |
id | text | output | Resource ID. |
internal_broker_url | text | output | The broker inside EnclaveStack's networks, nats://es-system-broker:4222. |
password_secret | text | output | Name of the managed secret holding the user's password. |
subject | text | output | The subject apps publish to. |
username | text | output | The broker user apps sign in as. |
Limits and security
Good to know
- Messages up to 1 MiB; kept 1 – 336 hours (96 by default).
Security
- Each queue has its own credentials.