Files
main.tsmain
What you'll learn
- Explain CQRS: commands change state and say little, queries read and change nothing, events announce what changed
- Dispatch through CommandBus and QueryBus, and handle with @CommandHandler and @QueryHandler classes registered as providers
- Model a change as an AggregateRoot that applies events, and publish them with EventPublisher.mergeObjectContext() and commit()
- React to events with @EventsHandler, and chain work with a @Saga that maps events to commands
Press Run tests to start the app. Its log appears here.Graded endpoints
{ cmd: 'find-one' } became a GetCatQuery, which GetCatHandler answered from the repository
The query handler's RpcException reaches the gateway as a 404
AdoptCatCommand's handler adopted the aggregate and returned it
commit() published CatAdoptedEvent: its handler wrote the notice, and the saga turned it into a ScheduleVetCheckCommand, whose handler booked the appointment
Tom already has an adopter: the handler refuses before touching the aggregate
The command handler finds no cat
A second aggregate, a second event
Refused commands published nothing; each adoption produced one notice and one appointment
The query sees the aggregate the command changed