Projection

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class Projection

A projection: a processor whose OnEvent functions write a read model from committed events.

Each handler is compiled into its own subscription, named processor.function, where the processor is the class's Name or its simple name. A handler takes the committed stream with the state after it, and optionally the me.ahoo.wow.api.subscribe.SubscriptionContext:

@Projection
class CartSummaryProjection(private val repository: CartSummaries) {
@OnEvent
fun onEvent(event: StateEvent<CartState>, context: SubscriptionContext) {
repository.upsert(event.state, ifNewer = event.version)
}
}

A handler returns nothing, and may be suspend or return a Reactor Mono. It may do I/O; its writes are guarded by version, since a commit may be handled more than once. A failure parks the aggregate in the failure ledger. The processor's dependencies are its constructor's parameters.

A processor is of exactly one kind: Projection, Reactor or Saga.