sample book store app using grpc python and grpc cpp demonstrates python and cpp services interacting over grpc.
Run the following commands that will bring store
, warehouse
and client
up
git clone https://github.com/tosbala/sample-grpc.git
cd sample-grpc
docker-compose build
docker-compose up
Ensure you have grpc_cpp setup in your system.
We can take out python service and replace it with cpp service and vice versa.
cd sample-grpc/cpp
mkdir -p cmake/build
pushd cmake/build
cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
make -j
./bookstore_server
./bookstore_client
Ensure grpc::EnableDefaultHealthCheckService
is set to true
to enable tracking the status through grpc health check protocol.
Then grpc_health_probe shall be used to probe the health of the service
grpc::SslCredentialsOptions ssl_opt = {root_cert, client_key, client_cert};
auto client_creds = grpc::SslCredentials(ssl_opt);
BookstoreClient store(
grpc::CreateChannel(target_str, client_creds));
Refer client_credentials()
in cpp/bookstore_client.cc
grpc::SslServerCredentialsOptions::PemKeyCertPair key_cert_pair = {server_key, server_cert};
grpc::SslServerCredentialsOptions ssl_opts(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
ssl_opts.pem_root_certs = root_cert;
ssl_opts.pem_key_cert_pairs.push_back(key_cert_pair);
auto server_creds = grpc::SslServerCredentials(ssl_opts);
builder.AddListeningPort(server_address, server_creds);
Refer server_credentials()
in cpp/bookstore_server.cc
All the references to certs and keys require file content as string not the file path.