Packages
x3m_system
0.9.1
0.9.1
0.9.0
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
retired
0.7.20
0.7.19
0.7.18
0.7.17
0.7.16
0.7.15
0.7.14
0.7.13
0.7.12
0.7.11
0.7.10
0.7.9
0.7.8
retired
0.7.7
0.7.6
retired
0.7.5
0.7.4
retired
0.7.3
retired
0.7.2
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
retired
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.1.1
0.1.0
Building blocks for distributed and/or CQRS/ES systems
Current section
Files
Jump to
Current section
Files
lib/local_aggregates.ex
defmodule X3m.System.LocalAggregates do
@moduledoc """
Declares which aggregate modules run on the local node.
`use` it with the list of aggregate modules to host; it defines a supervisor that
starts an aggregate group per module:
defmodule MyApp.LocalAggregates do
use X3m.System.LocalAggregates, [MyApp.Accounts.Aggregate, MyApp.Orders.Aggregate]
end
Wire it into your supervision tree through `X3m.System.LocalAggregatesSupervision`.
See the "Aggregates & Event Sourcing" guide for the full setup.
"""
defmacro __using__(opts) do
quote do
@moduledoc false
use Supervisor
require Logger
def start_link(prefix),
do:
Supervisor.start_link(__MODULE__, prefix, name: X3m.System.LocalAggregates.name(prefix))
def init(prefix) do
children =
unquote(opts)
|> Enum.map(fn item -> aggregate_group(item, prefix) end)
Supervisor.init(children, strategy: :one_for_one)
end
defp aggregate_group(aggr_mod, prefix) do
name = X3m.System.AggregateGroup.name(aggr_mod)
%{
id: name,
start: {X3m.System.AggregateGroup, :start_link, [prefix, aggr_mod]}
}
end
end
end
def name(prefix),
do: Module.concat(prefix, LocalAggregates)
end