tonic
tonic copied to clipboard
Ability to pass customized connector for channel with multiple endpoints
Feature Request
Crates
tonic
https://github.com/hyperium/tonic/tree/master/tonic/src/transport/channel
Motivation
For channel with a single endpoint, we can create the channel with customized connector by calling Endpoint::connect_with_connector.
However, we are not able to pass a customized connector for channel with multiple endpoints created from balance_xxx methods. Reasons are as followed.
Currently we have several public methods to create a balanced channel: balance_list, balance_channel and balance_channel_with_executor, where balance_list is based on balance_channel and balance_channel is based on balance_channel_with_executor. The balance_channel_with_executor is based on the balance method. The balance method accepts a parameter that implements Discover<Service = Connection>, which provides the ability to pass some customized logic. However, the balance method is private to crate, and cannot be used externally. When balance_channel_with_executor calls balance, it pass the DynamicServiceStream as the parameter that implements Discover<Service = Connection>. But in the poll_next of DynamicServiceStream, it creates all the connection from hyper::client::connect::HttpConnector, which is hard-coded and cannot be customized.
Proposal
Make the following changes:
- Turn
DynamicServiceStreamfrompub(crate)topub. Meanwhile, add new generic parameterM: MakeConnection<Uri> + From<Endpoint>to DynamicServiceStream. ImplementsInto<hyper::client::connect::HttpConnector>forEndpointso thathyper::client::connect::HttpConnectorsatisfies the trait bound ofM. - Turn the
balancemethod frompub(crate)topub.
Alternatives
I am willing to make such refactor if needed.