The project provides example of generated code and implemented brokrpc server & client.
System requirements:
- buf CLI to generate code from protobuf files
- protoc to generate code from protobuf files
- docker compose to run RabbitMQ broker
- python 3.12 or higher
Python requirements:
pyprotostuben
BrokRPC[aiormq]
- proto -- contains protobuf files that are used to generate code
- buf.yaml -- buf CLI config for the project
- buf.gen.yaml -- buf CLI config for codegen
- src -- python code
- check buf dependencies
buf dep update
- generate code
buf generate
After that the src/gen python package will be updated with following modules:
- greeting_brokrpc.py -- RPC server & RPC client for BrokRPC framework (generated by
protoc-gen-brokrpc
plugin). - greeting_pb2.py -- python module with protobuf message structures for runtime (generated by builtin protoc python plugin).
- greeting_pb2.pyi -- protobuf message stubs for python type checker (generated by
protoc-gen-mypy-stub
plugin). - greeting_pb2_grpc.py -- servicer & stub for gRPC framework (generated by remote buf plugin).
- greeting_pb2_grpc.pyi -- gRPC stubs for python type checker (generated by
protoc-gen-mypy-stub
plugin).
- start rabbitmq with
docker-compose up -d rabbitmq
- client_brokrpc.py -- uses generated
GreeterClient
code to send RPC toGreeterService
. Run it withpython src/server_brokrpc.py
- server_brokrpc.py -- RPC server with
GreeterService
implementation. Run it withpython src/client_brokrpc.py