Learning gRPC and protocol buffers based on this tutorial blog.
- python3
- virtualenv
create virtual environment directory for python
virtualenv venvstart virtualenv
source venv/bin/activatechange to app directory
cd app/install python packages
pip install -r requirements.txtgenerate gRPC class files from .proto files
python \
-m grpc_tools.protoc \
--proto_path=autogenerated=proto \
--python_out=. \
--grpc_python_out=. \
proto/*.protospin-up gRPC server
python server.pydocker build -t=learn-grpc-protobuf .
docker run -p 50051:50051 learn-grpc-protobufin another terminal, start virtualenv
source venv/bin/activatechange to app directory
cd app/make a request to the gRPC server via the client script
python client.pyyou should see this output:
result of square_root(16): 4.0
result of add(4,5): 9.0
result of say_hello(My name is Harry): Hello, your request message was: My name is Harryspin-down python gRPC server in 1st terminal
ctrl+cdeactivate virtualenv in both terminals
deactivate