【问题标题】:Consuming a grpc stream fails on de-serializing response使用 grpc 流在反序列化响应时失败
【发布时间】:2021-02-28 19:26:32
【问题描述】:

我们正在尝试使用带有网络核心后端的流,但出现反序列化错误

"grpc":{2 items
    "method":string"*****"
    "error":{2 items
    "code":int2
    "message":string"Error in response deserializer function."
  }
}

protoc 是 3.14.0 版本 grpc-web-gen 是 1.2.1

生成客户端的命令是: protoc -I=./protos ./protos/*.proto --js_out=import_style=commonjs,binary:./dist --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:./dist

我们成功连接到端点并检索数据,但调用在绑定使用 response.getMessage() 时失败 由于没有其他错误消息并且调试不是很简单,因此欢迎任何有关可能导致此错误的原因的见解:)

谢谢

【问题讨论】:

    标签: reactjs deserialization grpc grpc-web


    【解决方案1】:

    我在使用 gRPC Web 时遇到了同样的错误,因为我复制了示例而没有意识到 getMessage() 不是框架 API 的一部分,而是示例 Protobuf 定义中的 message 字符串字段。

    尝试直接使用response(或使用toObject()对其进行序列化)

    var stream = echoService.serverStreamingEcho(streamRequest, metadata);
    stream.on('data', function(response) {
      console.log(response.toObject());
    });
    

    【讨论】:

    • 它对我有用!感谢分享马特奥
    猜你喜欢
    • 2012-08-11
    • 2018-11-23
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    相关资源
    最近更新 更多