gRPC源碼/服務發現

來源:互聯網
上載者:User

代碼

GitHub - messixukejia/grpc-wrapper: wrapper of grpc

關鍵資料結構

流程處理

關鍵流程圖


1、用戶端開工階段從etcd擷取所有服務端地址,並watch服務端變更。
2、服務端變化,推送給watch的用戶端。
3、服務端開工階段,將自己的地址資訊put到etcd。

服務端

1、向ETCD建立用戶端串連:etcd.New。
2、建立ETCD註冊器:NewEtcdRegisty,用於與ETCD的互動,例如註冊服務地址等。
3、建立grpc server,並註冊相應的服務。
4、啟動server,並將自己服務資訊通過etcdRegistry.Register
向ETCD註冊,在監聽用戶端串連強求,處理相應業務。

用戶端

1、向ETCD建立用戶端串連:etcd.New。
2、建立ETCD resolver:NewEtcdResolver,用於與ETCD的互動。
3、建立負載平衡策略,並向服務端Dial。
3.1、newCCResolverWrapper->Builder
.Build(Builder creates a resolver that will be used to watch name resolution updates。預設使用defaultScheme = ”passthrough“。)->passthroughResolver.start->NewAddress->轉到3.2
3.2、resolverWrapper.start->ccResolverWrapper.watcher監控地址變化->handleResolvedAddrs/handleServiceConfig

3.3、首次newCCBalancerWrapper->balancerWrapperBuilder.Build->根據制定的負載平衡策略Start->Resolve(建立watcher)->起goroutine監控地址變化watchAddrUpdates(Next中watch etcd資料變化)-> update地址寫入addrCh
3.4、lbWatcher監控addrCh->生效到用戶端NewSubConn/RemoveSubConn

4、向服務端發起資料請求。

日誌

用戶端日誌:ETCD相關:{"level":"info","ts":1528723680.321994,"caller":"client/client.go:64","msg":"begin to create etcd"}{"level":"info","ts":1528723680.32224,"caller":"grpc/clientconn.go:494","msg":"parsed scheme: \"\""}{"level":"info","ts":1528723680.322293,"caller":"grpc/clientconn.go:500","msg":"scheme \"\" not registered, fallback to default scheme"}{"level":"info","ts":1528723680.3223171,"caller":"passthrough/passthrough.go:51","msg":"passthrough newaddress add 127.0.0.1:2379\n"}{"level":"info","ts":1528723680.322419,"caller":"client/client.go:70","msg":"end etcd"}{"level":"info","ts":1528723680.322929,"caller":"grpc/resolver_conn_wrapper.go:116","msg":"ccResolverWrapper: sending new addresses to cc: [{127.0.0.1:2379 0  <nil>}]"}{"level":"warn","ts":1528723680.323195,"caller":"grpc/balancer_v1_wrapper.go:269","msg":"Handle [{127.0.0.1:2379 0  <nil>}]. Err: <nil>"}{"level":"info","ts":1528723680.32329,"caller":"grpc/balancer_v1_wrapper.go:125","msg":"balancerWrapper: got update addr from Notify: [{127.0.0.1:2379 <nil>}]\n"}服務側相關:2018/06/11 21:28:00 Initializing logging reporter{"level":"info","ts":1528723680.324028,"caller":"client/client.go:85","msg":"begin to dial"}{"level":"info","ts":1528723680.324024,"caller":"grpc/balancer_v1_wrapper.go:125","msg":"balancerWrapper: got update addr from Notify: [{127.0.0.1:2379 <nil>}]\n"}{"level":"info","ts":1528723680.324088,"caller":"grpc/clientconn.go:494","msg":"parsed scheme: \"\""}{"level":"info","ts":1528723680.324113,"caller":"grpc/clientconn.go:500","msg":"scheme \"\" not registered, fallback to default scheme"}{"level":"info","ts":1528723680.324137,"caller":"passthrough/passthrough.go:51","msg":"passthrough newaddress add HelloServer\n"}{"level":"info","ts":1528723680.324235,"caller":"grpc/resolver_conn_wrapper.go:116","msg":"ccResolverWrapper: sending new addresses to cc: [{HelloServer 0  <nil>}]"}{"level":"warn","ts":1528723680.324367,"caller":"grpc/balancer_v1_wrapper.go:269","msg":"Handle [{HelloServer 0  <nil>}]. Err: <nil>"}{"level":"info","ts":1528723680.3257082,"caller":"plugins/etcd.go:136","msg":"etcd get upt is {0 127.0.0.1:1234 ...}\n"}{"level":"info","ts":1528723680.327142,"caller":"grpc/balancer_v1_wrapper.go:125","msg":"balancerWrapper: got update addr from Notify: [{127.0.0.1:1234 ...}]\n"}2018/06/11 21:28:00 Reporting span 72551c84db313989:72551c84db313989:0:1{"level":"info","ts":1528723680.431375,"caller":"client/client.go:106","msg":"Greeting: Hello defaultName"}
相關關鍵詞:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.