Code
Github-messixukejia/grpc-wrapper:wrapper of Grpc
Key Data Structures
Process processing
Key flowchart
1, client start-up phase from ETCD to obtain all the server address, and watch server changes.
2, the service side changes, pushed to watch's client.
3, the service side starts the stage, will own address information put to ETCD.
Service side
1, establish client connection to ETCD: Etcd.new.
2. Create ETCD registrar: newetcdregisty for interaction with ETCD, such as registering a service address, etc.
3, establish GRPC server, and register the corresponding services.
4, start the server, and will own service information through Etcdregistry.register
To ETCD registration, in the listening client connection forced to handle the corresponding business.
Client
1, establish client connection to ETCD: Etcd.new.
2. Create Etcd Resolver:newetcdresolver for interaction with ETCD.
3, establish the load balancing strategy, and dial to the server.
3.1, Newccresolverwrapper->builder
. Build (Builder creates a resolver that'll be used to watch name resolution updates. Defaultscheme = "Passthrough" is used by default. )->passthroughresolver.start->newaddress-> go to 3.2
3.2, Resolverwrapper.start->ccresolverwrapper.watcher monitoring address change->handleresolvedaddrs/handleserviceconfig
3.3, first newccbalancerwrapper->balancerwrapperbuilder.build-> according to the established load Balancing strategy Start->resolve (Create Watcher) Goroutine Monitoring Address Change watchaddrupdates (next watch ETCD data change), update address write Addrch
3.4, Lbwatcher monitoring addrch-> effective to the client Newsubconn/removesubconn
4. Initiate data requests to the server.
Log
Client logs: Etcd Related: {"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:gotUpdate addr from Notify: [{127.0.0.1:2379 <nil>}]\n}} service side Related: 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"}