tob*_*mdk 5 c# f# protocol-buffers grpc
我想从 grpc 服务器流式传输字符串元组。
我似乎找不到一个聪明的方法(如果有的话)来做到这一点。你们中有人在 Protobuf 中的元组方面有过运气吗?
附加信息:
我正在使用 F#,并且想要相应的东西
string * string
Run Code Online (Sandbox Code Playgroud)
你使用什么库?我使用protobuf-net.Grpc没有任何问题。我的服务如下所示:
member __.SubscribeTupleAsync() =
asyncSeq {
while true do
let time = DateTime.Now
yield string time.Minute, string time.Second
do! Async.Sleep 1000
} |> AsyncSeq.toAsyncEnum
Run Code Online (Sandbox Code Playgroud)
我的客户看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
合同是:
[<ServiceContract>]
type ITimeService =
abstract member SubscribeTupleAsync : unit -> IAsyncEnumerable<string * string>
Run Code Online (Sandbox Code Playgroud)
.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);
}
Run Code Online (Sandbox Code Playgroud)
客户端的输出是:
3, 26
3, 27
3, 28
3, 29
3, 30
3, 31
3, 32
3, 33
3, 34
3, 35
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3923 次 |
| 最近记录: |