Lab 7 - TDD Policy - Subscribe to a Kitchen Domain Event from an Adjacent Aggregate and Update State
1. Summary
It is often useful to subscribe to events published by Aggregates in other Bounded Contexts. We saw an example of this in the Kitchen context.
Any time an OnlineOrderPaidEvent is published, a new KitchenOrder is added to the repository.
In this lab, we will create a similar collaboration between the Kitchen and Delivery contexts.
We will complete two stories:
-
We will build out the minimum implementation necessary to manage the creation of a
DeliveryOrder. -
We will subscribe to the
kitchen_orderstopic, and onKitchenOrderAssemblyFinishedEvent, we will create a matchingDeliveryOrder.
You can run com.mattstine.dddworkshop.pizzashop.suites.Lab7Suite to check your progress in this lab.
2. Instructions
-
Build out
DeliveryOrder. It needs to keep track of the following properties:-
Its
DeliveryOrderRef -
Its matching
KitchenOrderRefandOnlineOrderRef. -
A collection of
Pizzaobjects, copied from the Kitchen context. -
Its internal state. In this lab we will only implement one
Statevalue,READY_FOR_DELIVERY.
-
-
Add the appropriate value to the
DeliveryOrder.Stateenum. -
DeliveryOrderneeds both its@Builderand no-args constructors implemented. -
DeliveryOrderneeds the following methods implemented:-
identity() -
accumulatorFunction() -
getRef()- HINT: if you leverage Lombok, you can get this implementation for free. -
state() -
isReadyForDelivery()- HINT: you’ll want to base this on the internalStatevalue.
-
-
Implement the
applymethod inDeliveryOrder.Accumulator. -
Build out
DeliveryOrder.OrderState. -
Complete the implementation of
DeliveryOrderRef. It should be fairly obvious what’s missing here. -
Complete the implementation of
InProcessEventSourcedDeliveryOrderRepository.findByKitchenOrderRef(). You need to create an index that allows you to find aDeliveryOrderby itsKitchenOrderRef. You’ll need to update this index every time aDeliveryOrderis added to the repository.If you’re looking for hints, you can model your implementation after your solutions to Lab 5.
-
Finally, finish the implementation of
DeliveryService. It needs to subscribe to thekitchen_orderstopic, and onKitchenOrderAssemblyFinishedEvent, create a matchingDeliveryOrder.Then complete the implementation of
DeliveryService.findDeliveryOrderByKitchenOrderRef. This should be easy!