【问题标题】:gRPC message exceeds maximum size 4194304: 5145024gRPC 消息超过最大大小 4194304:5145024
【发布时间】:2023-01-24 00:37:47
【问题描述】:

在 grpc 客户端上调用服务器中的 rpc 方法后出现此错误。 我正在使用 grpc-spring-boot-starter。请告诉我如何增加响应大小。

        at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262)
        at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243)
        at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156)

【问题讨论】:

    标签: java spring network-programming grpc grpc-java


    【解决方案1】:
    • 如果您使用的是官方 grpc 库,则按以下方式创建客户端。
    ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9089).usePlaintext().maxInboundMessageSize(Integer.MAX_VALUE).build();
    
    productsBlockingStub prodStub = productsGrpc.newBlockingStub(channel);
    

    可以参考grpc项目here。只需添加修改 maxInboundMessageSize

    • 如果您使用的是 grpc-client-spring-boot-starter,那么您也可以。
    @GrpcClient("greeting-service")
        private GreetingServiceGrpc.GreetingServiceBlockingStub greetingServiceBlockingStub;
    
        greetingServiceBlockingStub = greetingServiceBlockingStub.withMaxInboundMessageSize(Integer.MAX_VALUE);
        greetingServiceBlockingStub = greetingServiceBlockingStub.withMaxOutboundMessageSize(Integer.MAX_VALUE);
    

    或者在道具中添加这个。

    grpc.client.greeting-service.max-inbound-message-size=9155241000
    grpc.client.greeting-service.package-max-inbound-message-size=9155241000
    grpc.client.greeting-service.server.max-inbound-message-size=9155241000
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-07
      • 2019-08-17
      • 1970-01-01
      • 2020-10-30
      • 2011-08-02
      • 2020-03-18
      • 2017-04-30
      • 2019-11-08
      相关资源
      最近更新 更多