Struct junction_core::Client
source · 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 client, spawning a new ADS client in the background.
This method creates a new ADS client and ADS connection. Data fetched over ADS won’t be shared with existing clients. To create a client that shares with an existing cache, call Client::clone on an existing client.
This function assumes that you’re currently running the context of a
tokio
runtime and spawns background tasks.
sourcepub fn with_defaults(
self,
default_routes: Vec<Route>,
default_backends: Vec<Backend>,
) -> Result<Client>
pub fn with_defaults( self, default_routes: Vec<Route>, default_backends: Vec<Backend>, ) -> Result<Client>
Set default routes
and backends
for this client.
The client will continue to use the same dynamic configuration cache it previously used.
sourcepub fn csds_server(&self, port: u16) -> impl Future<Output = Result<(), Error>>
pub fn csds_server(&self, port: u16) -> impl Future<Output = Result<(), Error>>
Start a gRPC CSDS server on the given port.
To run the server, you must await
this future.
sourcepub fn dump_xds(&self) -> impl Iterator<Item = XdsConfig> + '_
pub fn dump_xds(&self) -> impl Iterator<Item = 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_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 resolve_routes(
&self,
config_mode: ConfigMode,
request: HttpRequest<'_>,
) -> Result<ResolvedRoute>
pub fn resolve_routes( &self, config_mode: ConfigMode, request: HttpRequest<'_>, ) -> 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 the [Target] that was selected.
This is a lower-level method that only performs the Route matching half of full resolution. It’s intended for debugging or querying a client for specific information. For everyday use, prefer Client::resolve_http.
sourcepub fn resolve_http(
&mut self,
method: &Method,
url: &Url,
headers: &HeaderMap,
) -> Result<Vec<Endpoint>>
pub fn resolve_http( &mut self, method: &Method, url: &Url, headers: &HeaderMap, ) -> Result<Vec<Endpoint>>
Resolve an HTTP method, URL, and headers into a set of Endpoints.
When multiple endpoints are returned, a client should send traffic to ALL of the returned endpoints because the routing policy specified that traffic should be mirrored.
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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