javascript - NodeJS gRPC : "Method handler expected but not provided"

标签 javascript node.js rpc grpc

我仔细阅读了文档,但尚未找到解决方案。该应用程序大致基于 "sayHello"-example来自他们的文档,但每次代码运行时都会返回警告 Method handler for/eventComm.DatabaseRPC/InsertSingleDocument expected but not provided

我的原型(prototype)文件:

service DatabaseRPC {
  rpc InsertSingleDocument (Doc) returns (Doc) {} 
}

message Doc {
  required string name = 1;
  required int32 id = 2;
}

我的 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()

这段代码有什么问题?当然我已经试过了google the error但没有找到解决方案

最佳答案

为了符合 JavaScript 命名约定,方法的首字母应小写:

server.addProtoService(protoDef.DatabaseRPC.service, {
  insertSingleDocument: InsertSingleDocument
})

您可以在链接的 Hello World 示例中看到这一点。该方法在原型(prototype)文件中声明为 SayHello,但作为 sayHello 传递给服务器。

注意:我同意这令人困惑,并且 I will try to improve the situation .

关于javascript - NodeJS gRPC : "Method handler expected but not provided",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42706736/

相关文章:

javascript - sinon.stub() vs sinon.sandbox.stub()?

c# - 如何将请求 header 从跨域传递到WCF服务?

javascript - Chrome 中鼠标悬停时无法播放视频

javascript - lite-server 未在/js 文件夹内提供 .js 文件 - 浏览器不请求/js 文件

java - 如何处理 XML-RPC 中的错误响应?

javascript - 将图表下载为图像

javascript - ember js 中的动态段

.net - 在 .Net 中进行 RPC 的优化方法

java - GAE - 我应该链接异步回调吗?

node.js - Sequelize 连接模型包括多对多