GitHub - messixukejia/grpc-wrapper: wrapper of grpcgit
一、客戶端開工階段從etcd獲取全部服務端地址,並watch服務端變動。
二、服務端變化,推送給watch的客戶端。
三、服務端開工階段,將本身的地址信息put到etcd。github
一、向ETCD創建客戶端鏈接:etcd.New。
二、建立ETCD註冊器:NewEtcdRegisty,用於與ETCD的交互,例如註冊服務地址等。
三、創建grpc server,並註冊相應的服務。
四、啓動server,並將本身服務信息經過etcdRegistry.Register
向ETCD註冊,在監聽客戶端鏈接強求,處理相應業務。數據結構
一、向ETCD創建客戶端鏈接:etcd.New。
二、建立ETCD resolver:NewEtcdResolver,用於與ETCD的交互。
三、創建負載均衡策略,並向服務端Dial。
3.一、newCCResolverWrapper->Builder
.Build(Builder creates a resolver that will be used to watch name resolution updates。默認使用defaultScheme = 」passthrough「。)->passthroughResolver.start->NewAddress->轉到3.2
3.二、resolverWrapper.start->ccResolverWrapper.watcher監控地址變化->handleResolvedAddrs/handleServiceConfigapp
3.三、首次newCCBalancerWrapper->balancerWrapperBuilder.Build->根據制定的負載均衡策略Start->Resolve(建立watcher)->起goroutine監控地址變化watchAddrUpdates(Next中watch etcd數據變化)-> update地址寫入addrCh
3.四、lbWatcher監控addrCh->生效到客戶端NewSubConn/RemoveSubConn負載均衡
四、向服務端發起數據請求。ui
客戶端日誌: 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"}