OnEvent

@OnMessage(functionKind = FunctionKind.EVENT, defaultFunctionName = "onEvent")
annotation class OnEvent(val value: String)

Marks a function as a domain event handler.

Functions annotated with @OnEvent are invoked when domain events are published. They allow aggregates to react to events from the same or different aggregates, enabling complex business workflows and state synchronization.

Event handlers are used for:

  • Updating aggregate state based on events

  • Implementing event sourcing within aggregates

  • Cross-aggregate communication and coordination

  • Maintaining derived state and projections

Example usage:

@EventProcessor
class OrderEventProcessor {

@OnEvent
fun onOrderCreated(event: OrderCreated) {
// Update inventory
inventoryService.reserveItems(event.items)

// Send confirmation email
emailService.sendOrderConfirmation(event.customerId, event.orderId)
}

@OnEvent
fun onOrderShipped(event: OrderShipped) {
// Update shipping records
shippingService.recordShipment(event.orderId, event.trackingNumber)
}
}

Parameters

value

Array of aggregate names to listen for events from. If empty, listens to events from any aggregate. Used for filtering and routing.

See also

for command handlers

for domain event classes

for external event processors

Properties

Link copied to clipboard
val value: Array<out String>

Names of aggregates to listen for events from.