【发布时间】: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)
})
如果ServiceA 和ServiceB 由同一台服务器提供服务,有什么方法可以重用客户端对象吗?
我可以这样做吗:
let commonClient = new grpc.Client(common_url, grpc.credentials.createInsecure());
commonClient.ServiceA.functionOne();
commonClient.ServiceB.functionTwo();
【问题讨论】: