grpc bidirectional stream with different messages

2,871 views
Skip to first unread message

vija...@gmail.com

unread,
Feb 7, 2017, 4:21:03 AM2/7/17
to grpc.io
hi,

Newbie to grpc and not sure if following is possible.
Need to implement client->server processes which can work with bidirectional streaming support. Additionally want to check it is possible to stream different messages/responses from client/server after connection is established.

So far all the examples i searched show ability of sending one message request/response behavior.

Client----->Server
connectReq()--->
                     <-----connectRes.

after connection is established, any different request/response below may happen.

cliMsg1------->
      <-----------cliMsgRes1


             <--------serverMsgReq1
serverMsgRes1---->  

Thx,
Vijay

Ken Payson

unread,
Feb 7, 2017, 5:29:33 AM2/7/17
to vija...@gmail.com, grpc.io
If you are using protobufs, the easiest way to approach this would be to use the oneof feature.

Oneof allows you to specify a request type that is "one of" connectReq/cliMsg/serverMsgRes.

Likewise, your response type can be specified as "one of" connectRes/cliMsgRes/serverMsgReq.


--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/60f82252-313d-4db3-bbf2-abc4a758a7f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vija...@gmail.com

unread,
Feb 7, 2017, 5:42:29 AM2/7/17
to grpc.io, vija...@gmail.com
Thanks, let me try it.
Vijay


On Tuesday, February 7, 2017 at 3:59:33 PM UTC+5:30, Ken Payson wrote:
If you are using protobufs, the easiest way to approach this would be to use the oneof feature.

Oneof allows you to specify a request type that is "one of" connectReq/cliMsg/serverMsgRes.

Likewise, your response type can be specified as "one of" connectRes/cliMsgRes/serverMsgReq.

On Tue, Feb 7, 2017 at 1:21 AM, <vija...@gmail.com> wrote:
hi,

Newbie to grpc and not sure if following is possible.
Need to implement client->server processes which can work with bidirectional streaming support. Additionally want to check it is possible to stream different messages/responses from client/server after connection is established.

So far all the examples i searched show ability of sending one message request/response behavior.

Client----->Server
connectReq()--->
                     <-----connectRes.

after connection is established, any different request/response below may happen.

cliMsg1------->
      <-----------cliMsgRes1


             <--------serverMsgReq1
serverMsgRes1---->  

Thx,
Vijay

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

jing...@dialpad.com

unread,
Feb 13, 2017, 5:28:53 PM2/13/17
to grpc.io, vija...@gmail.com
HI Vijay,

It seems it was not a very scalable solution. If we have a huge number of different message definition that needs to be fit into the same stream response message, it would be a big waste to just loop through the messages and try to get the right pb message type to decode it. Or do we have any good solution for this already? 


Thanks,
Justin

jing...@dialpad.com

unread,
Feb 13, 2017, 5:30:11 PM2/13/17
to grpc.io, vija...@gmail.com
Hi Ken,

It seems it was not a very scalable solution. If we have a huge number of different message definition that needs to be fit into the same stream response message, it would be a big waste to just loop through the messages and try to get the right pb message type to decode it. Or do we have any good solution for this already? 


Thanks,
Justin

On Tuesday, February 7, 2017 at 2:29:33 AM UTC-8, Ken Payson wrote:
If you are using protobufs, the easiest way to approach this would be to use the oneof feature.

Oneof allows you to specify a request type that is "one of" connectReq/cliMsg/serverMsgRes.

Likewise, your response type can be specified as "one of" connectRes/cliMsgRes/serverMsgReq.

On Tue, Feb 7, 2017 at 1:21 AM, <vija...@gmail.com> wrote:
hi,

Newbie to grpc and not sure if following is possible.
Need to implement client->server processes which can work with bidirectional streaming support. Additionally want to check it is possible to stream different messages/responses from client/server after connection is established.

So far all the examples i searched show ability of sending one message request/response behavior.

Client----->Server
connectReq()--->
                     <-----connectRes.

after connection is established, any different request/response below may happen.

cliMsg1------->
      <-----------cliMsgRes1


             <--------serverMsgReq1
serverMsgRes1---->  

Thx,
Vijay

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

Arpit Baldeva

unread,
Feb 13, 2017, 5:34:11 PM2/13/17
to grpc.io, vija...@gmail.com, jing...@dialpad.com
You don't need to loop through all the message types. Protobuf generates a 'case' method which would tell you the case/type of the message. You should use a switch statement in your code using that generated method.
Reply all
Reply to author
Forward
0 new messages