gnat v0.3.3 Gnat.ConnectionSupervisor

A process that can supervise a named connection for you

If you would like to supervise a Gnat connection and have it automatically re-connect in case of failure you can use this module in your supervision tree. It takes a map with the following data:

gnat_supervisor_settings = %{
  name: :gnat, # (required) the registered named you want to give the Gnat connection
  backoff_period: 4_000, # number of milliseconds to wait between consecurity reconnect attempts (default: 2_000)
  connection_settings: [
    %{host: '10.0.0.100', port: 4222},
    %{host: '10.0.0.101', port: 4222},
  ]
}

The connection settings can specify all of the same values that you pass to Gnat.start_start_link/1. Each time a connection is attempted we will use one of the provided connection settings to open the connection. This is a simplistic way of load balancing your connections across a cluster of nats nodes and allowing failove to other nodes in the cluster if one goes down.

To use this in your supervision tree add an entry like this:

import Supervisor.Spec
worker(Gnat.ConnectionSupervisor, [gnat_supervisor_settings])

Now in the rest of your code you can call things like:

:ok = Gnat.pub(:gnat, "subject", "message")

And it will use your supervised connection. If the connection is down when you call that function (or dies during that function) it will raise an error.

Link to this section Summary

Link to this section Functions

Link to this function start_link(options)