xref: /aosp_15_r20/external/grpc-grpc/examples/cpp/interceptors/README.md (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1*cc02d7e2SAndroid Build Coastguard Worker# gRPC C++ Interceptors Example
2*cc02d7e2SAndroid Build Coastguard Worker
3*cc02d7e2SAndroid Build Coastguard WorkerThe C++ Interceptors example shows how interceptors might be used with a simple key-value store. Note that the C++ Interception API is still experimental and subject to change.
4*cc02d7e2SAndroid Build Coastguard Worker
5*cc02d7e2SAndroid Build Coastguard Worker## Key Value Store
6*cc02d7e2SAndroid Build Coastguard Worker
7*cc02d7e2SAndroid Build Coastguard WorkerThe key-value store service is defined in [keyvaluestore.proto](https://github.com/grpc/grpc/blob/master/examples/protos/keyvaluestore.proto).It has a simple bidi streaming RPC where the request messages contain a key and the response messages contain a value.
8*cc02d7e2SAndroid Build Coastguard Worker
9*cc02d7e2SAndroid Build Coastguard WorkerThe example shows a very naive CachingInterceptor added on the client channel that caches the key-value pairs that it sees. If the client looks up a key present in the cache, the interceptor responds with its saved value and the server doesn't see the request for that key.
10*cc02d7e2SAndroid Build Coastguard Worker
11*cc02d7e2SAndroid Build Coastguard WorkerOn the server-side, a very simple logging interceptor is added that simply logs to stdout whenever a new RPC is received.
12*cc02d7e2SAndroid Build Coastguard Worker
13*cc02d7e2SAndroid Build Coastguard Worker## Running the example
14*cc02d7e2SAndroid Build Coastguard Worker
15*cc02d7e2SAndroid Build Coastguard WorkerTo run the server -
16*cc02d7e2SAndroid Build Coastguard Worker
17*cc02d7e2SAndroid Build Coastguard Worker```
18*cc02d7e2SAndroid Build Coastguard Worker$ tools/bazel run examples/cpp/interceptors:server
19*cc02d7e2SAndroid Build Coastguard Worker```
20*cc02d7e2SAndroid Build Coastguard Worker
21*cc02d7e2SAndroid Build Coastguard WorkerTo run the client (on a different terminal) -
22*cc02d7e2SAndroid Build Coastguard Worker
23*cc02d7e2SAndroid Build Coastguard Worker```
24*cc02d7e2SAndroid Build Coastguard Worker$ tools/bazel run examples/cpp/interceptors:client
25*cc02d7e2SAndroid Build Coastguard Worker```
26