duanke2503 2018-03-31 17:18
浏览 472

如何在grpc服务器端使用从客户端传递的上下文

I have defined an endpoint in the grpc service. Now when the client calls the endpoint with some context how am I supposed to handle that context, its expiry/deadline etc?

I mean in the service side, I have a series of steps to be performed to complete the request. It includes some processing, writing to data store etc. Now how am I supposed to honor the context. Is it that after every step in the process, I am required to check if the context is done?. If it is done, I will just return instead of proceeding to the next step? This doesn't feel right though.

What is the right way to do it in GRPC/Go?

  • 写回答

1条回答 默认 最新

  • douye4051 2018-04-04 20:14
    关注

    The context that the service handler gets has the deadline(the one that client set) set in it. Go way would be to pass that context around in each step of your way and if any of these steps are blocking you block on that context as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看