Node.js的gRPC客户端工具:grpc-caller

如果你想让Node.js作为客户端调用gRPC的方法,可以在https://github.com/grpc/grpc-node 上找到相应的方法。在其中,我们认为”grpc-caller”是最简单方便的Client方法。

我也尝试了名为「node-grpc-client」的工具,但最终还是选择了「grpc-caller」。

安装

使用npm安装grpc-caller模块。

范本

const path = require('path')
const caller = require('grpc-caller')

const PROTO_PATH = path.resolve(__dirname, './protos/cassandra.proto')
const client = caller('localhost:50051', PROTO_PATH, 'Calendar')

client.getCalendar({ calendarId: '20191010abc' }, (err, res) => {
  console.log(res)
})

以上

bannerAds