Messaging & Events
PubSubService, domain events, @JobEvent, event dispatch, deduplication, job queues, and @JobDefinition executors.
Overview
- Domain Events — dispatched from services after writes, trigger job enqueuing and pub-sub publishing.
- PubSubService — real-time publish/subscribe for inter-process notification and GraphQL subscriptions.
- Job Queues — durable, at-least-once background job processing.
Defining Events
Events are @Serializable classes annotated with @JobEvent:
kotlin
| @JobEvent Parameter | Purpose |
|---|---|
jobs | Job classes to enqueue when dispatched |
pubsubChannel | Channel to publish to (empty = no publish) |
Dispatching Events
KSP generates a dispatch() extension. Both job enqueuing and pub-sub publishing are deferred until after the transaction commits.
kotlin
Event Deduplication
The deferredEvents {} scope deduplicates events by (eventClass, identityKey()):
kotlin
Job Executors
A job executor extends AbstractJobExecutor<T> and is annotated with @JobDefinition:
kotlin
Job payload
kotlin
Full Event Flow
The complete lifecycle:
Event flow