commanded v0.12.0 Commanded.ProcessManagers.ProcessManager behaviour

Behaviour to define a process manager

Summary

Functions

Macro as a convenience for defining a process manager

Callbacks

Mutate the process manager’s state by applying the domain event

Process manager instance handles the domain event, returning commands to dispatch

Is the process manager interested in the given command?

Types

command()
command() :: struct
domain_event()
domain_event() :: struct
process_manager()
process_manager() :: struct
process_uuid()
process_uuid() :: String.t

Functions

__using__(opts) (macro)

Macro as a convenience for defining a process manager

defmodule ExampleProcessManager do

use Commanded.ProcessManagers.ProcessManager,
  name: "example_process_manager",
  router: BankRouter

def interested?(%AnEvent{...}) do
  # ...
end

def handle(%ExampleProcessManager{...}, %AnEvent{...}) do
  # ...
end

def apply(%ExampleProcessManager{...}, %AnEvent{...}) do
  # ...
end

end

# start process manager (or configure as a worker inside a supervisor) {:ok, process_manager} = ExampleProcessManager.start_link()

Callbacks

apply(process_manager, domain_event)

Mutate the process manager’s state by applying the domain event

handle(process_manager, domain_event)

Process manager instance handles the domain event, returning commands to dispatch

interested?(domain_event)
interested?(domain_event) ::
  {:start, process_uuid} |
  {:continue, process_uuid} |
  {:stop, process_uuid} |
  false

Is the process manager interested in the given command?