如何使用包 io.grpc 中的 grpc 状态详细信息

How to use grpc Status Details in package io.grpc

我正在编写一个 java 客户端,它使用 gRPC 与服务器通信。服务器(用 rust 编写)returns 结构化数据在错误的情况下使用 Status Details field.

我看到 com.google.rpc.Status has a getDetails method for accessing the "Any" type. However, my generated java code along with all of the exampls gRPC java clients I've found are using io.grpc.* and io.grpc.Status 没有 可以访问 Details

如何访问详细信息? 通过使用 io.grpc.* 或以某种方式更改我生成的 grpc 客户端以使用 com.google.rpc.

google.rpc.Status 通过 gRPC 元数据传播。 io.grpc.StatusProto class 具有处理 google.rpc.Status 消息的实用程序。使用这些实用程序很重要,因为它们会验证 google.rpc.Status 是否与 io.grpc.Status 匹配,以避免因混合使用两者而导致的安全漏洞。

拦截器将使用 StatusProto.fromStatusAndTrailers(Status, Metadata),而应用程序将使用 StatusProto.fromThrowable(Throwable)StatusRuntimeException in grpc-java 包含元数据,因此可以提取状态。

这与有关。