【问题标题】:Flatbuffer gRPC streaming definitions (bidi, server, client...)Flatbuffer gRPC 流定义(双向、服务器、客户端...)
【发布时间】:2020-12-31 23:05:07
【问题描述】:

我正在尝试实现一个 Flatbuffer gRPC 服务器,但最初被流式处理:“服务器”定义所迷惑。由于缺乏有关该主题的文档,经过大量挖掘和挫折后,我确实设法弄清楚可以声明一些流类型:

rpc_service MonsterStorage {
  Store(Monster):Stat (streaming: "none");
  Retrieve(Stat):Monster (streaming: "server", idempotent);
  GetMaxHitPoint(Monster):Stat (streaming: "client");
  GetMinMaxHitPoints(Monster):Stat (streaming: "bidi");
}

现在我更加好奇了。看来比迪烟是我需要的,但noneserverclient 是什么意思?幂等对流做了什么?

这实际上是否记录在某个地方,而我只是在搜索方面很糟糕?哈哈。

【问题讨论】:

  • 您可能需要阅读主要的 gRPC 文档。
  • 为什么 Flatbuffer 文档至少不链接到解释这一点的来源?没有任何文档概述 rpc_service 本身的结构。

标签: flatbuffers


【解决方案1】:

gRPC对四种流式的介绍是https://www.grpc.io/docs/languages/cpp/basics/#defining-the-service

将该示例转换为平面缓冲区产生:

rpc_service RouteGuide {

// A simple RPC where the client sends a request to the server using the stub
// and waits for a response to come back, just like a normal function call.

/// Obtains the feature at a given position.
GetFeature(Point): Feature (streaming: "none");


// A server-side streaming RPC where the client sends a request to the server
// and gets a stream to read a sequence of messages back. The client reads
// from the returned stream until there are no more messages.

/// Obtains the Features available within the given Rectangle.  Results are
/// streamed rather than returned at once (e.g. in a response message with a
/// repeated field), as the rectangle may cover a large area and contain a
/// huge number of features.
ListFeatures(Rectangle): Feature (streaming: "server");


// A client-side streaming RPC where the client writes a sequence of
// messages and sends them to the server, again using a provided stream.
// Once the client has finished writing the messages, it waits for the server to
// read them all and return its response.

/// Accepts a stream of Points on a route being traversed, returning a
/// RouteSummary when traversal is completed.
RecordRoute(Point): RouteSummary (streaming: "client");


// A bidirectional streaming RPC where both sides send a sequence of
// messages using a read-write stream. The two streams operate
// independently, so clients and servers can read and write in whatever order
// they like: for example, the server could wait to receive all the client
// messages before writing its responses, or it could alternately read a
// message then write a message, or some other combination of reads and
// writes. The order of messages in each stream is preserved.

/// Accepts a stream of RouteNotes sent while a route is being traversed,
/// while receiving other RouteNotes (e.g. from other users).
RouteChat(RouteNote): RouteNote (streaming: "bidi");

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 2018-04-26
    • 2020-09-09
    • 2021-11-01
    相关资源
    最近更新 更多