下面我们通过一个具体例子来呈现
ExampleServiceImpl
Serviceadd_service()
接口添加到Server里start
或者serve
开启服务,处理即将到来的rpc请求Example::Service
派生更多的功能的rpcEcho
不同实现的Serviceadd_service
到不同的Server上,我们也可以把不同的ServiceIMPL实例add_service
到同一个Server上ExampleServiceImpl
,在三个不同端口、同时服务于BPRC-STD、SogouRPC-STD、SogouRPC-Http甚至,我们可以将1个PB的ExampleServiceImpl
和1个Thrift的AnotherThriftServiceImpl
,add_service
到同一个SogouRPC-STD Server,两种IDL在同一个端口上完美工作!
int main()
{
SRPCServer server_srpc;
SRPCHttpServer server_srpc_http;
BRPCServer server_brpc;
ThriftServer server_thrift;
ExampleServiceImpl impl_pb;
AnotherThriftServiceImpl impl_thrift;
server_srpc.add_service(&impl_pb);
server_srpc.add_service(&impl_thrift);
server_srpc_http.add_service(&impl_pb);
server_srpc_http.add_service(&impl_thrift);
server_brpc.add_service(&impl_pb);
server_thrift.add_service(&impl_thrift);
server_srpc.start(1412);
server_srpc_http.start(8811);
server_brpc.start(2020);
server_thrift.start(9090);
pause();
server_thrift.stop();
server_brpc.stop();
server_srpc_http.stop();
server_srpc.stop();
return 0;
}