Commanded supports running on a single node, or multiple nodes run as either a distributed Erlang cluster or as multiple single instance nodes.
Running your app using Commanded on a single node requires no configuration as local is the default setting.
To support deployment to a cluster of nodes you must use the Commanded Swarm registry library and Phoenix's distributed pub/sub and presence platform to allow process distribution and communication amongst all nodes in the cluster.
Add commanded_swarm_registry to your list of dependencies in mix.exs:
def deps do
[
{:commanded_swarm_registry, "~> 0.1"}
]
endFetch mix dependencies:
$ mix deps.getConfigure your application to use the Swarm registry:
# config/config.exs
config :my_app, MyApp.Application, registry: Commanded.Registration.SwarmRegistryThis uses the Swarm to distribute process amongst the available nodes in the cluster.
First, add it as a dependency to your project's mix.exs file:
defp deps do
[{:phoenix_pubsub, "~> 1.0"}]
endFetch mix deps and configure the pubsub settings for your application in the environment config file:
# `config/config.exs`
config :my_app, MyApp.Application,
pubsub: [
phoenix_pubsub: [
adapter: Phoenix.PubSub.PG2,
pool_size: 1
]
]The PG2 adapter is preferable for cluster deployment since it is provided by Erlang and requires no further dependencies.
Running multiple nodes, but choosing not to connect the nodes together to form a cluster, requires that you use the local registry and Phoenix's pub/sub library with its Redis adapter.
You must install and use Phoenix's pub/sub library, as described above.
Since the nodes aren't connected, you are required to use the Redis adapter as a way of communicating between the nodes. Therefore you will need to host a Redis instance for use by your app.
# config/config.exs
config :my_app, MyApp.Application,
registry: :local,
pubsub: [
phoenix_pubsub: [
adapter: Phoenix.PubSub.Redis,
host: "localhost",
port: 6379,
node_name: "localhost"
]
]