pub trait EndpointsProvider: DynClone + Debug + Send + Sync {
    fn get_endpoints<'e>(
        &'e self,
        options: GetOptions<'_>
    ) -> ApiResult<Cow<'e, Endpoints>>; fn async_get_endpoints<'a>(
        &'a self,
        options: GetOptions<'a>
    ) -> Pin<Box<dyn Future<Output = ApiResult<Cow<'a, Endpoints>>> + Send + 'a>> { ... } }
Expand description

终端地址列表获取接口

同时提供阻塞获取接口和异步获取接口,异步获取接口则需要启用 async 功能

Required Methods§

获取终端地址列表

该方法的异步版本为 Self::async_get_endpoints

Provided Methods§

Available on crate feature async only.

异步获取终端地址列表

Examples found in repository?
src/client/call/request_call.rs (line 87)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
pub(in super::super) async fn async_request_call<E: EndpointsProvider>(
    request: AsyncInnerRequest<'_, E>,
) -> ApiResult<AsyncResponse> {
    let (parts, mut body, into_endpoints, service_name, extensions) = request.split();
    let options = EndpointsGetOptions::builder().service_names(service_name).build();
    let endpoints = into_endpoints.async_get_endpoints(options).await?;
    let mut tried_ips = IpAddrsSet::default();
    let mut retried = RetriedStatsInfo::default();

    return match try_preferred_endpoints(
        endpoints.preferred(),
        &parts,
        &mut body,
        extensions,
        &mut tried_ips,
        &mut retried,
    )
    .await
    {
        Ok(response) => Ok(response),
        Err(err)
            if err.retry_decision() == RetryDecision::TryAlternativeEndpoints
                && !endpoints.alternative().is_empty() =>
        {
            let (_, extensions) = err.split();
            retried.switch_to_alternative_endpoints();
            debug!("Switch to alternative endpoints");
            try_alternative_endpoints(
                endpoints.alternative(),
                &parts,
                &mut body,
                extensions,
                &mut tried_ips,
                &mut retried,
            )
            .await
        }
        Err(err) => Err(err.into_response_error()),
    };

    async fn try_preferred_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> Result<AsyncResponse, TryErrorWithExtensions> {
        async_try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, true).await
    }

    async fn try_alternative_endpoints(
        endpoints: &[Endpoint],
        parts: &InnerRequestParts<'_>,
        body: &mut AsyncRequestBody<'_>,
        extensions: Extensions,
        tried_ips: &mut IpAddrsSet,
        retried: &mut RetriedStatsInfo,
    ) -> ApiResult<AsyncResponse> {
        async_try_endpoints(endpoints, parts, body, extensions, tried_ips, retried, false)
            .await
            .map_err(|err| err.into_response_error())
    }
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Implementations on Foreign Types§

Available on crate feature async only.
Available on crate feature async only.
Available on crate feature async only.
Available on crate feature async only.
Available on crate feature async only.

Implementors§