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 DynamicServiceStream from pub(crate) to pub. Meanwhile, add new generic parameter M: MakeConnection<Uri> + From<Endpoint> to DynamicServiceStream. Implements Into<hyper::client::connect::HttpConnector> for Endpoint so that hyper::client::connect::HttpConnector satisfies the trait bound of M.
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
andbalance_channel_with_executor
, wherebalance_list
is based onbalance_channel
andbalance_channel
is based onbalance_channel_with_executor
. Thebalance_channel_with_executor
is based on thebalance
method. Thebalance
method accepts a parameter that implementsDiscover<Service = Connection>
, which provides the ability to pass some customized logic. However, thebalance
method is private to crate, and cannot be used externally. Whenbalance_channel_with_executor
callsbalance
, it pass theDynamicServiceStream
as the parameter that implementsDiscover<Service = Connection>
. But in thepoll_next
ofDynamicServiceStream
, it creates all the connection fromhyper::client::connect::HttpConnector
, which is hard-coded and cannot be customized.Proposal
Make the following changes:
DynamicServiceStream
frompub(crate)
topub
. Meanwhile, add new generic parameterM: MakeConnection<Uri> + From<Endpoint>
to DynamicServiceStream. ImplementsInto<hyper::client::connect::HttpConnector>
forEndpoint
so thathyper::client::connect::HttpConnector
satisfies the trait bound ofM
.balance
method frompub(crate)
topub
.Alternatives