Install grpcio-tools
:
pip install -r requirements.txt
Generate both RPC stubs + protobuf classes:
python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --grpc_python_out=. ./post.proto
- Install Dev Containers VS Code extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
- Build the image:
docker build -t ddia-4 .
- Run the image:
docker run -it ddia-4
- Click the "remote" icon in the bottom left of VS Code, then select "Attach to Running Container" and select the
ddia-4
container you just ran
- Run
python server.py
andpython client.py
(in separate terminals) to create some posts — check outposts.db
and/orposts.json
to see the encoded data - Add comments (either as nested objects with
Post
or separateComment
type) + create/read RPCs - Some ideas for schema evolution (make sure to regenerate the protobuf classes after each change):
- Try changing
Post.id
from anint32
to astring
(what happens with old encodedPost
s when the server deserializes them?) - Mark
Post.id
as reserved, then add a newstring
uuid
field instead - Change
Post.views
to auint64
- Relevant docs for updating and
reserved
- Try a "rolling upgrade" for a backward-compatible change:
- Leave the server/client running
- Change the
Post
schema inpost.proto
- Regenerate the protobuf classes
- Make code changes for the new fields
- Run the server/client again on a different port
- https://grpc.io/docs/languages/python/basics/
- https://developers.google.com/protocol-buffers/docs/pythontutorial
- https://developers.google.com/protocol-buffers/docs/proto3
Just use above
Install protoc
:
apt-get install protobuf-compiler
Generate post_pb2.py
from post.proto
:
protoc --python_out=. ./post.proto