Struct conjure_runtime::ClientFactory

source ·
pub struct ClientFactory<T = Complete>(/* private fields */);
Expand description

A factory type which can create clients that will live-reload in response to configuration updates.

Implementations§

source§

impl ClientFactory<ConfigStage>

source

pub fn builder() -> Self

Creates a new builder to construct a client factory.

source

pub fn config( self, config: Refreshable<ServicesConfig, Error> ) -> ClientFactory<UserAgentStage>

Sets the refreshable configuration used for service clients.

source§

impl ClientFactory<UserAgentStage>

source

pub fn user_agent(self, user_agent: UserAgent) -> ClientFactory

Sets the user agent sent by clients.

source§

impl ClientFactory

source

pub fn user_agent(self, user_agent: UserAgent) -> Self

Sets the user agent sent by clients.

source

pub fn get_user_agent(&self) -> &UserAgent

Returns the configured user agent.

source

pub fn client_qos(self, client_qos: ClientQos) -> Self

Sets clients’ rate limiting behavior.

Defaults to ClientQos::Enabled.

source

pub fn get_client_qos(&self) -> ClientQos

Returns the configured rate limiting behavior

source

pub fn server_qos(self, server_qos: ServerQos) -> Self

Sets clients’ behavior in response to a QoS error from the server.

Defaults to ServerQos::AutomaticRetry.

source

pub fn get_server_qos(&self) -> ServerQos

Returns the configured QoS behavior.

source

pub fn service_error(self, service_error: ServiceError) -> Self

Sets clients’ behavior in response to a service error from the server.

Defaults to ServiceError::WrapInNewError.

source

pub fn get_service_error(&self) -> ServiceError

Returns the configured service error behavior.

source

pub fn idempotency(self, idempotency: Idempotency) -> Self

Sets clients’ behavior to determine if a request is idempotent or not.

Only idempotent requests will be retried.

Defaults to Idempotency::ByMethod.

source

pub fn get_idempotency(&self) -> Idempotency

Returns the configured idempotency behavior.

source

pub fn node_selection_strategy( self, node_selection_strategy: NodeSelectionStrategy ) -> Self

Sets the clients’ strategy for selecting a node for a request.

Defaults to NodeSelectionStrategy::PinUntilError.

source

pub fn get_node_selection_strategy(&self) -> NodeSelectionStrategy

Returns the configured node selection strategy.

source

pub fn metrics(self, metrics: Arc<MetricRegistry>) -> Self

Sets the metric registry used to register client metrics.

Defaults to no registry.

source

pub fn get_metrics(&self) -> Option<&Arc<MetricRegistry>>

Returns the configured metrics registry.

source

pub fn host_metrics(self, host_metrics: Arc<HostMetricsRegistry>) -> Self

Sets the host metrics registry used to track host performance.

Defaults to no registry.

source

pub fn get_host_metrics(&self) -> Option<&Arc<HostMetricsRegistry>>

Returns the configured host metrics registry.

source

pub fn blocking_handle(self, blocking_handle: Handle) -> Self

Returns the Handle to the tokio Runtime to be used by blocking clients.

This has no effect on async clients.

Defaults to a conjure-runtime internal Runtime.

source

pub fn get_blocking_handle(&self) -> Option<&Handle>

Returns the configured blocking handle.

source

pub fn client<T>(&self, service: &str) -> Result<T, Error>
where T: AsyncService<Client>,

Creates a new client for the specified service.

The client’s configuration will automatically refresh to track changes in the factory’s ServicesConfig.

If no configuration is present for the specified service in the ServicesConfig, the client will immediately return an error for all requests.

The method can return any type implementing the conjure-http AsyncService trait. This notably includes all Conjure-generated client types as well as the conjure-runtime Client itself.

source

pub fn blocking_client<T>(&self, service: &str) -> Result<T, Error>
where T: Service<Client>,

Creates a new blocking client for the specified service.

The client’s configuration will automatically refresh to track changes in the factory’s ServicesConfig.

If no configuration is present for the specified service in the ServicesConfig, the client will immediately return an error for all requests.

The method can return any type implementing the conjure-http Service trait. This notably includes all Conjure-generated client types as well as the conjure-runtime blocking::Client itself.

source

pub fn per_host_clients<T>( &self, service: &str ) -> Result<Refreshable<PerHostClients<T>, Error>, Error>
where T: AsyncService<Client> + 'static + Sync + Send,

Creates a refreshable collection of clients, each corresponding to a separate replica of the service.

§Note

The client type T is assumed to be stateless - each instance will be recreated on every refresh.

source

pub fn blocking_per_host_clients<T>( &self, service: &str ) -> Result<Refreshable<PerHostClients<T>, Error>, Error>
where T: Service<Client> + 'static + Sync + Send,

Creates a refreshable collection of blocking clients, each corresponding to a separate replica of the service.

§Note

The client type T is assumed to be stateless - each instance will be recreated on every refresh.

Trait Implementations§

source§

impl<T: Clone> Clone for ClientFactory<T>

source§

fn clone(&self) -> ClientFactory<T>

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
source§

impl Default for ClientFactory<ConfigStage>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ClientFactory<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ClientFactory<T>
where T: RefUnwindSafe,

§

impl<T> Send for ClientFactory<T>
where T: Send,

§

impl<T> Sync for ClientFactory<T>
where T: Sync,

§

impl<T> Unpin for ClientFactory<T>
where T: Unpin,

§

impl<T> UnwindSafe for ClientFactory<T>
where T: UnwindSafe,

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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