https://github.com/chxuan/easyrpc
:sunflower:Easy to use RPC framework
https://github.com/chxuan/easyrpc
boost c-plus-plus protobuffer rpc-framework
Last synced: 9 months ago
JSON representation
:sunflower:Easy to use RPC framework
- Host: GitHub
- URL: https://github.com/chxuan/easyrpc
- Owner: chxuan
- License: mit
- Created: 2015-12-03T13:43:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-01-20T07:56:15.000Z (almost 8 years ago)
- Last Synced: 2025-04-28T13:03:44.946Z (9 months ago)
- Topics: boost, c-plus-plus, protobuffer, rpc-framework
- Language: C++
- Homepage: https://github.com/chxuan/easyrpc
- Size: 643 KB
- Stars: 42
- Watchers: 6
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A modern RPC framework based on protobuf
===============================================
> easyrpc是采用C++开发的,使用方便的RPC库。
![License][1]
## Tutorial
* **Simple server**
```cpp
#include "easyrpc/easyrpc.h"
#include "common.pb.h"
using namespace easyrpc;
using namespace std::placeholders;
void echo(const std::shared_ptr& req, const std::shared_ptr& res)
{
res->set_response(req->message);
}
int main()
{
// 1.创建rpc服务器对象
// 服务端将采用1个io线程和2个work线程服务
auto server = std::make_shared("0.0.0.0:8888", 1, 2);
// 2.设置路由
server->route(echo_message::descriptor()->full_name(), std::bind(echo, _1, _2));
// 3.启动事件循环(非阻塞)
server->run();
std::cin.get();
return 0;
}
```
* **Simple client**
```cpp
#include "easyrpc/easyrpc.h"
#include "common.pb.h"
using namespace easyrpc;
int main()
{
// 1.创建rpc客户端对象
// 配置连接地址并设置请求超时为3秒
auto client = std::make_shared("127.0.0.1:8888", 3);
// 2.启动事件循环(非阻塞)
client->run();
auto req = std::make_shared();
req->set_str("Hello world");
req->set_num(1024);
// 3.异步调用echo函数
client->call(message, [](const std::shared_ptr& ret)
{
log_info << ret->message->DebugString();
});
std::cin.get();
return 0;
}
```
## 开发平台
* Ubuntu17.10 gcc7.2.0
## 依赖性
* boost
* protobuf
* c++11
## DONE
* TCP长连接。
* rpc异步调用。
* 日志记录。
* worker线程池处理任务。
* 客户端请求超时处理。
* 支持主动推送模式。
## License
This software is licensed under the [MIT license][2]. © 2017 chxuan
[1]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[2]: https://github.com/chxuan/easyrpc/blob/master/LICENSE