Skip to content

Commit e170ff6

Browse files
authored
fix grpc: migrate to new unary RPC API for clients (#3)
1 parent f4fdfa1 commit e170ff6

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

src/hello.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::string SayHelloTo(std::string_view name, UserType type) {
4646
return fmt::format("Hi again, {}!\n", name);
4747
}
4848

49-
UASSERT(false);
49+
UINVARIANT(false, "Invalid user type");
5050
}
5151

5252
void AppendHello(userver::components::ComponentList& component_list) {

src/hello_client.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,8 @@ std::string HelloClient::SayHello(std::string name) {
1010
handlers::api::HelloRequest request;
1111
request.set_name(std::move(name));
1212

13-
// Deadline must be set manually for each RPC
14-
auto context = std::make_unique<grpc::ClientContext>();
15-
context->set_deadline(
16-
userver::engine::Deadline::FromDuration(std::chrono::seconds{20}));
17-
18-
// Initiate the RPC. No actual actions have been taken thus far besides
19-
// preparing to send the request.
20-
auto stream = client_.SayHello(request, std::move(context));
21-
22-
// Complete the unary RPC by sending the request and receiving the response.
23-
// The client should call `Finish` (in case of single response) or `Read`
24-
// until `false` (in case of response stream), otherwise the RPC will be
25-
// cancelled.
26-
handlers::api::HelloResponse response = stream.Finish();
13+
// Perform RPC by sending the request and receiving the response.
14+
auto response = client_.SayHello(request);
2715

2816
return std::move(*response.mutable_text());
2917
}

0 commit comments

Comments
 (0)