我们的通信超出了默认的grpc-java消息大小限制:
Caused by: io.grpc.StatusRuntimeException: INTERNAL:
Frame size 4555602 exceeds maximum: 4194304.
If this is normal, increase the maxMessageSize
in the channel/server builder
Run Code Online (Sandbox Code Playgroud)
该限制可以增加,请参见https://github.com/grpc/grpc-java/issues/917:
在通道/服务器构建器上设置 maxMessageSize()。
然而,当试图在我们的代码库中实现修复时,我不清楚如何做到这一点,因为并非所有Channel实现都有一个maxMessageSize方法。
我们的代码使用ManagedChannel. 设置代码如下所示:
ManagedChannel channel =
ManagedChannelBuilder.forAddress(rpcHost, grpcPort)
.usePlaintext(true).build();
CatalogGrpcServiceGrpc.CatalogGrpcServiceBlockingStub stub =
CatalogGrpcServiceGrpc.newBlockingStub(channel);
CatalogRetrieverGrpcServiceAdapter grpcServiceAdapter =
new CatalogRetrieverGrpcServiceAdapter(
stub, metricRegistry);
Run Code Online (Sandbox Code Playgroud)
也许我遗漏了一些东西,但我看不到如何增加ManagedChannel. 只有OkHttpChannelBuilder拥有它 ( OkHttpChannelBuilder#maxMessageSize)。
问题:
ManagedChannel?ManagedChannel,我该如何重写代码以使用另一个支持增加默认限制的通道实现?当我查看 grpc-java 自动生成的服务器调用类以及 grpc-java git 存储库中给出的示例时,我可以看到我们扩展了 ImplBase 类并重写了服务方法。就像下面这样:
static class communicationImpl extends communicationImplBase
在 C++ 中,为了实现异步服务,我们使用 AsyncService 而不是 Service 类来扩展我们的实现。但是在java生成的Grpc类中,我看不到另一个名为/以Async开头的类。我在那里看到的唯一与服务器相关的类是以 ImplBase 结尾的类。那么我如何设置我的服务器来在 grpc-Java 中异步处理请求呢?
@Override
public StreamObserver<MdtDialoutArgs> mdtDialout(StreamObserver<MdtDialoutArgs> responseObserver) {
return new StreamObserver<MdtDialoutArgs>() {
@Override
public void onError(Throwable t) {
logger.warn( "Encountered error in mdtDialout");
}
@Override
public void onCompleted() {
responseObserver.onCompleted();
}
@Override
public void onNext(MdtDialoutArgs arg0) {
try {
....
....
...
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出一个 java.lang.ArithmeticException ,没有堆栈跟踪,也没有消息。我没有在 try 块中创建/抛出空的 ArithmeticException 。什么java方法调用/代码可以抛出java.lang.ArithmeticException,没有堆栈跟踪,也没有错误消息?
有没有人见过java中没有消息的ArithmeticException?日志输出:
null java.lang.ArithmeticException
我们在生产环境中使用了很多 grpc 通道。有些通道打开然后关闭,还有许多通道持续打开。
最近,在一个开发项目之后,我们意识到我们让一些通道保持开放状态,而不是关闭它们,直到它成为一个真正需要解决的麻烦时我们才意识到这一点。
我们希望对连接进行一些监控。
我找到了https://github.com/grpc/grpc-java/blob/master/documentation/monitoring-service-tutorial.md但它说
注意:监控服务需要instrumentation-java库实现,该库仍在开发中。在 Instrumentation-java 实现发布之前,本教程中的步骤将不起作用。
我正在为我们的 grpc 寻找一些简单的监控。比如通道开放、吞吐量、错误计数等基本的东西。
只是想知道您的团队在生产中使用什么来监控 grpc java?
我试图弄清楚当我创建连接但什么也没找到时如何使用用户名/密码进行身份验证。所以,我的问题:
有人可以解释我下面.proto文件中“值”的含义吗?
message Test {
string id = 1;
string name = 2;
google.protobuf.Value property = 6;}
Run Code Online (Sandbox Code Playgroud) 与服务器端代码的幂等性或它的必要性有关的问题。一般用于 gRPC,或专门用于 java 实现。
是否有可能,当我们发送消息一旦从客户端,它是处理两次通过我们的服务实现?也许这与服务似乎不可用时的重试有关;或者可以通过某种策略进行配置?
Grpc 客户端未重试,并因 UNAVAILABLE: io 异常而失败。目前我正在设置重试和 maxRetryAttempt,如下所示:
Channel channel = NettyChannelBuilder.forAddress(address.getTarget(), address.getPort())
.enableRetry()
.maxRetryAttempts(3)
.intercept(interceptors)
.sslContext(context.build())
.build();
Run Code Online (Sandbox Code Playgroud)
io.grpc:grpc-netty:1.18.0 是否支持enableRetry 和 maxRetryAttempt?
谢谢。
我正在尝试用 Java 创建 grpc 服务客户端,其中服务器位于 goLang 中并使用 https 进行部署。我试图实现非安全连接[我不想通过证书]
public class testgrpc {
ManagedChannel channel ;
ServiceGrpc.ServiceBlockingStub blockingStub;
String host = "remotesecuredhost";
int port ="XXX";
@Test
public void testgrpc()
{
channel = ManagedChannelBuilder.forAddress(host,port).build();
blockingStub = ServiceGrpc.newBlockingStub(channel);
response = blockingStub.health(Empty.newBuilder().build());
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了以下异常
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:221)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:202)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:131)
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙处理客户端代码吗
在 io.grpc.internal.AbstractServerImplBuilder 中,您可以将 ServerInterceptor 的实现添加到最终列表中
final List<ServerInterceptor> interceptors = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)
然后在构建器的默认服务器实现中 - io.grpc.internal.ServerImpl 它在 foreach 循环中调用它们
/** Never returns {@code null}. */
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
ServerMethodDefinition<ReqT, RespT> methodDef, Metadata headers,
Context.CancellableContext context, StatsTraceContext statsTraceCtx, Tag tag) {
// TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
statsTraceCtx.serverCallStarted(
new ServerCallInfoImpl<>(
methodDef.getMethodDescriptor(), // notify with original method descriptor
stream.getAttributes(),
stream.getAuthority()));
ServerCallHandler<ReqT, RespT> handler = methodDef.getServerCallHandler();
for (ServerInterceptor interceptor : interceptors) { …Run Code Online (Sandbox Code Playgroud) grpc-java ×10
grpc ×9
java ×7
asynchronous ×1
exception ×1
go ×1
monitoring ×1
performance ×1
proto ×1
python ×1
spring ×1
ssl ×1