Adding an event
Use the outbox when another module must react after the business row commits, including across a process restart.
- Call
outboxWriter.enqueue(tx, { tenantId, eventType, aggregateId, payload })inside the businessprisma.$transaction. - Add
@OnEvent('event.type')on a listener in a module thatWorkerModuleimports. - If a retry would double-apply, wrap the handler with
IdempotentEventHandlerService. - Do not
EventEmitter2.emitfrom order command for order side effects.
In-process emit is appropriate only when the listener is loaded in the same process and you accept loss on crash. shipment.status.changed is the current example. return.status.changed shows the failure mode: emit with no listener and no retry.
String event names are what the dispatcher emits. Payload classes under src/common/events are optional TypeScript types. They are not a separate bus.
Document the new eventType on Events in the same change.