ProjectionProcessor
Marks a class as a projection processor for maintaining read models.
Projection processors transform domain events into optimized read models (projections) that are tailored for specific query and display requirements. They maintain denormalized views of the domain data for efficient querying.
Projection processors are responsible for:
Building and updating read models from domain events
Maintaining data consistency across projections
Handling event versioning and schema evolution
Optimizing data structures for query performance
Supporting eventual consistency patterns
Example usage:
@ProjectionProcessor
class OrderSummaryProjection {
@OnEvent
fun onOrderCreated(event: OrderCreated) {
val summary = OrderSummary(
orderId = event.orderId,
customerId = event.customerId,
totalAmount = event.totalAmount,
status = OrderStatus.CREATED,
createdAt = event.createdAt
)
orderSummaryRepository.save(summary)
}
@OnEvent
fun onOrderPaid(event: OrderPaid) {
val summary = orderSummaryRepository.findById(event.orderId)
summary?.let {
it.status = OrderStatus.PAID
it.paidAt = event.paidAt
orderSummaryRepository.save(it)
}
}
}Content copied to clipboard
See also
for general event processing
for event handler methods