relaying grpc calls

236 views
Skip to first unread message

dan.b...@huawei.com

unread,
Jan 13, 2019, 3:52:29 AM1/13/19
to grpc.io
Consider a grpc client C, and servers L & R (local & remote). 
Servers L & R are connected. Client C can reach only server L.

Client C needs to send a request to server R. 

Can I create a "relay_request" message that server L will support, where the body is the request to send to server R? (also dealing with relaying the reply)

Is there anything better I can do for such a scenario?

Thanks,
Dan

Carl Mastrangelo

unread,
Jan 14, 2019, 2:40:03 PM1/14/19
to grpc.io
Yes, this is possible.  You'll need to implement some unpacking scheme on L, but it can then forward the raw bytes of the request.   Note that if you are  using Proto, you may not be able to use all the generated stub code.   If C, L, and R all know about the same message types, then you can use the proto stubs.

Note also that the headers will need to be captured from C->L, and the response trailers from R->L.    If you wanted this to be "delayed" in any way, it may get more tricky.  

Eric Anderson

unread,
Jan 15, 2019, 10:57:43 AM1/15/19
to Carl Mastrangelo, grpc.io
It sounds like L is just a proxy in that case. You use the relay_request if that feels natural to you. You can also do "L7 load balancing" by relaying requests at the HTTP/2 or gRPC level. I have made an example service-agnostic gRPC proxy in Java. My example proxies everything, but it is possible to also proxy only services or methods. I think you can do semi-similar things in other languages, although the difficulty may vary.

--
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.
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/fc766ee0-a9b7-46f2-bbd5-024c1fba3e1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dan.b...@huawei.com

unread,
Jan 16, 2019, 2:13:17 AM1/16/19
to grpc.io
That is half correct ;-)  in my scenario L is also a service provider, but it is also a proxy for requests I need to send to R. 
I was not aware of relay_request. I'll definitely check it out, as well as your service-agnostic example.

Thanks,
Dan

dan.b...@huawei.com

unread,
Jan 16, 2019, 2:51:06 AM1/16/19
to grpc.io
@Eric, I did not find any mention of relay_request in the documentation. However, I *loved* the service-agnostic proxy. 
While reading the code it dawned on me that I can run an instance of this proxy on L, and the client will simply send to port X to get to L, and to port Y to get to R.
I'm going to give this a try.

Thanks a lot!
Dan

Eric Anderson

unread,
Jan 22, 2019, 5:30:09 PM1/22/19
to dan.b...@huawei.com, grpc.io
I wasn't saying "relay_request" was a "thing". I just used the terminology because you used the terminology.

Glad the service-agnostic proxy looks good. I would encourage you to consider having a single port and choosing the service-agnostic proxy for only certain services; it removes the client from having to know what goes where.

Hakim Kahlouche

unread,
May 7, 2023, 9:50:04 PM5/7/23
to grpc.io
@Eric: I tried to access the service-agnostic grpc proxy link below, but I am getting 404 (not found):
Please let me know if there is a new link for it.

Thanks

Larry Safran

unread,
May 15, 2023, 9:07:21 PM5/15/23
to grpc.io
Instead of looking for it in Eric's personal repo, you can now find it in the master repository:  https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/grpcproxy/GrpcProxy.java
Reply all
Reply to author
Forward
0 new messages