https://github.com/aliakseis/grpc-demo
https://github.com/aliakseis/grpc-demo
cpp grpc publish-subscribe streaming
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/aliakseis/grpc-demo
- Owner: aliakseis
- License: mit
- Created: 2020-08-01T11:19:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-21T11:33:41.000Z (9 months ago)
- Last Synced: 2025-09-21T13:21:13.920Z (9 months ago)
- Topics: cpp, grpc, publish-subscribe, streaming
- Language: C++
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gRPC Demo (C++)
A minimal but extendable **gRPC demo project in C++** showcasing a clientβserver architecture, message exchange via `.proto` definitions, and integration with supporting libraries.
---
## π Overview
This project demonstrates how to set up and use **gRPC** with modern **C++17**, using a clean modular structure.
It includes:
- A **gRPC server** (`server/`, `serverlib/`)
- A **gRPC client** (`client/`, `clientlib/`)
- A **shared protocol definition** (`proto/Fov.proto`)
- **Utility libraries** (`common/`) and **transformer app** (`transformer/`)
- Examples of **publish/subscribe client patterns**
---
## π Project Structure
```
grpc-demo-master/
βββ client/ # Demo client executable
β βββ main.cpp
βββ clientlib/ # Client library implementation
β βββ ClientImpl.h
β βββ FovClient.cpp/h
β βββ IPublishSubscribeClient.h
βββ common/ # Shared utilities
β βββ Delegate.h
β βββ fqueue.h
β βββ notifications.hpp
βββ server/ # Demo server executable
β βββ main.cpp
βββ serverlib/ # Server library implementation
β βββ FovServer.cpp/h
β βββ ServerImpl.h
βββ transformer/ # Data transformer app
β βββ main.cpp
βββ ultimateclient/ # Additional example client
β βββ main.cpp
βββ proto/ # gRPC service definitions
β βββ Fov.proto
βββ cmake/ # CMake helper scripts
β βββ doxygenHelper.cmake
βββ docs/ # Doxygen configuration
β βββ Doxyfile.in
βββ CMakeLists.txt # Root build configuration
βββ LICENSE # License information
βββ .gitignore
βββ .gitattributes
```
---
## π οΈ Dependencies
- **C++17 or newer**
- [gRPC](https://grpc.io/) (C++ implementation)
- [Protobuf](https://developers.google.com/protocol-buffers)
- [CMake β₯ 3.15](https://cmake.org/)
- Standard C++ build toolchain (GCC, Clang, or MSVC)
Optional:
- [Doxygen](https://www.doxygen.nl/) for documentation generation
---
## βοΈ Building
1. **Clone the repository**:
```
git clone https://github.com/yourusername/grpc-demo.git
cd grpc-demo-master
```
2. **Create a build directory**:
```
mkdir build && cd build
```
3. **Run CMake**:
```
cmake ..
```
4. **Build the project**:
```
cmake --build .
```
βΆοΈ Running
Start the server:
```
./server/server
```
Run the client:
```
./client/client
```
By default, the client connects to the server using the configuration defined in proto/Fov.proto.
π§ Extending
Add new services to proto/*.proto
Run protoc with the gRPC C++ plugin to regenerate stubs
Implement server handlers in serverlib/
Update client logic in clientlib/
Example protoc invocation:
```
protoc -I=proto --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` proto/Fov.proto
protoc -I=proto --cpp_out=. proto/Fov.proto
```
π Documentation
You can generate API documentation with Doxygen:
```
cd build
make docs
```
Output will be placed under docs/.
The code is structured to be modular and reusable.
You can integrate the client and server libraries into larger applications.
The transformer and ultimateclient are example applications showing flexibility of the architecture.
* [Server implementation](serverlib/ServerImpl.h), [usage example](serverlib/FovServer.cpp)
* [Client implementation](clientlib/ClientImpl.h), [usage example](clientlib/FovClient.cpp)
https://user-images.githubusercontent.com/11851670/127492863-ae7e13a9-babe-46a9-8cd2-a118cda92448.mp4