how to define a one-way rpc message?

7,603 views
Skip to first unread message

phelyks

unread,
Feb 3, 2010, 10:24:28 AM2/3/10
to Protocol Buffers
Hi all!

I am currently playing around with protocol buffers and now was
looking closer at the rpc code that can be generated by it.

But I am a bit confused. I did not find a way how to create rpc
messages that do not define a reply.
is there a way to create one-way rpc calls in protocol buffers?

An example what i would like would be that:
service myService
{
rpc Echo (EchoParam) returns (EchoReply) ;
rpc OneWayWithoutResponse(ParamsToSend);
}


the only workaround that i can think of would be creating a "Void"
message that is declared as the answer and the rpc implementation to
then "ignore" those.

like this:

message Void
{
}

service myService
{
rpc OneWayWithoutResponse(FirmwareEvent) returns (Void);
}

is there a way how i can avoid this workaround?

cheers phelyks

Jason Hsueh

unread,
Feb 3, 2010, 1:11:04 PM2/3/10
to phelyks, Protocol Buffers
No, each method needs to specify a response type. The workaround you suggested is the way to go. However, you may want to define your own message that is empty (rather than a generic Void that might get reused by other services) so that you can extend your message in the future.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Adam Vartanian

unread,
Feb 3, 2010, 1:14:08 PM2/3/10
to phelyks, Protocol Buffers
> the only workaround that i can think of would be creating a "Void"
> message that is declared as the answer and the rpc implementation to
> then "ignore" those.
>
> like this:
>
> message Void
> {
> }
>
> service myService
> {
> rpc OneWayWithoutResponse(FirmwareEvent) returns (Void);
> }
>
> is there a way how i can avoid this workaround?

Nope, that's the way it's done. Generally speaking, it's recommended
that you create a separate empty response message for each service
method instead of a generic Void message you return from many methods,
so that if you ever do decide to send a response back you don't have
to switch message types, but otherwise that's the usual way it's done.

- Adam

Felix Schmutz

unread,
Feb 4, 2010, 5:01:08 AM2/4/10
to Adam Vartanian, jas...@google.com, Protocol Buffers
okay, understood.

many thanks for the hint guys.

-phelyks
Reply all
Reply to author
Forward
0 new messages