Cluster.Strategy.DynamicSrv (libcluster_dynamic_srv v1.1.0)

View Source

This implements a libcluster strategy that utilizes DNS SRV records in a generic way. The K8s SRV strategy is too prescriptive to use generically because of the way it formulates its SRV hostnames.

For this strategy to work the SRV records should be in the format of <node-name>.<service-domain-name>. This works with Consul by specifying the node-name as a label and the service-domain-name is service.consul by default.

You can read more about Consul's DNS SRV records here.

While this was implemented to work with Consul, it can be used with any DNS service that supports SRV records and tagging of the hostname.

Configuration

  • service (required) — the DNS SRV service name to query.
  • polling_interval (optional, default 5000) — how often to poll DNS, in milliseconds.
  • disconnect_on_deregister (optional, default true) — when true, nodes are disconnected as soon as they disappear from DNS. When false, a node that has left DNS but still has a live distribution connection is left connected; it will only be disconnected once the connection drops naturally. Setting this to false avoids spurious :global partition-prevention cascades during graceful shutdowns that use a deregistration delay.

Example Configuration:

config :libcluster,
  topologies: [
    dyn_srv: [
      strategy: Cluster.Strategy.DynamicSrv,
      config: [
        service: "my-service-name.service.consul",
        disconnect_on_deregister: false
      ]
    ]
  ]

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.