Disco v0.1.3 Disco.Orchestrator View Source
Orchestrates multiple Disco.Aggregate
together.
This module is a GenServer
implementation that can handle more than one aggregate in
the same place. A common problem, for example, arises when working with umbrella projects,
where a module can be used to run all the commands and queries without exposing internal
list of available aggregates.
Usage example
The usage is similar to Disco.Aggregate
, except that this is a GenServer
, so it needs
to be started before using it. In a real scenario, maybe you’ll want to put in under
some supervisor.
NOTE: Disco.Factories.ExampleAggregate
has been defined in test/support/examples/example_aggregate.ex
.
iex> {:ok, pid} = Disco.Orchestrator.start_link [Disco.Factories.ExampleAggregate]
iex> is_pid(pid)
true
iex> Disco.Orchestrator.commands()
[:do_something]
iex> Disco.Orchestrator.routes()
[:find_something]
iex> Disco.Orchestrator.dispatch(:do_something, %{foo: "bar"})
{:ok, %Disco.Factories.ExampleAggregate{foo: "bar", id: "4fd98a9e-8d6f-4e35-a8fc-aca5544596cb"}}
iex> Disco.Orchestrator.query(:find_something, %{foo: "bar"})
%{foo: "bar"}
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
Returns a list of available commands
Executes a command if available. It runs sync by default, use async: true
option to
run async
Returns a list of available queries
Executes a query on one of the available aggregates
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Returns a list of available commands.
Executes a command if available. It runs sync by default, use async: true
option to
run async.
Returns a list of available queries.
Executes a query on one of the available aggregates.