Queue
A Queue is a durable message queue. Producers queue.publish(msg); consumers process via a Worker (or a Function trigger on AWS).
Quick example
import { Project, Queue, Worker } from '@sprintsail/sdk';
export const app = new Project('orders');
export const orders = new Queue(app, 'orders', { fifo: false });
export const process = new Worker(app, 'process-order', {
handler: './src/handlers/process.ts',
triggers: [orders],
});
Producer (publish from anywhere bound to the queue):
import { orders } from '../infra.js';
await orders.publish({ id: 'ord_123', amount: 4200 });
Consumer (the worker handler — AWS SQS event shape):
export default async function handler(event: { Records: Array<{ messageId: string; body: string }> }) {
const order = JSON.parse(event.Records[0].body);
// ...
}
Config
interface QueueConfig {
fifo?: boolean; // default false
}
Target mapping
| Target | Maps to | Notes |
|---|---|---|
aws | SQS | Standard or FIFO. Configurable visibility timeout + retention land in v1.1. |
sprintsail-runtime | RabbitMQ Cluster Operator RabbitmqCluster | One cluster per Queue primitive. The logical AMQP queue is declared lazily on first publish (default name default). Cluster ready in ~90s. |
Runtime methods
queue.publish<T>(message: T): Promise<void>;
The message is JSON-serialised. The receiving Worker sees it as body: string and parses it itself.
What sail migrate does
Nothing — queues are transient. In-flight messages aren't part of the migration contract. Drain the source queue before cutover (stop producers, wait for the source worker to drain).
Triggers
A Queue used as a Worker's triggers: [queue] becomes the worker's consume target. On AWS this is an SQS event source mapping. On the runtime it's the worker's runWorkerLoop AMQP consume().
Limits
- AWS: SQS standard message size cap 256 KB.
- Runtime: RabbitMQ default frame max 128 KB; configurable later.