1 Star 0 Fork 129

NickYang / fastrpc

forked from feimat / fastrpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

简单易用,几乎和调用本地方法一样使用即可。
使用protobuf生成代码 支持同时处理pbrpc调用和http请求
客户端支持 windows linux android使用
支持多进程协程和多线程协程两种模式
支持同步异步方式调用 支持单向推送
支持hook sys socket,不用修改任何代码让你业务里的同步socket操作变异步
支持闲时关闭链接 支持自动重连与断开事件处理
同步压测 4核机子虚拟机
简单echo(因为nginx是读文件公平竞争 我们也是读文件) 1000并发 6wqps; nginx 4.5wqps
异步压测10并发 50+w qps
另有400多行实现的 python web服务器,原理一样的,以供参考(通用的多线程reactor模式,用非阻塞模拟异步io)
http://www.oschina.net/p/fastpy

例子

首先定义protobuf 协议

package echo;
message EchoRequest
{
required string message = 1;
};
message EchoResponse
{
required string response = 1;
};
service EchoService
{
rpc Echo(EchoRequest) returns (EchoResponse);
};
option cc_generic_services = true;

然后客户端调用:
RpcClient client(10, "192.168.1.13", 8999, 1000); // 1:并发sock数 2:host 3:ip 4:超时时间
echo::EchoService::Stub stub(&client);

echo::EchoRequest req;
req.set_message("cli hello");
echo::EchoResponse res;
stub.Echo(NULL, &req, &res, NULL); // 同步

服务器调用:
class EchoServiceImpl : public echo::EchoService { // 实现pb生成的接口
virtual void Echo(::google::protobuf::RpcController* controller,
const ::echo::EchoRequest* request,
::echo::EchoResponse* response,
::google::protobuf::Closure* done) {
response->set_response(request->message()+" server_hello");
if (done) {
done->Run();
}
}
};

RpcServer server("192.168.1.13", 8999);
RPCREGI_ONEP(server, EchoServiceImpl);
server.start();

服务器http 处理:

class MyHttpHandler : public HttpHandler {
public:
virtual void Init(CASyncSvr* svr) {}
virtual void OnRec(HttpRequest* request,
::google::protobuf::Closure done) {
CHttpParser
ps = request->ps;
ps->parse_form_body(); // 解析post数据
std::string kk = ps->get_param("kk");
std::string res = kk + " server hello":
std::string content_type = "text/html";
std::string add_head = "Connection: keep-alive\r\n";
CHttpResponseMaker::make_string(kk,
request->response,
content_type,
add_head);
if (done) {
done->Run();
}
}
virtual void Finish(CASyncSvr* svr) {}
};

RpcServer server("192.168.1.13", 8999);
RPCREGI(server, EchoServiceImpl);
HTTPREGI(server, MyHttpHandler);
server.start();

浏览器访问 http://192.168.1.13:8999/xxx?kk=hello

上面只是简单演示了同步rpc请求的例子,
异步调用、协程使用、服务器向客户端单向推送、定时器、线程池的使用和各种网络事件处理的例子参考以下两个main.cpp文件即可
客户端:example/client/main.cpp
服务器端: example/server/main.cpp
http的处理库:http_codec/http/http_util.cpp
更多丰富功能请参阅代码,如果要用到python开发包请参考这里安装http://web.49jie.com/?p=1644

空文件

简介

高性能 c++ 服务器框架 10秒即可上手。技术交流群:339711102,主要探讨游戏开发,游戏框架,后台开发,web框架及fastrpc使用优化问题。 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/nickyang1988/fastrpc.git
git@gitee.com:nickyang1988/fastrpc.git
nickyang1988
fastrpc
fastrpc
master

搜索帮助