33{
34 std::cout << "=== gRPC Service Example ===" << std::endl;
35
36
37 std::cout << "\n1. gRPC Server configuration:" << std::endl;
39 config.max_concurrent_streams = 100;
41 config.keepalive_time = std::chrono::milliseconds(7200000);
42 config.keepalive_timeout = std::chrono::milliseconds(20000);
43
44 std::cout <<
" Max concurrent streams: " <<
config.max_concurrent_streams << std::endl;
45 std::cout <<
" Worker threads: " <<
config.num_threads << std::endl;
46 std::cout <<
" Keepalive: " <<
config.keepalive_time.count() <<
"ms" << std::endl;
47
48
49 std::cout << "\n2. Creating gRPC server:" << std::endl;
51
52 auto reg_result =
server.register_unary_method(
53 "/example.Greeter/SayHello",
56 {
57 std::cout <<
" [Handler] Received request (" << request.
data.size()
58 << " bytes)" << std::endl;
59
61 std::string body = "Hello from gRPC server!";
62 response.
data.assign(body.begin(), body.end());
63 return kcenon::common::ok(std::move(response));
64 });
65
66 if (reg_result.is_ok())
67 {
68 std::cout << " Method '/example.Greeter/SayHello' registered" << std::endl;
69 }
70 else
71 {
72 std::cout << " Method registration: " << reg_result.error().message << std::endl;
73 }
74
75
76 std::cout << "\n3. gRPC Client:" << std::endl;
77 std::cout << " Target: localhost:50051" << std::endl;
78 std::cout << " (Connection requires a running server)" << std::endl;
79
80
81 std::cout << "\n4. gRPC API overview:" << std::endl;
82 std::cout << " Server: register_unary_method(), start(port), stop()" << std::endl;
83 std::cout << " Client: connect(), call_raw(method, request, options)" << std::endl;
84 std::cout << " Message: grpc_message { data: vector<byte> }" << std::endl;
85
86 std::cout << "\nDone." << std::endl;
87 return 0;
88}
gRPC server for handling RPC requests
Context for handling a single RPC request.
@ server
Server-side handling of a request.
gRPC message with compression flag and payload
std::vector< uint8_t > data
Message payload.
Configuration for gRPC server.