Skip to main content

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:

  1. Open Usecase Details Menu:

    • Click on a Usecase on the map to access its details.
  2. Open the Hamburger Menu:

    • Click the Hamburger Menu icon (Hamburger icon) on the very left of the Usecase Details Menu.

    This action will open an additional menu on the left side.

  3. Select a Source Event:

    • Choose a source event from the dropdown menu.

    Codebricks Planner with opened Usecase Details with Usecase Management menu. Add Source Event is highlighted.

note

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 the UPDATE statement.

  • Value Sources: Specifies which attributes are updated by the event.

    Codebricks Planner with opened Usecase Details on a projection readmodel.

note

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:

  1. Open Usecase Details Menu:

    • Click on a Usecase on the map to access its details.
  2. Open the Hamburger Menu:

    • Click the Hamburger Menu icon (Hamburger icon) on the very left of the Usecase Details Menu.

    This will open an additional menu on the left side.

  3. Remove the Event:

    • Click the small x on the chip of the consumed event you wish to remove.

    Codebricks Planner with opened Usecase Details with Usecase Management menu. Remove Source Event is highlighted.