- Notifications
You must be signed in to change notification settings - Fork16
chxuan/easyrpc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
easyrpc是采用C++开发的,使用方便的RPC库。
Simple server
#include"easyrpc/easyrpc.h"#include"common.pb.h"usingnamespaceeasyrpc;usingnamespacestd::placeholders;voidecho(const std::shared_ptr<request>& req,const std::shared_ptr<response>& res){ res->set_response(req->message);}intmain(){// 1.创建rpc服务器对象// 服务端将采用1个io线程和2个work线程服务auto server = std::make_shared<rpc_server>("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();return0;}
Simple client
#include"easyrpc/easyrpc.h"#include"common.pb.h"usingnamespaceeasyrpc;intmain(){// 1.创建rpc客户端对象// 配置连接地址并设置请求超时为3秒auto client = std::make_shared<rpc_client>("127.0.0.1:8888",3);// 2.启动事件循环(非阻塞) client->run();auto req = std::make_shared<echo_message>(); req->set_str("Hello world"); req->set_num(1024);// 3.异步调用echo函数 client->call(message, [](const std::shared_ptr<result>& ret) { log_info << ret->message->DebugString(); }); std::cin.get();return0;}
- Ubuntu17.10 gcc7.2.0
- boost
- protobuf
- c++11
- TCP长连接。
- rpc异步调用。
- 日志记录。
- worker线程池处理任务。
- 客户端请求超时处理。
- 支持主动推送模式。
This software is licensed under theMIT license. © 2017 chxuan