【问题标题】:GRPC how to reuse client connection?GRPC如何重用客户端连接?
【发布时间】:2018-05-21 17:06:14
【问题描述】:
 // ServiceA - proto
const proto = grpc.load({
    root: protoDir,
    file: 'serviceA.proto'
});

 // ServiceB - proto
const proto = grpc.load({
    root: protoDir,
    file: 'serviceB.proto'
});


let clientA = new ddl_proto.com.mypackage.serviceA(common_url, grpc.credentials.createInsecure());
clientA.functionOne({
    options: JSON.stringify(user_options)
}, (error, response) => {
    console.log(response)
})



let clientB = new ddl_proto.com.mypackage.serviceB(common_url, grpc.credentials.createInsecure());
clientB.functionTwo({
    options: JSON.stringify(user_options)
}, (error, response) => {
    console.log(response)
})

如果ServiceAServiceB 由同一台服务器提供服务,有什么方法可以重用客户端对象吗?

我可以这样做吗:

let commonClient = new grpc.Client(common_url, grpc.credentials.createInsecure());

commonClient.ServiceA.functionOne();

commonClient.ServiceB.functionTwo();

【问题讨论】:

    标签: node.js grpc


    【解决方案1】:

    Answer from grpc developers

    目前,您无法为两种不同的服务显式附加单个连接到客户端。但是,如果您使用相同的 URL、凭据和选项(如果有)创建两个客户端,它们最终应该使用相同的底层连接。

    感谢Michael Lumish

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 2020-10-15
      • 2017-01-09
      • 2020-09-05
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      • 2017-05-25
      • 2017-12-24
      相关资源
      最近更新 更多