Skip to content

Latest commit

 

History

History
89 lines (63 loc) · 2.68 KB

Deployment.md

File metadata and controls

89 lines (63 loc) · 2.68 KB

Deployment

Commanded supports running on a single node, or multiple nodes run as either a distributed Erlang cluster or as multiple single instance nodes.

Single node deployment

Running your app using Commanded on a single node requires no configuration as local is the default setting.

Multi node cluster deployment

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.

Commanded Swarm registry

Add commanded_swarm_registry to your list of dependencies in mix.exs:

def deps do
  [
    {:commanded_swarm_registry, "~> 1.0.0"}
  ]
end

Fetch mix dependencies:

$ mix deps.get

Configure your application to use the Swarm registry:

# config/config.exs
config :my_app, MyApp.Application, registry: Commanded.Registration.SwarmRegistry

This uses the Swarm to distribute process amongst the available nodes in the cluster.

Phoenix pub/sub

First, add it as a dependency to your project's mix.exs file:

defp deps do
  [{:phoenix_pubsub, "~> 1.0"}]
end

Fetch 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.

EventStore

If using PostgreSQL-based Elixir EventStore please also refer to its documentation about running on a clustering of nodes.

Multi node, but not clustered deployment

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"
    ]
  ]