GRPC Source/Service Discovery

Source: Internet
Author: User
Tags passthrough etcd

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 &LT;NIL&GT}] "} {" 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"}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.