Events

Defining Events

Events are immutable records of changes that have occurred in the application. They capture what happened and serve as the primary source of truth. They are produced by command handlers and consumed by event handlers to update the system's state or trigger other actions.

Example Event:
@TopicInfo("customer-events")
public interface CustomerEvent {

  class CustomerCreated implements CustomerEvent {
    @AggregateId
    private String customerId;
    private String firstName;
    private String lastName;
    // getters and setters
  }

}

Publishing Events

While events are usually published by command handlers, there are scenarios where you may need to publish events directly. This can be useful in situations where events need to be published without going through the usual command handling process. Eventify provides an Event Gateway for this purpose.

Event Handling

Event handlers process events to update read models or trigger side effects. They are typically used in projections or sagas.