Consuming Events
In Domain-Driven Design (DDD) and event-driven architectures, consuming events is crucial for building reactive systems. After an event is consumed, you have two primary options for how to react:
- Projection: Store the information from the event to be read later, typically used to build a read model.
- Policy (or Command Policy): Use the event to trigger another command, enabling automation and complex workflows.
Adding a Consumed Event
To associate a consumed event with a Usecase, follow these steps:
-
Open Usecase Details Menu:
- Click on a Usecase on the map to access its details.
-
Open the Hamburger Menu:
- Click the Hamburger Menu icon (
) on the very left of the Usecase Details Menu.
This action will open an additional menu on the left side.
- Click the Hamburger Menu icon (
-
Select a Source Event:
- Choose a source event from the dropdown menu.
Usecases can consume events from other aggregates and bounded contexts, provided they are within the same business domain.
Defining the Projection Operation
For Projection usecases, specify how the event should update the Readmodel. Configure the following:
-
Projection Operation: Determines the action triggered by the event. Options include:
upsertOne
– Insert or update a single entry.updateOne
– Update a single entry.updateMany
– Update multiple entries.delete
– Remove entries.
-
Projection Condition: Defines the
WHERE
conditions in theUPDATE
statement. -
Value Sources: Specifies which attributes are updated by the event.
The updateMany
operation updates 0 to n entries, while updateOne
targets exactly one entry and throws an error if no entry is updated.
Removing a Consumed Event
To remove a consumed event, follow these steps:
-
Open Usecase Details Menu:
- Click on a Usecase on the map to access its details.
-
Open the Hamburger Menu:
- Click the Hamburger Menu icon (
) on the very left of the Usecase Details Menu.
This will open an additional menu on the left side.
- Click the Hamburger Menu icon (
-
Remove the Event:
- Click the small x on the chip of the consumed event you wish to remove.