View Source gc_discover_dns_srv (gen_cluster v0.3.0)
Discovery method that takes a host name to query DNS SRV records for and
uses all the returned hosts as peers to connect or reconnect to. Whether
to use the hostname or IP for each hostname result is configured with
the option host_type
which takes hostname
or ip
as values. The default
is hostname
which keeps the result as is in the node name. When it
is ip
each returned hostname is passed to inet_res:getbyname/3
to get an IP.
Since this is a built-in discovery module it has an alias, dns
, which
can be used in place of the full module name, gc_discovery_dns_srv
. The
alias dns
covers both gc_discover_dns_ip
and gc_discover_dns_srv
.
This module (gc_discover_dns_srv
) is used when the option
record_type => srv
is given.
The name part of the node name to connect to is taken from the current node's name.
The following is an example relying on the alias, dns
:
{gen_cluster, [{discovery, {dns, #{record_type => srv,
domain => "k8s-erlang-cluster.k8s-erlang-cluster"}}}]}
This results in the SRV records for k8s-erlang-cluster.k8s-erlang-cluster
being queried for every gen_cluster
refresh interval and it tries to
establish connections to those not already connected to.
To use IPv6 addresses as the host part of each node name set both
host_type
to ip
and ipv6
to true
:
{gen_cluster, [{discovery, {dns, #{record_type => srv,
domain => "k8s-erlang-cluster.k8s-erlang-cluster",
host_type => ip,
ipv6 => true}}}]}
Summary
Types
Module options. Takes domain
, the domain to query for, an optional host_type
which
can be ip
or hostname
, the optional boolean ipv6
for whether to query for A
or
AAAA
record when host_type
is ip
and optional lookup_timeout
which is the time
each DNS query can take (defaults to 5000 milliseconds).
Types
-type options() :: #{domain := string(), host_type => gc_discover_dns:host_type(), ipv6 => boolean(), lookup_opts => [inet_res:res_option()]}.
Module options. Takes domain
, the domain to query for, an optional host_type
which
can be ip
or hostname
, the optional boolean ipv6
for whether to query for A
or
AAAA
record when host_type
is ip
and optional lookup_timeout
which is the time
each DNS query can take (defaults to 5000 milliseconds).
Functions
-spec init(options()) -> {ok, #state{node_name :: string(), srv :: gc_discover_dns:dns_name(), host_type :: gc_discover_dns:host_type(), ip_record_type :: gc_discover_dns:ip_record_type(), lookup_timeout :: erlang:timeout()}}.
-spec peers(#state{node_name :: string(), srv :: gc_discover_dns:dns_name(), host_type :: gc_discover_dns:host_type(), ip_record_type :: gc_discover_dns:ip_record_type(), lookup_timeout :: erlang:timeout()}) -> gen_cluster:peers().