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:

  1. We will support finding a KitchenOrder by its OnlineOrderRef.

  2. We will support finding a Set<Pizza> by their associated KitchenOrderRef.

You can run com.mattstine.dddworkshop.pizzashop.suites.Lab5Suite to check your progress in this lab.

2. Instructions

  1. 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 a KitchenOrder by its OnlineOrderRef. You’ll need to update this index every time a KitchenOrder is added to the repository.

  2. Complete the implementation of InProcessEventSourcedPizzaRepository.findPizzasByKitchenOrderRef(). This one is slightly trickier. Basically, you need to create an index that allows you to find a Set<Pizza> by their associated KitchenOrderRef. You’ll need to update this index every time a Pizza is added to the repository.