如何在 node.js 中设置 grpc 客户端超时
How to set timeout of grpc client in node.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);
});
在这种调用格式中,我在哪里提供调用截止时间选项。
此外,https://grpc.io/grpc/node/ 的 jsdoc 从来没有这种 API 调用。
是否有关于此的很好的教程,其中涵盖了流式 rpc、超时、保护通道等示例?
有一个可选参数用于在请求参数和回调之间传递附加选项。这包括一个 deadline
键。所以你会做这样的事情:
client.sayHello({name: user}, {deadline: deadline}, function(err, response) {
console.log('Greeting:', response.message);
});
截止日期可以是日期对象,也可以是Infinity
明确表示通话不会超时。
这在某种程度上是有记录的,因为 Client#makeUnaryRequest
function; just ignore the first three arguments. That mentions the optional options
argument, and its type Client~CallOptions
描述了可以传递到那里的所有选项。
我指的是以下 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、超时、保护通道等示例?
有一个可选参数用于在请求参数和回调之间传递附加选项。这包括一个 deadline
键。所以你会做这样的事情:
client.sayHello({name: user}, {deadline: deadline}, function(err, response) {
console.log('Greeting:', response.message);
});
截止日期可以是日期对象,也可以是Infinity
明确表示通话不会超时。
这在某种程度上是有记录的,因为 Client#makeUnaryRequest
function; just ignore the first three arguments. That mentions the optional options
argument, and its type Client~CallOptions
描述了可以传递到那里的所有选项。