Persistence Strategy
PHP Event Sourcing Persistence Strategy
Describes how streams with events will be stored.
The default persistence strategy is Single Stream Strategy.
This persistence stores all instances of specific aggregate, within same stream.
#[ServiceContext]
public function persistenceStrategy()
{
return \Ecotone\EventSourcing\EventSourcingConfiguration::createWithDefaults()
->withSingleStreamPersistenceStrategy();
}
namespace Domain\Ticket;
#[EventSourcingAggregate]
class Ticket
All instances of
Ticket
will be stored within Domain\Ticket\Ticket stream
. Read more about this strategy under
SingleStreamStrategy
:
http://docs.getprooph.org/event-store/implementations/pdo_event_store/variants.html#SingleStreamStrategyThis persistence creates stream per aggregate instance.
#[ServiceContext]
public function persistenceStrategy()
{
return \Ecotone\EventSourcing\EventSourcingConfiguration::createWithDefaults()
->withStreamPerAggregatePersistenceStrategy();
}
namespace Domain\Ticket;
#[EventSourcingAggregate]
class Ticket
Instances of
Ticket
will be stored within Domain\Ticket\Ticket-{ticketId} stream
where ticketId
is identifier of specific aggregate. Read more about this strategy under
AggregateStreamStrategy
:
http://docs.getprooph.org/event-store/implementations/pdo_event_store/variants.html#AggregateStreamStrategyYou may provide your own Customer Persistence Strategy as long as it implements
PersistenceStrategy
.#[ServiceContext]
public function aggregateStreamStrategy()
{
return EventSourcingConfiguration::createWithDefaults()
->withCustomPersistenceStrategy(new CustomStreamStrategy(new FromProophMessageToArrayConverter()));
}
If you want to make use of custom stream name (default is Aggregate class name), then you can apply
Stream
attribute to your aggregate.#[Stream("basket_stream")]
class Basket
Then tell the projection to make use of it:
#[Projection(self::PROJECTION_NAME, "basket_stream")]
class BasketList
By default events in the stream will hold Aggregate Class as
AggregateType
.
You may customize this by applying AggregateType
attribute to your Aggregate.#[AggregateType("basket")]
class Basket
Setting this up will allow you to refactor the aggregate class name or namespace and still load the same Aggregate.
Last modified 7mo ago