Skip to main content

Adding an event

Use the outbox when another module must react after the business row commits, including across a process restart.

  1. Call outboxWriter.enqueue(tx, { tenantId, eventType, aggregateId, payload }) inside the business prisma.$transaction.
  2. Add @OnEvent('event.type') on a listener in a module that WorkerModule imports.
  3. If a retry would double-apply, wrap the handler with IdempotentEventHandlerService.
  4. Do not EventEmitter2.emit from 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.