Skip to content

Shane0821/shrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

327 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-rpc

A distributed C++ RPC framework built on C++20 coroutines, Google Protobuf, Tencent LLBC, and Zookeeper.

Design document: https://www.processon.com/view/link/674fc43f51e6566236b8c764?cid=645b8e4f34a3ca40d19073a2

Features

  • Coroutine-based RPC: Uses C++20 coroutines to provide a simple, synchronous-style API for asynchronous RPC calls.
  • Service discovery: Integrates with Zookeeper for service registration and discovery.
  • Protobuf-based interfaces: RPC request/response types are defined using Google Protobuf.
  • LLBC networking: Uses Tencent LLBC as the underlying networking layer.

Project layout

  • src/: Core RPC implementation (channels, controllers, service manager, registry, client/server, etc.).
  • 3rd/: Third-party dependencies (protobuf, llbc, fmt, etc.).
  • build/: CMake build output (generated after configuring/building).
  • CMakeLists.txt: Top-level CMake configuration.

Prerequisites

  • A C++20-capable compiler (e.g. GCC 11+, Clang 13+).
  • CMake 3.16+.
  • Zookeeper runtime/server accessible for service registration.

Note: Third-party libraries (protobuf, llbc, fmt, etc.) are vendored under 3rd/ and are wired via CMake. You generally don’t need to install them system-wide.

Build

From the project root:

mkdir -p build
cd build
cmake ..
cmake --build . -j$(nproc)

This will build the main RPC library/binaries defined in src/ (such as client/server executables if present in CMakeLists.txt).

Running

  1. Start Zookeeper and ensure it is reachable at the address used by the code (for example 127.0.0.1:2181, as seen in RpcServiceMgr::Init).
  2. Start your RPC server:
    • Implement your own Protobuf services.
    • Register them with RpcServiceMgr::AddService.
    • Start the underlying LLBC network server and RPC connection manager.
  3. Start your RPC client:
    • Use RpcServiceMgr::RegisterRpcChannel to obtain a channel to a service.
    • Invoke the generated Protobuf stubs over that channel (using coroutine or blocking style depending on your controller usage).

Since this repo focuses on the core framework, typical server/client wiring code lives in the src/ directory—check the examples there when exploring.

High-level flow

  1. Server registers Protobuf services with RpcServiceMgr.
  2. On startup, the service manager registers each service/method in Zookeeper (service_name.method_name -> ip:port).
  3. Client resolves a service via Zookeeper and opens an RpcChannel.
  4. An RPC request is sent over LLBC, deserialized by RpcServiceMgr::HandleRpcReq, dispatched to the target Protobuf service, and the response is serialized and returned from RpcServiceMgr::OnRpcDone.
  5. Client-side coroutine (managed by RpcCoroMgr) resumes when the response arrives in RpcServiceMgr::HandleRpcRsp.

Status

This project is under active development and the APIs may change. Use it as a reference implementation or starting point for coroutine-based RPC with LLBC, Zookeeper, and Protobuf.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors