ExESDB.Events (ex_esdb v0.11.0)
Event definitions and schemas for ExESDB subsystems.
This module provides centralized event type definitions and helper functions for building event payloads. Each module is responsible for publishing its own events using Phoenix.PubSub directly.
Event Categories
:system- System lifecycle and initialization events:cluster- Cluster membership and coordination events:leadership- Leadership changes and responsibilities:persistence- Data persistence and storage events:gateway- External interface and API events:coordination- General coordination events:subscriptions- Subscription management events
Usage
# Each module publishes its own events:
# In PersistenceWorker:
event = Events.build_event(:events_persisted, %{stream_id: "orders", event_count: 5})
Phoenix.PubSub.broadcast(ExESDB.PubSub, "exesdb:control:store_id:persistence",
{:persistence_event, event})
# In StoreCluster:
event = Events.build_event(:cluster_joined, %{via_node: target_node})
Phoenix.PubSub.broadcast(ExESDB.PubSub, "exesdb:control:store_id:cluster",
{:cluster_event, event})
Summary
Functions
Returns all event types organized by category
Builds a standard event map with common fields.
Helper to build event payload with standardized event wrapper.
Builds a topic string for a given store and category.
Returns all defined cluster events
Returns all defined coordination events
Returns all defined gateway events
Returns all defined leadership events
Returns all defined persistence events
Returns all defined subscription events
Returns all defined system events
Checks if an event type is valid for a given category
Validates that an event has all required fields
Functions
Returns all event types organized by category
Builds a standard event map with common fields.
Parameters
event_type- The event type (atom)data- Event-specific data (map)opts- Optional fields like:store_id(keyword list)
Examples
Events.build_event(:cluster_joined, %{via_node: node1})
Events.build_event(:events_persisted, %{stream_id: "orders", count: 5}, store_id: :my_store)
Helper to build event payload with standardized event wrapper.
Examples
Events.build_payload(:cluster_event, :cluster_joined, %{via_node: node1})
# => {:cluster_event, %{event_type: :cluster_joined, ...}}
Builds a topic string for a given store and category.
Examples
Events.build_topic(:my_store, :cluster)
# => "exesdb:control:my_store:cluster"
Returns all defined cluster events
Returns all defined coordination events
Returns all defined gateway events
Returns all defined leadership events
Returns all defined persistence events
Returns all defined subscription events
Returns all defined system events
Checks if an event type is valid for a given category
Validates that an event has all required fields