minirpc分布式 RPC 系统
minirpc 是基于 protobuf 的分布式 RPC 系统。
1. rpc server端提供的service可以是so库文件方式存在,可以使用libloader工具增加到server上。
 2. rpc server会将自己所提供的服务注册到agent上。
 3. agent服务中心采用去中心化的方式运行,通过加入组播实现rpc server的服务列表管理和运行状态的准实时展现。
 4. rpc client可以使用需要调用的server名称(字符串服务名),向agent中心获取提供此类服务的rpc server,之后连接rpc server实现数据传输和业务处理。
5. rpc server单进程每秒处理142000个请求包(intel i5 cpu),可以参考统计页面的Package TPS显示。
------------------------------------------------------------------
rpc 具体业务实现lib库编写方式:
#include "rpc_serverobserver.h"
#include "echo.pb.h"
#include "common/clogwriter.h"
#include <unistd.h>
extern "C" {
    int echo_Init(CRpcSerObserver* aRpcServer);
}
class LibEchoServiceImpl : public echo::EchoService {
    virtual void Echo(::google::protobuf::RpcController* controller,
                      const ::echo::EchoRequest* request,
                      ::echo::EchoResponse* response,
                      ::google::protobuf::Closure* done) {
        response->set_response(request->message()+" lib_rpc_server_echo_hello");
        if (done) {
            done->Run();
        }
    }
    virtual void Dummy(::google::protobuf::RpcController* controller,
                       const ::echo::DummyRequest* request,
                       ::echo::DummyResponse* response,
                       ::google::protobuf::Closure* done) {
        if (done) {
            done->Run();
        }
    }
};
int echo_Init(CRpcSerObserver* aRpcServer) {
    DEBUG(LL_WARN, "echo_Init Begin.");
    RPCREGI(aRpcServer, LibEchoServiceImpl);
    return 0;
} 
------------------------------------------------------------------
agent启动方式:
cd agent
[w@localhost agent]$./miniagent -d
打开agent的运行页面观察运行状态,默认端口是15218.
http://serverip:15218
rpc server启动方式:
[w@localhost protobuf]$ ./rpc_server_basic  -p 9987 -s ECHO -d
 [w@localhost protobuf]$ ./rpc_server_basic  -p 9988 -s ECHO1 -d      
 [w@localhost protobuf]$ ./rpc_server_basic  -h
 =====================================
   使用方法: RpcServer [参数选项][-c 配置文件]
   参数选项描述:
   -p 监听端口 程序启动时绑定的监听端口。
   -s 服务名称 程序启动时提供的服务名称。
   -c 配置文件。
   -d 后台运行  守护进程方式运行。
   -l 日志级别  日志级别见如下描述:
                1. 错误日志;
                2. 警告日志;
                3. 通知日志;
                4. 重要的提示性日志;
                5. 打印关键变量的值;
                6. 开发人员的调试日志;
                7. 打开所有的日志。
   -v           输出版本信息。
   -h           输出运行帮助信息。
   启动实例:   RpcServer  -p 9090 -c RpcServer.ini -l 2 -d
 =====================================
运行动态库加载工具,向服务BasicServer增加libecho.so提供的服务。
[w@localhost protobuf]$ ./rpc_libloader BasicServer load libecho.so
create success
 load resp: libecho.so load success, method list:  echo.EchoService.Echo echo.EchoService.Dummy
 load requ: libecho.so
 load success
 [w@localhost protobuf]$ ./rpc_libloader BasicServer load libecho2.so
 create success
 load resp: libecho2.so load success, method list:  echo2.EchoService.Echo echo2.EchoService.Dummy
参考:
 代码中你会看到一些类似的开源代码。本项目中的一些代码来自如下开源软件。
 haproxy
 cxxtools
 thrift
 protobuf
 kamailio
 sems
 fastrpc
 redis
 putty等。
谢谢以上开源软件的开发者们。
请不要拍砖,如果你觉得不可使用,可以选择thrift等其他rpc软件。
