Fetching and Querying Aggregate
In order to fetch aggregates you may introduce interface repository:
// 1. nullable return type
public function findBy(string $orderId): ?Order;
// 2. non-nullable return type
public function getBy(string $orderId): Order;
Ecotone based on return type class will find corresponding repository, that can handle fetching given aggregate.
- 1.Nullable return type - In case return type is nullable, Ecotone will return null, if aggregate is not found.
- 2.Non-nullable return type - In case return type is non-nullable, it will throw
AggregateNotFoundExceptionif aggregate is not found.
The next benefit of the above solution is abstracting away persistence layer. If you will switch to In Memory repository implementations, everything will continue to work.
You may put query handler on your aggregate, to fetch the state.
public function getContent(): string
$result = $queryBus->sendWithRouting (
// this is how we tell Ecotone aggregate identifier to fetch
metadata: ["aggregate.id" => $twitterId]
Ecotone will resolve the aggregrate by
aggregate.idheader and call the method for you.
In case you would like to call aggregate to fetch the state or to make some calculations, Ecotone allows you to build
API via interface. This way you may skip using
QueryBusand work with your
own business interface.
public function getContent(#[AggregateIdentifier] string $twitId): string;