An open API service indexing awesome lists of open source software.

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

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