2017-03-09 54 views
1

我翻閱了文檔,但尚未找到解決方案。該應用程序鬆散地基於他們的文檔中的"sayHello"-example,但每次運行代碼時都會返回Method handler for /eventComm.DatabaseRPC/InsertSingleDocument expected but not provided的警告。NodeJS gRPC:「方法處理程序預期但未提供」

我的原型文件:

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卻發現無解

回答

2

使用JavaScript命名慣例接軌,方法應提供小寫的第一個字母:

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

您可以在您鏈接的Hello World例子看看這個。該方法在原始文件中聲明爲SayHello,但作爲sayHello傳遞給服務器。

注:我同意這是令人困惑的,並且I will try to improve the situation

+0

謝謝。我完全錯過了榜樣中的低調。它也是其他語言的問題嗎?也許這將有助於強制執行一個命名方案,其中所有函數都是在proto文件中用起始小寫字母來聲明的。 – trahloff

+0

在多種語言中,有一些期望方法名稱將遵循該語言的命名方案,但這些命名方案可能不同。您在proto文件中的聲明符合proto文件的命名約定。 – murgatroid99

+1

好的,謝謝澄清。可以將它添加到文檔中嗎?在大紅色字母。我喜歡gRPC,但當我閱讀[快速入門指南](http://www.grpc.io/docs/quickstart/node.html#update-a-grpc-service)時,我完全錯過了這一點。 – trahloff

相關問題