Module: Couchbase::DNS
- Defined in:
- lib/couchbase/dns.rb
Class Method Summary collapse
-
.locate(name, bootstrap_protocol = :http) ⇒ Object
Locate bootstrap nodes from a DNS SRV record.
Class Method Details
.locate(name, bootstrap_protocol = :http) ⇒ Object
Note:
This is experimental interface. It might change in future (e.g. service identifiers)
Locate bootstrap nodes from a DNS SRV record.
The DNS SRV records need to be configured on a reachable DNS server. An example configuration could look like the following:
_cbmcd._tcp.example.com. 0 IN SRV 20 0 11210 node2.example.com.
_cbmcd._tcp.example.com. 0 IN SRV 10 0 11210 node1.example.com.
_cbmcd._tcp.example.com. 0 IN SRV 30 0 11210 node3.example.com.
_cbhttp._tcp.example.com. 0 IN SRV 20 0 8091 node2.example.com.
_cbhttp._tcp.example.com. 0 IN SRV 10 0 8091 node1.example.com.
_cbhttp._tcp.example.com. 0 IN SRV 30 0 8091 node3.example.com.
Now if “example.com” is passed in as the argument, the three nodes configured will be parsed and put in the returned URI list. Note that the priority is respected (in this example, node1 will be the first one in the list, followed by node2 and node3). As of now, weighting is not supported.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/couchbase/dns.rb', line 57 def locate(name, bootstrap_protocol = :http) service = case bootstrap_protocol when :http "_cbhttp" when :cccp "_cbmcd" else raise ArgumentError, "unknown bootstrap protocol: #{bootstrap_transports}" end hosts = [] Resolv::DNS.open do |dns| resources = dns.getresources("#{service}._tcp.#{name}", Resolv::DNS::Resource::IN::SRV) hosts = resources.sort_by(&:priority).map { |res| "#{res.target}:#{res.port}" } end hosts end |