Skip to content

createBus

createBus is the single entry point for building a Bus. You pass it a BusOptions describing the transport, the queue name, and any optional collaborators (serializer, registry, logger, polling intervals, consume wrapper). It returns a fully wired Bus ready for registerMessage / handle calls and a final await bus.start().

import { createBus } from '@serviceconnect/core';
export function createBus(options: BusOptions): Bus;
import { createBus } from '@serviceconnect/core';
import { createRabbitMQTransport } from '@serviceconnect/rabbitmq';
const bus = createBus({
queue: { name: 'orders' },
transport: createRabbitMQTransport({ url: 'amqp://localhost' }),
})
.registerMessage<OrderPlaced>('OrderPlaced')
.handle<OrderPlaced>('OrderPlaced', async (msg) => {
console.log('received', msg.orderId);
});
await bus.start();