pub struct Client { /* private fields */ }
Expand description
A service discovery client that looks up URL information based on URLs, headers, and methods.
Clients use a shared in-memory cache to keep data warm so that a request never has to block on a remote service.
Clients are cheaply cloneable, and should be cloned to create multiple clients that share the same in-memory cache.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn build(
address: String,
node_id: String,
cluster: String,
) -> Result<Self, Box<dyn Error>>
pub async fn build( address: String, node_id: String, cluster: String, ) -> Result<Self, Box<dyn Error>>
Build a new dynamic client, spawning a new ADS client in the background.
This method creates a new ADS client and ADS connection. Dynamic data will not be shared with existing clients. To create a client that shares data with existing clients, clone an existing client.
This function assumes that you’re currently running the context of a
tokio
runtime and spawns background work on a tokio executor.
Sourcepub fn with_static_config(
self,
routes: Vec<Route>,
backends: Vec<Backend>,
) -> Client
pub fn with_static_config( self, routes: Vec<Route>, backends: Vec<Backend>, ) -> Client
Build a client with static configuration. This client will use the passed configuration to resolve routes and backends, but will still fetch endpoints dynamically.
This method will panic if the client being cloned is fully static. To convert a static client to a client that uses dynamic config, create a new client.
Sourcepub fn with_static_endpoints(
self,
routes: Vec<Route>,
backends: Vec<Backend>,
) -> Client
pub fn with_static_endpoints( self, routes: Vec<Route>, backends: Vec<Backend>, ) -> Client
Construct a client that uses fully static configuration and does not connect to a control plane at all.
This is intended to be used to test configuration in controlled settings or to use Junction an offline mode. Once a client has been converted to fully static, it’s not possible to convert it back to using dynamic discovery data.
Sourcepub async fn resolve_http(
&self,
method: &Method,
url: &Url,
headers: &HeaderMap,
) -> Result<Endpoint>
pub async fn resolve_http( &self, method: &Method, url: &Url, headers: &HeaderMap, ) -> Result<Endpoint>
Resolve an HTTP method, URL, and headers into an Endpoint.
This is the main entry point into Junction. When building an integration, use this method to fetch an initial endpoint. After making an initial request, use report_status to report the status of the request and to retry on failure.
The endpoint returned from this method should be a complete description of how to make an HTTP request - it contains the IP address to use, the full URL and hostname, the complete set of headers, and retry and timeout policy the client should use to make a request.
Sourcepub async fn report_status(
&self,
endpoint: Endpoint,
response: HttpResult,
) -> Result<Endpoint>
pub async fn report_status( &self, endpoint: Endpoint, response: HttpResult, ) -> Result<Endpoint>
Report the status of an externally made HTTP request made against an
Endpoint returned from resolve_http
.
If retrying the response is appropriate, a new Endpoint will be returned
with updated address and host info set - calling resolve_http
to start
a retry attempt will drop request history and may result in too many
retries.
If a retry is not appropriate, the returned Endpoint will have updated history information, but request details will remain the same. Clients may use that value for status or error reporting.
Sourcepub async fn resolve_route(
&self,
request: HttpRequest<'_>,
deadline: Option<Instant>,
) -> Result<ResolvedRoute>
pub async fn resolve_route( &self, request: HttpRequest<'_>, deadline: Option<Instant>, ) -> Result<ResolvedRoute>
Resolve an HTTP method, URL, and headers to a target backend, returning
the Route that matched, the index of the rule that matched, and the
backend that was chosen - to make backend choice determinstic with
multiple backends, set the JUNCTION_SEED
environment variable.
This is a lower-level method that only performs the Route matching part of resolution. It’s intended for debugging or querying a client for specific information. For everyday use, prefer Client::resolve_http.
Sourcepub async fn select_endpoint(
&self,
backend: &BackendId,
ctx: LbContext<'_>,
deadline: Option<Instant>,
) -> Result<SelectedEndpoint>
pub async fn select_endpoint( &self, backend: &BackendId, ctx: LbContext<'_>, deadline: Option<Instant>, ) -> Result<SelectedEndpoint>
Select an endpoint address for this backend from the set of currently available endpoints.
This is a lower level method that only performs part of route resolution, and is intended for debugging and testing. For everyday use, prefer Client::resolve_http.
Sourcepub async fn csds_server(self, port: u16) -> Result<(), Error>
pub async fn csds_server(self, port: u16) -> Result<(), Error>
Start a gRPC CSDS server on the given port. To run the server, you must
await
this future.
For static clients, this does nothing.
Sourcepub fn dump_xds(&self, not_found: bool) -> Vec<XdsConfig>
pub fn dump_xds(&self, not_found: bool) -> Vec<XdsConfig>
Dump the client’s current cache of xDS resources, as fetched from the config server.
This is a programmatic view of the same data that you can fetch over gRPC by starting a Client::csds_server.
Sourcepub fn dump_xds_errors(&self) -> Vec<XdsConfig>
pub fn dump_xds_errors(&self) -> Vec<XdsConfig>
Dump xDS resources that failed to update. This is a view of the data returned by Client::dump_xds that only contains resources with errors.
Sourcepub fn dump_routes(&self) -> Vec<Arc<Route>>
pub fn dump_routes(&self) -> Vec<Arc<Route>>
Dump the Client’s current table of [Route]s, merging together any default routes and remotely fetched routes the same way the client would when resolving endpoints.
Sourcepub fn dump_backends(&self) -> Vec<Arc<BackendLb>>
pub fn dump_backends(&self) -> Vec<Arc<BackendLb>>
Dump the Client’s current table of BackendLbs, merging together any default configuration and remotely fetched config the same way the client would when resolving endpoints.
Sourcepub fn dump_endpoints(&self, backend: &BackendId) -> Option<EndpointIter>
pub fn dump_endpoints(&self, backend: &BackendId) -> Option<EndpointIter>
Return the endpoints currently in cache for this backend.
The returned endpoints are a snapshot of what is currently in cache and will not update as new discovery information is pushed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request