File: README.md

package info (click to toggle)
grpc 1.51.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 76,144 kB
  • sloc: cpp: 361,866; python: 72,206; ansic: 37,778; objc: 12,434; ruby: 11,521; sh: 7,652; php: 7,615; makefile: 3,481; xml: 3,246; cs: 1,836; javascript: 1,614; java: 465; pascal: 227; awk: 132
file content (123 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
gRPC Hostname Example
=====================

The hostname example is a Hello World server whose response includes its
hostname. It also supports health and reflection services. This makes it a good
server to test infrastructure, like load balancing. This example depends on a
gRPC version of 1.28.1 or newer.

### Run the Server

1. Navigate to this directory:

```sh
cd grpc/examples/python/xds
```

2. Run the server

```sh
virtualenv venv -p python3
source venv/bin/activate
pip install -r requirements.txt
python server.py
```

### Run the Client

1. Set up xDS configuration.

After configuring your xDS server to track the gRPC server we just started,
create a bootstrap file as desribed in [gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md):

```
{
  xds_servers": [
    {
      "server_uri": <string containing URI of xds server>,
      "channel_creds": [
        {
          "type": <string containing channel cred type>,
          "config": <JSON object containing config for the type>
        }
      ]
    }
  ],
  "node": <JSON form of Node proto>
}
```

2. Point the `GRPC_XDS_BOOTSTRAP` environment variable at the bootstrap file:

```
export GRPC_XDS_BOOTSTRAP=/etc/xds-bootstrap.json
```

3. Run the client:

```
python client.py xds:///my-backend
```

### Verifying Configuration with a CLI Tool

Alternatively, `grpcurl` can be used to verify your server. If you don't have it,
install [`grpcurl`](https://github.com/fullstorydev/grpcurl/releases). This will allow
you to manually test the service.

Be sure to set up the bootstrap file and `GRPC_XDS_BOOTSTRAP` as in the previous
section.

1. Verify the server's application-layer service:

```sh
> grpcurl --plaintext -d '{"name": "you"}' localhost:50051
{
  "message": "Hello you from rbell.svl.corp.google.com!"
}
```

2. Verify that all services are available via reflection:

```sh
> grpcurl --plaintext localhost:50051 list
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter
```

3. Verify that all services are reporting healthy:

```sh
> grpcurl --plaintext -d '{"service": "helloworld.Greeter"}' localhost:50051
grpc.health.v1.Health/Check
{
  "status": "SERVING"
}

> grpcurl --plaintext -d '{"service": ""}' localhost:50051
grpc.health.v1.Health/Check
{
  "status": "SERVING"
}
```

### Running with Proxyless Security

#### Run the Server with Secure Credentials

Add the `--secure true` flag to the invocation outlined above.

```sh
python server.py --secure true
```

#### Run the Client with Secure Credentials

Add the `--secure true` flag to the invocation outlined above.

3. Run the client:

```
python client.py xds:///my-backend --secure true
```