简体   繁体   English

如何在node.js中设置grpc客户端超时

[英]How to set timeout of grpc client in node.js

I'm referring to the following example of node-grpc client: https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js 我指的是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);
  });

In this call format, where do I provide the call deadline options. 在这种呼叫格式下,我在哪里提供呼叫截止时间选项。

Also, the jsdoc at https://grpc.io/grpc/node/ never has this kind of API calls. 另外,位于https://grpc.io/grpc/node/的jsdoc从来没有这种API调用。 Is there a good tutorial on this which covers examples like streaming rpcs, timeouts, securing the channels etc? 是否有一个很好的教程涵盖了流RPC,超时,保护通道等示例?

There's an optional argument to pass additional options between the request argument and the callback. 有一个可选参数,用于在请求参数和回调之间传递其他选项。 This includes a deadline key. 这包括deadline密钥。 So you would do something like this: 因此,您将执行以下操作:

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

Deadline can either be a date object or Infinity to explicitly not have the call time out. 截止日期可以是日期对象,也可以是Infinity以明确地没有呼叫超时。

This is documented, sort of, as the Client#makeUnaryRequest function; 这在Client#makeUnaryRequest被记录为Client#makeUnaryRequest函数; just ignore the first three arguments. 只需忽略前三个参数即可。 That mentions the optional options argument, and its type Client~CallOptions describes all of the options that can be passed there. 上面提到了可选的options参数,其类型Client~CallOptions描述了可以在此处传递的所有选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM