You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using protobuf.js 6, services are instances of the service class here. You can look them up, but there is not a lot of functionality within. You can, however, get the resolved request and response types of the respective methods.
There has been a bit of discussion previously to support use cases like grpc out of the box, but as I am not using services myself, I'd require some suggestions.
varMyService=root.lookup("MyService");// First, implement the RPC channel:functionrpc(method,requestData,callback){// send requestData (binary) over the network
...
// then call the callback with error, if any, and the received responseData (binary)callback(null,responseData);}// Create a runtime service:varmyService=MyService.create(/* your rpc implementation */rpc,/* requestDelimited? */true,/* responseDelimited? */true);// Call its methods (uses your RPC channel)myService.MyMethod({awesomeField: "awesomeText"},function(err,responseMessage){
...
});
functionrpc(method,requestData,callback){varRequestType=root.lookup('RequestType');// CRASH in ReaderPrototype.skip on throw indexOutOfRange(this);varrequest=RequestType.decode(requestData);
Trying to debug:
$requestData.toString()"\u0000"
I know it's silly that my messages are empty at the moment, but I guess it shouldn't crash anyway and it's good for QA:
Well I am not sure whether message without any fields is delimited or not. But if I create RPC with MailService.create(rpc, false, false) then it works fine. It feels like if there are no any fields in message then it shouldn't attempt to read it..
so with Protobuf.js I can create RPC server in Node.js and that's pretty clear, however, how do I define an RPC client? Do I have to funnel data to remote RPC and pass back results somehow? I use ZeroMQ as transport to pass data between processes. As I understand there is no Rpc channel/controller for that so I have to implement all of that myself?
Activity
dcodeIO commentedon Nov 30, 2016
The wiki refers to protobuf.js 5.
Using protobuf.js 6, services are instances of the service class here. You can look them up, but there is not a lot of functionality within. You can, however, get the resolved request and response types of the respective methods.
There has been a bit of discussion previously to support use cases like grpc out of the box, but as I am not using services myself, I'd require some suggestions.
Initial take on runtime services, see #507
dcodeIO commentedon Nov 30, 2016
This commit adds the following API:
dcodeIO commentedon Dec 1, 2016
Feel free to reopen if there are still any issues or if you have a suggestion on how this should be implemented.
pronebird commentedon Dec 1, 2016
@dcodeIO thanks Daniel! Works like a charm!
One quick question, maybe I found a bug...:
So in RPC I do this:
Trying to debug:
I know it's silly that my messages are empty at the moment, but I guess it shouldn't crash anyway and it's good for QA:
dcodeIO commentedon Dec 1, 2016
So, your messages are length delimited, right? Did you specify that to Service.create?
Otherwise the length-bytes will be interpreted as message contents and throwing there is actually what it should do.
pronebird commentedon Dec 1, 2016
Well I am not sure whether message without any fields is delimited or not. But if I create RPC with
MailService.create(rpc, false, false)then it works fine. It feels like if there are no any fields in message then it shouldn't attempt to read it..dcodeIO commentedon Dec 1, 2016
Above you mentioned that, in one of your messages, there was a single zero byte:
That's why I assumed that it is a length-delimited empty message which of course throws if interpreted as a non-delimited message.
pronebird commentedon Dec 1, 2016
Yeah strange, that's how I call the method:
Not sure where 0-byte comes from. RequestType as is without any fields.
Update: if I specify that request is length delimited then rpc receives a buffer with one 0-byte, otherwise 0-length buffer is received.
dcodeIO commentedon Dec 1, 2016
Strange. in fact. The code encoding to a buffer is here: https://github.com/dcodeIO/protobuf.js/blob/master/src/service.js#L159
If shouldn't generate the zero byte, except if there is something true-ish specified for
requestDelimited.pronebird commentedon Dec 1, 2016
This is the source code if it helps ( bare bones)
mailservice.proto:
pronebird commentedon Dec 14, 2016
Hey, quick question:
so with Protobuf.js I can create RPC server in Node.js and that's pretty clear, however, how do I define an RPC client? Do I have to funnel data to remote RPC and pass back results somehow? I use ZeroMQ as transport to pass data between processes. As I understand there is no Rpc channel/controller for that so I have to implement all of that myself?
i.e:
dcodeIO commentedon Dec 14, 2016
There is an example in the README.
There is also a streaming rpc example here.
It basically works the same way on a client or a server. You just have to implement
rpcImplaccordingly.pronebird commentedon Dec 14, 2016
@dcodeIO thanks. I figured that it works on network level so it was easy to wire up everything!