You can follow the detailed example below:
ExampleServiceImpl
Serviceadd_service()
interface.start()
or serve()
to start the services in the Server and handle the upcoming rpc requests through the Server.Example::Service
, which have different implementations of rpc Echo
.add_service()
to add the same ServiceIMPL instance on different Servers, or we can use add_service()
to add different ServiceIMPL instances on the same server.ExampleServiceImpl
, serving BPRC-STD, SRPC-STD, SRPC-Http at three different ports at the same time.And we can use add_service()
to add one ExampleServiceImpl
related to Protobuf IDL and one AnotherThriftServiceImpl
related to Thrift IDL to the same SRPC-STD Server, and the two IDLs work perfectly on the same port!
int main()
{
SRPCServer server_srpc;
SRPCHttpServer server_srpc_http;
BRPCServer server_brpc;
ThriftServer server_thrift;
TRPCServer server_trpc;
TRPCHttpServer server_trpc_http;
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_trpc.add_service(&impl_pb);
server_trpc_http.add_service(&impl_pb);
server_srpc.start(1412);
server_srpc_http.start(8811);
server_brpc.start(2020);
server_thrift.start(9090);
server_trpc.start(2022);
server_trpc_http.start(8822);
getchar();
server_trpc_http.stop();
server_trpc.stop();
server_thrift.stop();
server_brpc.stop();
server_srpc_http.stop();
server_srpc.stop();
return 0;
}