简体   繁体   中英

NodeJS gRPC: “Method handler expected but not provided”

I plowed through the docs and haven't found a solution yet. The app is loosely based on the "sayHello"-example from their docs but every time the code runs the warning Method handler for /eventComm.DatabaseRPC/InsertSingleDocument expected but not provided is returned.

My proto file:

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

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

My gRPC Server:

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

What is the problem with this code? Of course I already tried to google the error but found no solution

To conform with JavaScript naming conventions, methods should be provided with the first letter lowercased:

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

You can see this in the Hello World example you linked. The method is declared as SayHello in the proto file, but is passed to the server as sayHello .

Note: I agree that this is confusing, and I will try to improve the situation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM