Examples
Here are some complete examples to illustrate how to use Eventify in a real application.
Command Handlers
Command handlers are responsible for processing incoming commands and producing events. A command handler typically validates the command, applies business logic, and emits one or more events.
Event Handlers
Event handlers process events to update read models or trigger side effects. They are typically used in projections or sagas.
Event Sourcing Handlers
Event sourcing handlers are responsible for applying events to reconstruct the state of an aggregate. They ensure that the current state can always be derived from the event history.
Gateways
Command Gateway
The command gateway is used to send commands to the system. It abstracts the underlying messaging infrastructure and provides a simple API for sending commands.
Event Gateway
The event gateway is used to publish events directly. This can be useful in situations where events need to be published without going through the usual command handling process.
Metadata
Metadata provides additional information about commands and events, such as timestamps, user information, or correlation IDs. This can be useful for auditing and tracing purposes.
Advanced Usage
Snapshotting
Snapshotting allows you to take periodic snapshots of an aggregate's state, reducing the need to replay the entire event history. This can improve performance, especially for aggregates with a long history. Snapshots can be configured to be taken after a certain number of events.
Upcasting
Upcasting is a technique used to convert old versions of events to the current version. This is useful when the event schema evolves over time while maintaining compatibility with previously stored events.