Updating host to be routed to by an interceptor

17 views
Skip to first unread message

Sivabalan

unread,
Jul 20, 2020, 1:21:46 PM7/20/20
to grp...@googlegroups.com
Hi folks,
    Let's say I have an interceptor which dictates which host to route the application request to based on some business logic. In okhttp client, it is straightforward by re-creating the request with a new host url. From my understanding of grpc, a channel/managedchannel is tightly coupled with the host and so(I do understand we could leverage dns resolver etc, but if not for that), an interceptor can't really update the host once the channel is created. If the request has to be routed to a different host compared to what current channel was instantiated, a new channel has to be instantiated, followed by adding all interceptors again and then start serving requests. 

Is my understanding correct? If there is any workaround to update the host dynamically by one of the interceptors. 

--
Regards,
-Sivabalan

Eric Anderson

unread,
Jul 20, 2020, 3:15:29 PM7/20/20
to Sivabalan, grpc-io
Interceptors are not great for routing to different backends. That'd be the job of a LoadBalancer. For your case, it sounds like you could also just create a Channel implementation instead of a ClientInterceptor. It could create multiple ManagedChannels and decide which to use based on the application logic.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CABeKz3md8b-UQvMLcTqVyXt%3DAQP1ooTPVte93%3D4bOFffgEcShg%40mail.gmail.com.

Sivabalan

unread,
Jul 21, 2020, 11:19:25 AM7/21/20
to Eric Anderson, grpc-io
cool. Pretty much what I was planning to do, but just wanted to confirm there are no other options. thanks for your help. 

--
Regards,
-Sivabalan
Reply all
Reply to author
Forward
0 new messages