【问题标题】:gRPC node-js method not called when protocol specifies void parameter type协议指定 void 参数类型时未调用 gRPC node-js 方法
【发布时间】:2021-09-28 06:26:02
【问题描述】:

我最近刚刚开始尝试使用 gRCP,目前正在尝试使用 node-js 创建一个简单的示例来看看它是如何工作的。但是,在创建要在客户端和服务器之间使用的协议之后。我的 rpc 方法之一没有被调用。 我在.proto文件中的消息规范下方添加了未调用的特定方法。我还在下面提供了客户端调用和服务器端处理程序的示例。

.proto

service WeatherService{
    rpc RetrieveAllWeather (void) returns (Temp);
}
message void{}

message Temp{
    string msg =1; 
}

server.js

// .... server configuration
server.addService(weather_proto.WeatherService.service,
    {
        "RetrieveAllWeather":RetrieveAllWeather,
        "RetrieveWeatherByQuery":RetrieveWeatherByQuery,
        "SaveWeatherToFile":SaveWeatherToFile,
    }    
); 
    
server.bindAsync(
    "127.0.0.1:4000",
    grpc.ServerCredentials.createInsecure(),
    (err,port)=>{
        if(err){
            console.error(err);
            process.exit(1);
        }
        console.log("Listening on port "+port)
        server.start();
    }
);

function RetrieveAllWeather(call,callback){
    console.log(call);
    console.log("working");
    callback(null,"call");
}

client.js


const client  =  new weather_proto.WeatherService(
    "127.0.0.1:4000",grpc.credentials.createInsecure()
);


client.RetrieveAllWeather({},(err,res)=>{
    if(err){
        return err;
    }
    console.log("working");
    console.log(JSON.stringify(res));
});

似乎是因为我试图指定 RetrieveAllWeather 不接受任何内容作为有效负载并发送 json {msg:"call"} 但它不起作用,而我创建的其他方法正在运行。

【问题讨论】:

    标签: javascript node.js grpc grpc-node


    【解决方案1】:

    似乎使用 void 消息命名约定是导致错误的原因,当我切换到使用 Capitiized 名称作为它开始工作的消息规范时。我所做的只是从message void{} 更改为message Void{}

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多