一、proto 文件
syntax = "proto3";
package example;
// 定义四种 RPC 模式的服务
service ExampleService {
// 1. 一元 RPC (Unary):客户端发一个请求,服务端回一个响应
rpc UnaryCall (Request) returns (Response);
// 2. 服务端流式 RPC (Server Streaming):客户端发一个请求,服务端回多个响应
rpc ServerStream (Request) returns (stream Response);
// 3. 客户端流式 RPC (Client Streaming):客户端发多个请求,服务端回一个响应
rpc ClientStream (stream Request) returns (Response);
// 4. 双向流式 RPC (Bidirectional Streaming):双方互相发多个消息
rpc BidiStream (stream Request) returns (stream Response);
}
// 请求消息
message Request {
string data = 1;
}
// 响应消息
message Response {
string data = 1;
}