Projections with State
Last updated
Was this helpful?
Last updated
Was this helpful?
In order to optimize projections or to avoid using external storage, we may use of Projection's State
.
State is data that is kept between executions and can be passed to Projection's Event Handler.
In order to pass the state to Projection's Event Handlers we need to mark method parameter with #[ProjectionState]
.
Ecotone will resolve this parameter and pass the state. The returned state from the Event Handler will becomes new state for next execution. We may pass the state between all Event Handlers in given Projection.
The state can be simple array or a class. Whatever you pick, Ecotone will automatically serialize and deserialize it for you.
You may want to fetch the state from outside to return it to the end user.
In that case Ecotone brings ProjectionStateGateway
.
Gateways are automatically registered in your Dependency Container, so you can fetch it like any other service.
The first parameter of the attribute is the projection name, so Ecotone can know, which state it should look for. This will automatically convert the state to your defined return type.