You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`userver_add_grpc_library` will link `userver-grpc` transitively and will generate the usual `.pb.h + .pb.cc` files. For service definitions, it will additionally generate asynchronous interfaces `foo_client.usrv.pb.hpp` and `foo_service.usrv.pb.hpp`.
34
+
`userver_add_grpc_library` will link `userver::grpc` transitively and will generate the usual `.pb.h + .pb.cc` files.
35
+
For service definitions, it will additionally generate asynchronous interfaces `foo_client.usrv.pb.hpp` and
36
+
`foo_service.usrv.pb.hpp`.
35
37
36
-
To create gRPC clients in your microservice, register the provided ugrpc::client::ClientFactoryComponent and add the corresponding component section to the static config.
38
+
To create gRPC clients in your microservice, register the provided @ref ugrpc::client::ClientFactoryComponent and add
39
+
the corresponding component section to the static config.
40
+
41
+
To create gRPC services in your microservice, register the provided @ref ugrpc::server::ServerComponent and add the
42
+
corresponding component section to the static config.
43
+
44
+
See @ref scripts/docs/en/userver/tutorial/grpc_service.md for a tutorial.
37
45
38
-
To create gRPC services in your microservice, register the provided ugrpc::server::ServerComponent and add the corresponding component section to the static config.
39
46
40
47
## gRPC clients
41
48
42
49
### Client creation
43
50
44
-
In a component constructor, find ugrpc::client::ClientFactoryComponent and store a reference to its ugrpc::client::ClientFactory. Using it, you can create gRPC clients of code-generated `YourServiceClient` types.
51
+
In a component constructor, find @ref ugrpc::client::ClientFactoryComponent and store a reference to its
52
+
@ref ugrpc::client::ClientFactory. Using it, you can create gRPC clients of code-generated `YourServiceClient` types.
53
+
54
+
Client creation in an expensive operation! Either create them once at the server boot time or cache them. An automated
55
+
solution for client creation and caching is the @ref ugrpc::client::SimpleClientComponent. It also allows to
56
+
specify dynamic config for @ref ugrpc::client::ClientQos:
On errors, exceptions from userver/ugrpc/client/exceptions.hpp are thrown. It is recommended to catch them outside the entire stream interaction. You can catch exceptions for [specific gRPC error codes](https://grpc.github.io/grpc/core/md_doc_statuscodes.html) or all at once.
78
+
On errors, exceptions from @ref userver/ugrpc/client/exceptions.hpp are thrown. It is recommended to catch them outside
79
+
the entire stream interaction. You can catch exceptions for
80
+
[specific gRPC error codes](https://grpc.github.io/grpc/core/md_doc_statuscodes.html) or all at once.
65
81
66
82
### Working with metadata
67
83
68
-
gRPC metadata allows you to send additional information along with requests and responses. Metadata consists of key-value pairs that are transmitted as HTTP/2 headers.
84
+
gRPC metadata allows you to send additional information along with requests and responses. Metadata consists of
85
+
key-value pairs that are transmitted as HTTP/2 headers.
69
86
70
87
#### Client-side metadata handling
71
88
72
89
##### Sending request metadata
73
90
74
-
To send metadata with a request, use @ref ugrpc::client::CallOptions and its @ref ugrpc::client::CallOptions::AddMetadata method:
91
+
To send metadata with a request, use @ref ugrpc::client::CallOptions and its
3.`grpc-client-baggage` with component ugrpc::client::middlewares::baggage::Component - passes request baggage to subrequests.
156
-
3.`grpc-client-headers-propagator` with component ugrpc::client::middlewares::headers_propagator::Component - propagates headers.
157
-
4.`grpc-client-middleware-testsuite` with component ugrpc::client::middlewares::testsuite::Component - supports testsuite errors thrown from the mockserver.
171
+
1.`grpc-client-logging` with component ugrpc::client::middlewares::log::Component - logs requests and responses.
172
+
2.`grpc-client-deadline-propagation` with component ugrpc::client::middlewares::deadline_propagation::Component - activates
3.`grpc-client-baggage` with component ugrpc::client::middlewares::baggage::Component - passes request baggage to subrequests.
175
+
4.`grpc-client-headers-propagator` with component ugrpc::client::middlewares::headers_propagator::Component - propagates headers.
176
+
5.`grpc-client-middleware-testsuite` with component ugrpc::client::middlewares::testsuite::Component - supports testsuite errors thrown from the mockserver.
177
+
158
178
159
179
## gRPC services
160
180
161
181
### Service creation
162
182
163
-
A service implementation is a class derived from a code-generated `YourServiceBase` interface class. Each service method from the schema corresponds to a method of the interface class. If you don't override some of the methods, `UNIMPLEMENTED` error code will be reported for those.
183
+
A service implementation is a class derived from a code-generated `YourServiceBase` interface class. Each service
184
+
method from the schema corresponds to a method of the interface class. If you don't override some of the methods,
185
+
`UNIMPLEMENTED` error code will be reported for those.
164
186
165
187
To register your service:
166
-
* Create a component that derives from ugrpc::server::ServiceComponentBase
188
+
* Create a component that derives from @refugrpc::server::ServiceComponentBase
167
189
* Store your service implementation instance inside the component
168
-
* Call ugrpc::server::ServiceComponentBase::RegisterService in the component's constructor
190
+
* Call @refugrpc::server::ServiceComponentBase::RegisterService in the component's constructor
169
191
* Don't forget to register your service component.
170
192
171
193
### Service method handling
@@ -178,12 +200,14 @@ Each method receives:
178
200
When using a server stream, always call `Finish` or `FinishWithError`. Otherwise the client will receive `UNKNOWN` error, which signifies an internal server error.
179
201
180
202
Read the documentation on gRPC streams:
181
-
* Single request, single response ugrpc::server::UnaryCall
182
-
* Request stream, single response ugrpc::server::InputStream
183
-
* Single request, response stream ugrpc::server::OutputStream
On connection errors, exceptions from userver/ugrpc/server/exceptions.hpp are thrown. It is recommended not to catch them, leading to RPC interruption. You can catch exceptions for [specific gRPC error codes](https://grpc.github.io/grpc/core/md_doc_statuscodes.html) or all at once.
208
+
On connection errors, exceptions from userver/ugrpc/server/exceptions.hpp are thrown. It is recommended not to catch
209
+
them, leading to RPC interruption. You can catch exceptions for
210
+
[specific gRPC error codes](https://grpc.github.io/grpc/core/md_doc_statuscodes.html) or all at once.
187
211
188
212
### TLS / SSL
189
213
@@ -442,7 +466,7 @@ These are the metrics provided for each gRPC method:
0 commit comments