|
@@ -8,14 +8,14 @@
|
|
|
| Thrift Binary HttpTransport | Thrift | HTTP | Binary | Not supported | Not supported | Supported | Not supported | Not supported |
|
|
|
| GRPC | PB | HTTP2 | Binary | gzip/zlib/lz4/snappy | Supported | Not supported | Supported | Supported |
|
|
|
| BRPC Std | PB | TCP | Binary | gzip/zlib/lz4/snappy | Supported | Not supported | Supported | Supported |
|
|
|
-| SogouRPC Std | PB/Thrift | TCP | Binary/JSON | gzip/zlib/lz4/snappy | Supported | Supported | Supported | Not supported |
|
|
|
-| SogouRPC Std HTTP | PB/Thrift | HTTP | Binary/JSON | gzip/zlib/lz4/snappy | Supported | Supported | Supported | Not supported |
|
|
|
+| SRPC Std | PB/Thrift | TCP | Binary/JSON | gzip/zlib/lz4/snappy | Supported | Supported | Supported | Not supported |
|
|
|
+| SRPC Std HTTP | PB/Thrift | HTTP | Binary/JSON | gzip/zlib/lz4/snappy | Supported | Supported | Supported | Not supported |
|
|
|
| tRPC Std | PB | TCP | Binary/JSON | gzip/zlib/lz4/snappy | Supported | Supported | Supported | Not supported |
|
|
|
|
|
|
## Basic concepts
|
|
|
|
|
|
- Communication layer: TCP/TPC\_SSL/HTTP/HTTPS/HTTP2
|
|
|
-- Protocol layer: Thrift-binary/BRPC-std/SogouRPC-std/tRPC-std
|
|
|
+- Protocol layer: Thrift-binary/BRPC-std/SRPC-std/tRPC-std
|
|
|
- Compression layer: no compression/gzip/zlib/lz4/snappy
|
|
|
- Data layer: PB binary/Thrift binary/JSON string
|
|
|
- IDL serialization layer: PB/Thrift serialization
|
|
@@ -93,7 +93,7 @@ service Example {
|
|
|
|
|
|
## RPC Service
|
|
|
|
|
|
-- It is the basic unit for sogouRPC services.
|
|
|
+- It is the basic unit for SRPC services.
|
|
|
- Each service must be generated by one type of IDLs.
|
|
|
- Service is determined by IDL type, not by specific network communication protocol.
|
|
|
|
|
@@ -103,7 +103,7 @@ You can follow the detailed example below:
|
|
|
|
|
|
- Use the same `example.proto` IDL above.
|
|
|
- Run the official `protoc example.proto --cpp_out=./ --proto_path=./` to get two files: `example.pb.h` and `example.pb.cpp`.
|
|
|
-- Run the `srpc_generator protobuf ./example.proto ./` in SogouRPC to get `example.srpc.h`.
|
|
|
+- Run the `srpc_generator protobuf ./example.proto ./` in SRPC to get `example.srpc.h`.
|
|
|
- Derive `Example::Service` to implement the rpc business logic, which is an RPC Service.
|
|
|
- Please note that this Service does not involve any concepts such as network, port, communication protocol, etc., and it is only responsible for completing the business logic that convert `EchoRequest` to `EchoResponse`.
|
|
|
|
|
@@ -141,8 +141,8 @@ You can follow the detailed example below:
|
|
|
- Imagine that we can also derive more Serivce from `Example::Service`, which have different implementations of rpc `Echo`.
|
|
|
- Imagine that we can create N different RPC Servers on N different ports, serving on different network protocols.
|
|
|
- Imagine that we can use `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.
|
|
|
-- Imagine that we can use the same `ExampleServiceImpl`, serving BPRC-STD, SogouRPC-STD, SogouRPC-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 SogouRPC-STD Server, and the two IDLs work perfectly on the same port!
|
|
|
+- Imagine that we can use the same `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!
|
|
|
|
|
|
~~~cpp
|
|
|
int main()
|
|
@@ -151,6 +151,8 @@ int main()
|
|
|
SRPCHttpServer server_srpc_http;
|
|
|
BRPCServer server_brpc;
|
|
|
ThriftServer server_thrift;
|
|
|
+ TRPCServer server_trpc;
|
|
|
+ TRPCHttpServer server_trpc_http;
|
|
|
|
|
|
ExampleServiceImpl impl_pb;
|
|
|
AnotherThriftServiceImpl impl_thrift;
|
|
@@ -161,12 +163,19 @@ int main()
|
|
|
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);
|
|
|
- pause();
|
|
|
+ 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();
|
|
@@ -194,6 +203,7 @@ You can follow the detailed example below:
|
|
|
~~~cpp
|
|
|
#include <stdio.h>
|
|
|
#include "example.srpc.h"
|
|
|
+#include "workflow/WFFacilities.h"
|
|
|
|
|
|
using namespace srpc;
|
|
|
|
|
@@ -201,18 +211,21 @@ int main()
|
|
|
{
|
|
|
Example::SRPCClient client("127.0.0.1", 1412);
|
|
|
EchoRequest req;
|
|
|
- req.set_message("Hello, sogou rpc!");
|
|
|
- req.set_name("Li Yingxin");
|
|
|
+ req.set_message("Hello!");
|
|
|
+ req.set_name("SRPCClient");
|
|
|
+
|
|
|
+ WFFacilities::WaitGroup wait_group(1);
|
|
|
|
|
|
- client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
|
|
|
+ client.Echo(&req, [&wait_group](EchoResponse *response, RPCContext *ctx) {
|
|
|
if (ctx->success())
|
|
|
printf("%s\n", response->DebugString().c_str());
|
|
|
else
|
|
|
printf("status[%d] error[%d] errmsg:%s\n",
|
|
|
ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
|
|
|
+ wait_group.done();
|
|
|
});
|
|
|
|
|
|
- pause();
|
|
|
+ wait_group.wait();
|
|
|
return 0;
|
|
|
}
|
|
|
~~~
|
|
@@ -476,13 +489,20 @@ int main()
|
|
|
auto *calc_task = WFTaskFactory::create_go_task(calc, 3, 4);
|
|
|
|
|
|
EchoRequest req;
|
|
|
- req.set_message("Hello, sogou rpc!");
|
|
|
+ req.set_message("Hello!");
|
|
|
req.set_name("1412");
|
|
|
rpc_task->serialize_input(&req);
|
|
|
|
|
|
- ((*http_task * rpc_task) > calc_task).start();
|
|
|
+ WFFacilities::WaitGroup wait_group(1);
|
|
|
+
|
|
|
+ SeriesWork *series = Workflow::create_series_work(http_task, [&wait_group](const SeriesWork *) {
|
|
|
+ wait_group.done();
|
|
|
+ });
|
|
|
+ series->push_back(rpc_task);
|
|
|
+ series->push_back(calc_task);
|
|
|
+ series->start();
|
|
|
|
|
|
- pause();
|
|
|
+ wait_group.wait();
|
|
|
return 0;
|
|
|
}
|
|
|
~~~
|