我希望能够从grpc服务器流式传输一个字符串元组。
我似乎找不到巧妙的方法(如果有的话),可以实现这个功能。你们中有人在protobuf中使用元组取得了成功吗?
其他信息:
我正在使用F#,并且希望找到相应的方法。
string * string
string * string
member __.SubscribeTupleAsync() =
asyncSeq {
while true do
let time = DateTime.Now
yield string time.Minute, string time.Second
do! Async.Sleep 1000
} |> AsyncSeq.toAsyncEnum
我的客户端看起来像这样:
use http = GrpcChannel.ForAddress("http://localhost:10042")
let client = http.CreateGrpcService<ITimeService>()
async {
for (min, sec) in client.SubscribeTupleAsync() |> AsyncSeq.ofAsyncEnum do
printfn "%s, %s" min sec
} |> Async.RunSynchronously
[<ServiceContract>]
type ITimeService =
abstract member SubscribeTupleAsync : unit -> IAsyncEnumerable<string * string>
.proto文件是:
syntax = "proto3";
package ProtobufCommon;
import "google/protobuf/empty.proto";
message Tuple_String_String {
string Item1 = 1;
string Item2 = 2;
}
service TimeService {
rpc SubscribeTuple (.google.protobuf.Empty) returns (stream Tuple_String_String);
}
客户端的输出为:
3, 26
3, 27
3, 28
3, 29
3, 30
3, 31
3, 32
3, 33
3, 34
3, 35
...
(string*string)
表示System.Tuple<string, string>
。 - JL0PD