Composite router allows you to combine multiple router modules into a single router able to dispatch any registered command from an included child router.
One example usage is to define a router per context and then combine each context's router into a single top-level composite app router used for all command dispatching.
Example
Define a composite router module which imports the commands from each included router:
defmodule Bank.AppRouter do
use Decree.Commands.CompositeRouter
router(Bank.Accounts.Router)
router(Bank.MoneyTransfer.Router)
end One or more routers or composite routers can be included in a
Decree.Application since it is also a composite router:
defmodule BankApp do
use Decree.Application
router(Bank.AppRouter)
endYou can dispatch a command via the application which will then be routed to the associated child router:
command = %OpenAccount{
command_id: command_id,
account_number: account_number,
initial_balance: 1_000
}
:ok = BankApp.dispatch(command)Or via the composite router itself, specifying the application:
:ok = Bank.AppRouter.dispatch(command, application: BankApp)A composite router can include composite routers.
A decision's stream prefix may not overlap an aggregate's across the routers it includes:
see "Prefixes" in Decree.Commands.Router.decide/2.
Summary
Functions
Register a Decree.Commands.Router module within this composite router.
Functions
Register a Decree.Commands.Router module within this composite router.
Will allow the composite router to dispatch any commands registered by the included router module. Multiple routers can be registered.