java-grpc: How to increase the message size limit in a ManagedChannel?
Asked Answered
V

2

9

Our communication exceeds the default grpc-java limit on the message size:

Caused by: io.grpc.StatusRuntimeException: INTERNAL:
Frame size 4555602 exceeds maximum: 4194304.
If this is normal, increase the maxMessageSize
in the channel/server builder

That limit can be increased, see from https://github.com/grpc/grpc-java/issues/917:

Set maxMessageSize() on the Channel/Server builder.

When trying to implement the fix in our code base, however, it is not clear for me how to do that, as not all Channel implementations have a maxMessageSize method.

Our code uses a ManagedChannel. The setup code looks like this:

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

CatalogGrpcServiceGrpc.CatalogGrpcServiceBlockingStub stub =
    CatalogGrpcServiceGrpc.newBlockingStub(channel);
CatalogRetrieverGrpcServiceAdapter grpcServiceAdapter =
    new CatalogRetrieverGrpcServiceAdapter(
            stub, metricRegistry);

Maybe I am missing something, but I cannot see how to increase the maximum size for ManagedChannel. Only the OkHttpChannelBuilder has it (OkHttpChannelBuilder#maxMessageSize).

Questions:

  • How can I increase the message limit with a 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?
Vagina answered 28/9, 2016 at 17:9 Comment(0)
F
9

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.

Fcc answered 28/9, 2016 at 17:36 Comment(0)
E
4

You can increase gRPC message limit using maxInboundMessageSize():

ManagedChannel channel = 
   ManagedChannelBuilder.forAddress(rpcHost, grpcPort)
                        .usePlaintext(true)
                        .maxInboundMessageSize(1000000) // enter the size here
                        .build();
Emulation answered 13/12, 2022 at 14:53 Comment(2)
maxInboundMessageSize is ignored in my case. Which grpcVersion are you using?Dichromatic
I don't have the configuration anymore but believe it was v1.51Emulation

© 2022 - 2025 — McMap. All rights reserved.