我試圖實現consul服務發現,並且遇到兩件事情時遇到問題:連接到自定義DNS服務器,並格式化我的net.LookupSRV()
請求。如何在我的應用程序中讀取領事SRV記錄?
這裏是我想從我去的應用程序中查找:
$ dig @127.0.0.1 -p 8600 serviceb.service.consul SRV
; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> @127.0.0.1 -p 8600 serviceb.service.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4511
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;serviceb.service.consul. IN SRV
;; ANSWER SECTION:
serviceb.service.consul. 0 IN SRV 1 1 80 az1-serviceb1.node.dc1.consul.
serviceb.service.consul. 0 IN SRV 1 1 80 az2-serviceb2.node.dc1.consul.
;; ADDITIONAL SECTION:
az1-serviceb1.node.dc1.consul. 0 IN A 10.6.41.22
az2-serviceb2.node.dc1.consul. 0 IN A 10.6.41.20
;; Query time: 6 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Fri May 16 15:09:28 2014
;; MSG SIZE rcvd: 275
這裏是相關的代碼。 (我知道這是錯的,但只是讓你可以看到我想要做的)
cname, addrs, err := net.LookupSRV("serviceb", "service", "consul")
log.Printf("%+v %+v %+v", cname, addrs, err)
和輸出:
2014/05/16 15:24:31 [] lookup _serviceb._service.consul: no such host
任何幫助,將不勝感激!謝謝
這裏是我寫的一篇博客文章,概述了我想出的內容:http://txt.fliglio.com/2014/05/encapsulated-services-with-consul-and-confd/以及一個去庫的原型,我開始解決這個問題(使用從我接受的答案提議)https://github.com/benschw/consul-clb-go –