xref: /aosp_15_r20/external/grpc-grpc/examples/cpp/xds/README.md (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1*cc02d7e2SAndroid Build Coastguard Worker# gRPC C++ xDS Hello World Example
2*cc02d7e2SAndroid Build Coastguard Worker
3*cc02d7e2SAndroid Build Coastguard WorkerThis xDS example builds on the [Hello World Example](https://github.com/grpc/grpc/tree/master/examples/cpp/helloworld) and changes the gRPC client and server to accept configuration from an xDS control plane.
4*cc02d7e2SAndroid Build Coastguard Worker
5*cc02d7e2SAndroid Build Coastguard Worker## Configuration
6*cc02d7e2SAndroid Build Coastguard Worker
7*cc02d7e2SAndroid Build Coastguard WorkerThe client takes two command-line arguments -
8*cc02d7e2SAndroid Build Coastguard Worker* target - By default, the client tries to connect to the xDS "xds:///helloworld:50051" and gRPC would use xDS to resolve this target and connect to the server backend. This can be overriden to change the target.
9*cc02d7e2SAndroid Build Coastguard Worker* secure - Bool value, defaults to true. When this is set, [XdsCredentials](https://github.com/grpc/proposal/blob/master/A29-xds-tls-security.md) will be used with a fallback on `InsecureChannelCredentials`. If unset, `InsecureChannelCredentials` will be used.
10*cc02d7e2SAndroid Build Coastguard Worker
11*cc02d7e2SAndroid Build Coastguard WorkerThe server takes three command-line arguments -
12*cc02d7e2SAndroid Build Coastguard Worker* port - Port on which the Hello World service is run. Defaults to 50051.
13*cc02d7e2SAndroid Build Coastguard Worker* mantenance_port - If secure mode is used (see below), the [Admin](https://github.com/grpc/proposal/blob/master/A38-admin-interface-api.md) service is exposed on this port. If secure mode is not used, `maintenance_port` is unused, and the Admin service is just exposed on `port`. Defaults to 50052.
14*cc02d7e2SAndroid Build Coastguard Worker* secure - Bool value, defaults to true. When this is set, [XdsServerCredentials](https://github.com/grpc/proposal/blob/master/A29-xds-tls-security.md) will be used with a fallback on `InsecureServerCredentials`. If unset, `InsecureServerCredentials` will be used.
15*cc02d7e2SAndroid Build Coastguard Worker
16*cc02d7e2SAndroid Build Coastguard Worker## Running the example
17*cc02d7e2SAndroid Build Coastguard Worker
18*cc02d7e2SAndroid Build Coastguard WorkerCurrently, this example and some of the gRPC xDS libraries that it depends on only builds with bazel. CMake support will be introduced in the future.
19*cc02d7e2SAndroid Build Coastguard Worker
20*cc02d7e2SAndroid Build Coastguard WorkerTo use XDS, you should first deploy the XDS management server in your deployment environment and know its name. You need to set the `GRPC_XDS_BOOTSTRAP` environment variable to point to the gRPC XDS bootstrap file (see [gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md#xdsclient-and-bootstrap-file) for the bootstrap format). This is needed by both client and server.
21*cc02d7e2SAndroid Build Coastguard Worker
22*cc02d7e2SAndroid Build Coastguard WorkerPlease view [GCP instructions](https://cloud.google.com/traffic-director/docs/security-proxyless-setup) as an example.
23*cc02d7e2SAndroid Build Coastguard Worker
24*cc02d7e2SAndroid Build Coastguard WorkerTo run the server -
25*cc02d7e2SAndroid Build Coastguard Worker
26*cc02d7e2SAndroid Build Coastguard Worker```
27*cc02d7e2SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
28*cc02d7e2SAndroid Build Coastguard Worker$ tools/bazel run examples/cpp/xds:greeter_server
29*cc02d7e2SAndroid Build Coastguard Worker```
30*cc02d7e2SAndroid Build Coastguard Worker
31*cc02d7e2SAndroid Build Coastguard WorkerTo run the client -
32*cc02d7e2SAndroid Build Coastguard Worker
33*cc02d7e2SAndroid Build Coastguard Worker```
34*cc02d7e2SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
35*cc02d7e2SAndroid Build Coastguard Worker$ tools/bazel run examples/cpp/xds:greeter_client
36*cc02d7e2SAndroid Build Coastguard Worker```
37*cc02d7e2SAndroid Build Coastguard Worker
38