Transports Overview
Transports handle message delivery between services.
Choosing a Transport​
| Transport | Best For | Features |
|---|---|---|
| RabbitMQ | General purpose | Topic routing, DLQ, clustering |
| Kafka | High throughput | Partitioning, replay, ordering |
| SQS | AWS native | FIFO queues, serverless |
| Azure Service Bus | Azure native | Sessions, scheduling |
| GCP Pub/Sub | GCP native | Global, serverless |
| Redis | Low latency | Streams, consumer groups |
| NATS | Cloud native | JetStream, lightweight |
| In-Memory | Testing | No external deps |
Transport Interface​
All transports implement:
interface Transport {
start(): Promise<void>;
stop(): Promise<void>;
subscribe<T>(options: TransportSubscribeOptions, handler: Handler<T>): Promise<void>;
publish<T>(message: T, options: TransportPublishOptions): Promise<void>;
}
Basic Usage​
import { createBus } from '@saga-bus/core';
import { RabbitMqTransport } from '@saga-bus/transport-rabbitmq';
const transport = new RabbitMqTransport({
url: 'amqp://localhost:5672',
});
const bus = createBus({
transport,
store,
sagas: [{ definition: orderSaga }],
});
await bus.start();
Configuration Patterns​
Environment-Based​
function createTransport() {
if (process.env.NODE_ENV === 'test') {
return new InMemoryTransport();
}
return new RabbitMqTransport({
url: process.env.RABBITMQ_URL!,
});
}