![](/img/trans.png)
[英]Java How to increase the message size of a grpc server in Spring Boot
[英]java-grpc: How to increase the message size limit in a ManagedChannel?
我们的通信超过了消息大小的默认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 :
在通道/服务器构建器上设置 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
,我如何重写代码以使用另一个支持增加默认限制的通道实现? 编辑:您现在可以直接从ManagedChannelBuilder
增加限制。
今天,您无法增加ManagedChannelBuilder
的限制; 您必须指定要使用的传输实现。
因此,大多数用户将明确使用NettyChannelBuilder
,而Android用户将使用OkHttpChannelBuilder
:
ManagedChannel channel =
NettyChannelBuilder.forAddress(rpcHost, grpcPort)
.usePlaintext(true).build();
我创建了GitHub问题2307来跟踪此问题。
您可以使用maxInboundMessageSize()增加 gRPC 消息限制:
ManagedChannel channel =
ManagedChannelBuilder.forAddress(rpcHost, grpcPort)
.usePlaintext(true)
.maxInboundMessageSize(1000000) // enter the size here
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.