junction_core

Struct 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more