Usage Chart
How strongly this package shapes the runtime
Package Flow
How this package moves through xtaskjs runtime phases
Before startup
Configure queue defaults, register transports, and decorate consumers while modules load so the queue runtime knows which producers and handlers to wire.
During CreateApplication()
The queues lifecycle publishes QueueService and named transport tokens into the container, discovers decorated consumers, and prepares them for lifecycle-ready startup.
During app.close()
Active consumers are stopped and connected transports are disconnected automatically so broker resources shut down with the application.
API Surface
Representative exports from the upstream package
Configuration and transports
- configureQueues
- registerQueueTransport
- registerInMemoryQueueTransport
- createRabbitMqTransport
- createMqttTransport
Decorators and injectors
- QueueHandler
- QueueSubscribe
- QueuePattern
- PublishToQueue
- InjectQueueService
- InjectQueueLifecycleManager
- InjectQueueTransport
Runtime service and lifecycle
- QueueService
- initializeQueueIntegration
- shutdownQueueIntegration
- getQueueServiceToken
- getQueueTransportToken
Usage
Typical adoption flow
1. Configure transports and defaults
Start with the built-in in-memory transport for local workflows, or register RabbitMQ or MQTT helpers when messages must cross process boundaries.
2. Decorate consumers and publishers
Use QueueHandler and QueuePattern for consumers, PublishToQueue for method-result events, and InjectQueueService when services need direct publish or producer APIs.
3. Inspect and control the queue runtime
Use QueueService to list groups and consumers, create producers with defaults, and start or stop queue processing for diagnostics or operations endpoints.
Example
Reference snippet
import { Service } from "@xtaskjs/core";
import {
InjectQueueService,
PublishToQueue,
QueueHandler,
QueueService,
configureQueues,
registerInMemoryQueueTransport,
} from "@xtaskjs/queues";
configureQueues({
defaultTransportName: "memory",
autoCreateDefaultInMemoryTransport: false,
});
registerInMemoryQueueTransport({
name: "memory",
kind: "in-memory",
});
@Service()
export class OrdersQueueService {
constructor(
@InjectQueueService()
private readonly queues: QueueService
) {}
async publishOrder(orderId: string) {
await this.queues.publish("orders.created", { orderId });
}
@PublishToQueue("orders.completed", { transportName: "memory" })
completeOrder(orderId: string) {
return { orderId, completedAt: new Date().toISOString() };
}
@QueueHandler("orders.created", { name: "orders.created", transportName: "memory" })
onOrderCreated(payload: { orderId: string }) {
console.log("received", payload.orderId);
}
}
Samples
Official samples to inspect next
Reference samples: 16-queues_memory_app and 17-queues_rabbitmq_app
Related
Packages commonly used with this one