Adding Proto Reflection and Health Check to basic C++ example server

And ensuring the example can be built and ran via
bazel, make, and cmake.
pull/22233/head
Donna Dionne 5 years ago
parent 854ebff0c3
commit ca8ba90292
  1. 1
      examples/BUILD
  2. 4
      examples/cpp/helloworld/CMakeLists.txt
  3. 4
      examples/cpp/helloworld/greeter_server.cc

@ -114,6 +114,7 @@ cc_binary(
deps = [
":helloworld_cc_grpc",
"//:grpc++",
"//:grpc++_reflection",
],
)

@ -54,6 +54,7 @@ if(GRPC_AS_SUBMODULE)
# After using add_subdirectory, we can now use the grpc targets directly from
# this build.
set(_PROTOBUF_LIBPROTOBUF libprotobuf)
set(_REFLECTION grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
@ -84,6 +85,7 @@ elseif(GRPC_FETCHCONTENT)
# Since FetchContent uses add_subdirectory under the hood, we can use
# the grpc targets directly from this build.
set(_PROTOBUF_LIBPROTOBUF libprotobuf)
set(_REFLECTION grpc++_reflection)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
set(_GRPC_GRPCPP_UNSECURE grpc++_unsecure)
if(CMAKE_CROSSCOMPILING)
@ -102,6 +104,7 @@ else()
message(STATUS "Using protobuf ${protobuf_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
@ -151,6 +154,7 @@ foreach(_target
${hw_proto_srcs}
${hw_grpc_srcs})
target_link_libraries(${_target}
${_REFLECTION}
${_GRPC_GRPCPP_UNSECURE}
${_PROTOBUF_LIBPROTOBUF})
endforeach()

@ -21,6 +21,8 @@
#include <string>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>
#include <grpcpp/ext/proto_server_reflection_plugin.h>
#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
@ -50,6 +52,8 @@ void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
ServerBuilder builder;
// Listen on the given address without any authentication mechanism.
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());

Loading…
Cancel
Save