1

I have just recent started experimenting with gRCP and currently trying to see how it works using node-js to create a simple example . However after creating the protocol to be used between both client and server . One of my rpc method is not been called . I have added below the specific method that is not been called along side the message specification in the .proto file .I have also provided a sample of both client side call and server side handler below.

.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));
});

It seems because I am trying to specify the RetrieveAllWeather to accept nothing as payload and send a json {msg:"call"} but it is not working while other method that I created are working .

hebronace
  • 77
  • 8

1 Answers1

1

It seems that using the void message naming convention was the cause of the bug , when I switch to using a Capitiized name for the message spec it started working . All I did was to change from message void{} to message Void{}

hebronace
  • 77
  • 8