【问题标题】:How to set timeout of grpc client in node.js如何在node.js中设置grpc客户端的超时时间
【发布时间】:2017-10-05 16:03:54
【问题描述】:

我指的是以下 node-grpc 客户端示例: https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js

//create a client
var client = new hello_proto.Greeter('localhost:50051',
                                       grpc.credentials.createInsecure());

//issue the call
  client.sayHello({name: user}, function(err, response) {
    console.log('Greeting:', response.message);
  });

在这种通话格式中,我在哪里提供通话截止日期选项。

另外,https://grpc.io/grpc/node/ 的 jsdoc 从来没有这种 API 调用。 是否有一个很好的教程,其中涵盖了流 RPC、超时、保护通道等示例?

【问题讨论】:

    标签: javascript node.js grpc


    【解决方案1】:

    有一个可选参数可以在请求参数和回调之间传递额外的选项。这包括一个deadline 密钥。所以你会做这样的事情:

    client.sayHello({name: user}, {deadline: deadline}, function(err, response) {
      console.log('Greeting:', response.message);
    });
    

    截止日期可以是日期对象或Infinity,以明确没有调用超时。

    这在某种程度上被记录为Client#makeUnaryRequest 函数;只需忽略前三个参数。这提到了可选的options 参数,它的类型Client~CallOptions 描述了可以在那里传递的所有选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2020-08-27
      • 2011-07-11
      • 1970-01-01
      相关资源
      最近更新 更多