Chronicle.Client (chronicle v0.0.1)

Copy Markdown View Source

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, reactors, reducers, and read models 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
      ],
      reactors: [MyApp.Reactors.NotificationReactor],
      reducers: [MyApp.Reducers.AccountReducer],
      read_models: [MyApp.ReadModels.Account]}
  ]

  Supervisor.start_link(children, strategy: :one_for_one)
end

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 to Chronicle.Client.
  • :connection_string — a connection string binary or Chronicle.Connections.ConnectionString struct. Defaults to ConnectionString.default/0 (localhost:35000).
  • :event_store — the event store name. Defaults to "default".
  • :namespace — the namespace within the event store. Defaults to "default".
  • :event_types — list of event type modules to register with the event store.
  • :reactors — list of reactor modules to start (each use Chronicle.Reactor).
  • :reducers — list of reducer modules to start (each use Chronicle.Reducer).
  • :read_models — list of read model modules (each use Chronicle.ReadModel). Modules that contain from/2 declarations are registered as projections.

Convenience functions

Once started, use Chronicle.append/3 and Chronicle.read_model/3 for the most common operations, or use the subsystem modules directly:

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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

config(client \\ __MODULE__)

@spec config(atom() | pid()) :: map()

Returns the stored configuration for the given client name.

Used internally by Chronicle.EventLog, Chronicle.ReadModels, etc.

start_link(opts \\ [])

@spec start_link(keyword()) :: Supervisor.on_start()

Starts a Chronicle client supervisor linked to the current process.