Quickstart
Publish and consume your first typed event with Rabbit Relay
This guide walks you through publishing and consuming your first typed event using Rabbit Relay.
What you will build
A small publisher creates a typed event and a consumer handles it from RabbitMQ.
Install
npm install @bitspacerlabs/rabbit-relayDefine an event contract
export const SchedulerEvents = {
ScheduleTask: "scheduler.scheduleTask",
} as const;
export type ScheduleTaskData = {
id: string;
when: number;
};Publish and consume
import { RabbitMQBroker, event } from "@bitspacerlabs/rabbit-relay";
import { SchedulerEvents, type ScheduleTaskData } from "./events";
const broker = new RabbitMQBroker("scheduler_service");
const pub = await broker.exchange("scheduler_exchange", {
exchangeType: "topic",
publisherConfirms: true,
});
const scheduleTask = event(
SchedulerEvents.ScheduleTask,
"v1"
).of<ScheduleTaskData>();
await pub.produce(
scheduleTask({
id: "task-1",
when: Date.now() + 5000,
})
);
await broker.close();Next steps
Now that you have a basic publisher and consumer, explore:
- Typed Events — event factories, versioning, and schemas
- Error Handling — what happens when a handler throws
- Retry & DLQ — bounded retries and poison-pill handling
- Configuration — broker options and topology modes