tra*_*off 4 javascript rpc node.js grpc
我翻阅了文档,但还没有找到解决方案。该应用程序松散地基于其文档中的“sayHello”示例,但每次代码运行时Method handler for /eventComm.DatabaseRPC/InsertSingleDocument expected but not provided都会返回警告。
我的原型文件:
service DatabaseRPC {
rpc InsertSingleDocument (Doc) returns (Doc) {}
}
message Doc {
required string name = 1;
required int32 id = 2;
}
Run Code Online (Sandbox Code Playgroud)
我的 gRPC 服务器:
function InsertSingleDocument (call, callback) {
callback(null, {
name: 'Hello ',
id: 1
})
}
let server = new grpc.Server()
server.addProtoService(protoDef.DatabaseRPC.service, {
InsertSingleDocument: InsertSingleDocument
})
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure())
server.start()
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?当然,我已经尝试用谷歌搜索错误,但没有找到解决方案
为了符合 JavaScript 命名约定,方法的首字母应该小写:
server.addProtoService(protoDef.DatabaseRPC.service, {
insertSingleDocument: InsertSingleDocument
})
Run Code Online (Sandbox Code Playgroud)
您可以在链接的 Hello World 示例中看到这一点。该方法SayHello在 proto 文件中声明,但作为sayHello.
注意:我同意这令人困惑,我会努力改善这种情况。