Lab 5 - TDD Policy - Subscribe to a Kitchen Domain Event from within an Aggregate and Create CQRS View
1. Summary
When using Event Sourcing, it’s really only possible to query an Aggregate by its primary key. Obviously we often want to execute different queries! We can subscribe to the events published by an Aggregate and create alternative indexes or data stores to support these queries.
In this lab, we’ll keep it simple and build out two alternative indexes. These will be used by the Application Service methods we implement in Lab 6.
We will complete two stories:
-
We will support finding a
KitchenOrderby itsOnlineOrderRef. -
We will support finding a
Set<Pizza>by their associatedKitchenOrderRef.
You can run com.mattstine.dddworkshop.pizzashop.suites.Lab5Suite to check your progress in this lab.
2. Instructions
-
Complete the implementation of
InProcessEventSourcedKitchenOrderRepository.findByOnlineOrderRef(). This one is a little bit tricky. Basically, you need to create an index that allows you to find aKitchenOrderby itsOnlineOrderRef. You’ll need to update this index every time aKitchenOrderis added to the repository. -
Complete the implementation of
InProcessEventSourcedPizzaRepository.findPizzasByKitchenOrderRef(). This one is slightly trickier. Basically, you need to create an index that allows you to find aSet<Pizza>by their associatedKitchenOrderRef. You’ll need to update this index every time aPizzais added to the repository.