• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Sep-2020-

client/H08-Sep-2020-13886

server/H08-Sep-2020-5125

README.mdH A D08-Sep-20201.3 KiB4129

README.md

1# Name resolving
2
3This examples shows how `ClientConn` can pick different name resolvers.
4
5## What is a name resolver
6
7A name resolver can be seen as a `map[service-name][]backend-ip`. It takes a
8service name, and returns a list of IPs of the backends. A common used name
9resolver is DNS.
10
11In this example, a resolver is created to resolve `resolver.example.grpc.io` to
12`localhost:50051`.
13
14## Try it
15
16```
17go run server/main.go
18```
19
20```
21go run client/main.go
22```
23
24## Explanation
25
26The echo server is serving on ":50051". Two clients are created, one is dialing
27to `passthrough:///localhost:50051`, while the other is dialing to
28`example:///resolver.example.grpc.io`. Both of them can connect the server.
29
30Name resolver is picked based on the `scheme` in the target string. See
31https://github.com/grpc/grpc/blob/master/doc/naming.md for the target syntax.
32
33The first client picks the `passthrough` resolver, which takes the input, and
34use it as the backend addresses.
35
36The second is connecting to service name `resolver.example.grpc.io`. Without a
37proper name resolver, this would fail. In the example it picks the `example`
38resolver that we installed. The `example` resolver can handle
39`resolver.example.grpc.io` correctly by returning the backend address. So even
40though the backend IP is not set when ClientConn is created, the connection will
41be created to the correct backend.