dongtan7639 2019-01-10 22:32
浏览 1331
已采纳

在Golang中更新grpc的接收和发送消息大小

I have grpc server written in Go and I am trying to update receive and send message size to 20MB instead of the default 4MB with the following code

var s *grpc.Server
s = grpc.NewServer(grpc.MaxRecvMsgSize(1024*1024*20), grpc.MaxSendMsgSize(1024*1024*20))

pb.RegisterProductServer(s,mysrv)

But the above doesn't seem to be working as I still get an error when I tried to call from a client received message larger than max (5807570 vs. 4194304)" Not sure whats overriding the size

  • 写回答

1条回答 默认 最新

  • douming4359 2019-01-11 02:45
    关注

    I haven't had the chance to test this yet but have you tried adding the same options from the client stub? The same options can be attached as dial options:

    maxMsgSize := 1024*1024*20
    conn, err := grpc.Dial(address, grpc.WithDefaultCallOptions(grpc.MaxRecvMsgSize(maxMsgSize), grpc.MaxSendMsgSize(maxMsgSize)))
    if err != nil {
        // ...
    }
    defer conn.close()
    client := pb.NewProductClient(conn)
    // ...
    

    I don't know anything about your use case but if your response data can be delivered piece wise then the streaming APIs might be useful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵