Supervisor that manages a Chronicle connection and all registered observers.
Chronicle.Client is the main entry point for the Chronicle Elixir client.
Start it in your application's supervision tree, providing a connection
string and the list of event types, migrations, reactors, reducers, read
models, discoverable webhooks, and discoverable event store subscriptions to
register.
Usage
In your Application.start/2:
def start(_type, _args) do
children = [
{Chronicle.Client,
connection_string: "chronicle://localhost:35000?disableTls=true",
event_store: "my-store",
event_types: [
MyApp.Events.AccountOpened,
MyApp.Events.FundsDeposited
],
migrations: [MyApp.Migrations.AccountOpenedV2Migration],
reactors: [MyApp.Reactors.NotificationReactor],
reducers: [MyApp.Reducers.AccountReducer],
read_models: [MyApp.ReadModels.Account],
webhooks: [MyApp.WebHooks.AccountEvents],
event_store_subscriptions: [
MyApp.EventStoreSubscriptions.DefaultAccountEvents
]}
]
Supervisor.start_link(children, strategy: :one_for_one)
endOr enable artifact auto-discovery from an OTP application:
{Chronicle.Client,
connection_string: "chronicle://localhost:35000?disableTls=true",
event_store: "my-store",
otp_app: :my_app}In that mode, Chronicle scans modules in :my_app and discovers artifacts
generated by Chronicle macros (use Chronicle.Events.EventType,
use Chronicle.Events.Migration, use Chronicle.Seeding.Seeder,
use Chronicle.Reactors.Reactor, use Chronicle.Reducers.Reducer, use Chronicle.ReadModels.ReadModel,
use Chronicle.WebHooks.Webhook, and
use Chronicle.EventStoreSubscriptions.Subscription).
By default, Chronicle also auto-discovers artifacts from loaded modules, so consumers can start with minimal configuration.
Read models that contain from/2, join/2, or removed_with/2 declarations
are automatically registered as server-side projections.
Multiple clients
You can start multiple clients with different names:
{Chronicle.Client,
name: :bank_chronicle,
connection_string: "chronicle://bank-server:35000",
event_store: "bank"}
{Chronicle.Client,
name: :crm_chronicle,
connection_string: "chronicle://crm-server:35000",
event_store: "crm"}Options
:name— registered name for this client. Defaults toChronicle.Client.:connection_string— a connection string binary orChronicle.Connections.ConnectionStringstruct. Defaults toConnectionString.default/0(localhost:35000).:event_store— the event store name. Defaults to"default".:namespace— the namespace within the event store. Defaults to"default".:discover— enable/disable artifact auto-discovery. Defaults totrue.:otp_app— optional OTP application to auto-discover Chronicle artifacts from. When omitted, discovery scans loaded modules. Discovered artifacts are merged with explicit:event_types,:migrations,:reactors,:reducers,:read_models,:webhooks, and:event_store_subscriptionsentries.:event_types— list of event type modules to register with the event store.:migrations— list of migration modules to register with the event store.:reactors— list of reactor modules to start (eachuse Chronicle.Reactors.Reactor).:reducers— list of reducer modules to start (eachuse Chronicle.Reducers.Reducer).:read_models— list of read model modules (eachuse Chronicle.ReadModels.ReadModel). Modules that containfrom/2declarations are registered as projections.:seeders— list of seeder modules (eachuse Chronicle.Seeding.Seeder). Seeders populate the event store with initial events during client startup.:webhooks— list of discoverable webhook modules (eachuse Chronicle.WebHooks.Webhook). These are registered on startup.:event_store_subscriptions— list of discoverable event store subscription modules (eachuse Chronicle.EventStoreSubscriptions.Subscription). These are registered on startup.
Convenience functions
Once started, use Chronicle.append/3 and Chronicle.read_model/3 for the
most common operations, or use the subsystem modules directly:
Chronicle.EventSequences.EventLog— append and query eventsChronicle.ReadModels— query read model instancesChronicle.Events.EventTypes— manage event type registrationsChronicle.Jobs— inspect and control Chronicle jobsChronicle.WebHooks— inspect and register webhooksChronicle.EventStoreSubscriptions— register cross-store subscriptions
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the stored configuration for the given client name.
Starts a Chronicle client supervisor linked to the current process.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns the stored configuration for the given client name.
Used internally by Chronicle.EventSequences.EventLog, Chronicle.ReadModels, etc.
@spec start_link(keyword()) :: Supervisor.on_start()
Starts a Chronicle client supervisor linked to the current process.