3

我们的通信超出了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

可以增加该限制,请参阅https://github.com/grpc/grpc-java/issues/917

在 Channel/Server 构建器上设置 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);

也许我遗漏了一些东西,但我看不到如何增加ManagedChannel. 只有OkHttpChannelBuilder有它 ( OkHttpChannelBuilder#maxMessageSize)。

问题:

  • 如何使用 增加消息限制ManagedChannel
  • If it is not possible with ManagedChannel, how can I rewrite the code to use another channel implementation that support to increase the default limit?
4

1 回答 1

5

Edit: You can now increase the limit directly from ManagedChannelBuilder.

Today, you can't increase the limit on ManagedChannelBuilder; you are forced to specify the transport implementation you want to use.

So most users would explicitly use NettyChannelBuilder, and Android users would use OkHttpChannelBuilder:

ManagedChannel channel = 
   NettyChannelBuilder.forAddress(rpcHost, grpcPort)
                        .usePlaintext(true).build();

I've created GitHub issue 2307 to track this.

于 2016-09-28T17:36:22.233 回答