Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.9 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.9 KB

greeting codegen example

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]

main structure

  • 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

codegen

  1. check buf dependencies buf dep update
  2. 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).

codegen usage

  • start rabbitmq with docker-compose up -d rabbitmq
  • client_brokrpc.py -- uses generated GreeterClient code to send RPC to GreeterService. Run it with python src/server_brokrpc.py
  • server_brokrpc.py -- RPC server with GreeterService implementation. Run it with python src/client_brokrpc.py