【问题标题】:java-grpc: How to increase the message size limit in a ManagedChannel?java-grpc:如何增加 ManagedChannel 中的消息大小限制?
【发布时间】:2016-09-28 17:09:30
【问题描述】:

我们的通信超出了默认的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 增加消息限制?
  • 如果无法使用ManagedChannel,我该如何重写代码以使用支持增加默认限制的另一个通道实现?

【问题讨论】:

    标签: java grpc grpc-java


    【解决方案1】:

    编辑:您现在可以直接从ManagedChannelBuilder 增加限制。

    今天你不能增加ManagedChannelBuilder的限制;您必须指定要使用的传输实现。

    所以大多数用户会明确使用NettyChannelBuilder,而Android用户会使用OkHttpChannelBuilder

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

    我创建了GitHub issue 2307 来跟踪这个。

    【讨论】:

      猜你喜欢
      • 2017-07-26
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2023-02-15
      • 1970-01-01
      相关资源
      最近更新 更多