pub struct HttpPool { /* private fields */ }tls-rustls only.Expand description
One set of HTTP connections that many clients share.
Every ClientBuilder builds a connection pool of
its own, so a program that holds a client for each of fifty peers holds
fifty pools, and two clients that call the same host share nothing. An
HttpPool is a pool you build once and give to as many clients as you
like with ClientBuilder::with_pool;
they then reuse each other’s connections. ADR 0032 has the reasoning.
use std::time::Duration;
use a2a_protocol_client::{ClientBuilder, HttpPool};
let pool = HttpPool::builder()
.with_max_connection_lifetime(Duration::from_secs(600))
.with_http2_keep_alive(Duration::from_secs(30), Duration::from_secs(10))
.build()?;
let alpha = ClientBuilder::new("https://alpha.example").with_pool(&pool).build()?;
let beta = ClientBuilder::new("https://beta.example").with_pool(&pool).build()?;§What a pool owns, and what it refuses to mix
A pool has exactly one TLS identity (the roots it trusts and the client
certificate it presents), one proxy route (read from the environment when
the pool is built) and one set of timeouts. Connections for two TLS
identities cannot be mixed, because they cannot be put in one pool: a
client that sets its own TLS configuration or connect timeout and is
given a pool fails at build() and names the setting, rather than having
the setting ignored.
A pool is the HTTP bindings’ (JSON-RPC and HTTP+JSON) and card discovery’s. gRPC and WebSocket clients keep the connections they have.
§What the defaults are
The same as a client without a pool: idle connections are closed after 50 s, no HTTP/2 PING is sent, connections are not recycled, and the number of idle connections per host is not limited. Each is opt-in. Nothing changes for a client that is not given a pool.
§Recycling connections
with_max_connection_lifetime
makes the pool start using new connections once the current ones are that
old (spread by up to 10% either way, so a fleet does not renew together).
In-flight calls and open streams are not cut. This is what spreads a
client’s calls over the replicas behind a layer-4 load balancer that
pins a long-lived HTTP/2 connection to one of them.
§Per-origin state (ADR 0050)
A pool keeps, for each origin its clients call (scheme, host and port), the calls in flight and how the origin has been doing. Three policies use it, each off unless asked for, and each shared by every client of the pool:
with_ejection: a circuit breaker. An origin that fails a number of calls in a row is refused withClientError::CircuitOpenuntil its ejection ends, and then one call probes it. A balanced client (with_balancing) takes it out of rotation instead.with_max_in_flight_per_origin: a call that would exceed the cap is refused withClientError::TooManyPendingRequests, whichever client makes it.with_retry_budget: retries towards one origin, from every client with a retry policy, are paid from one budget.
origins shows the state.
Cloning is cheap and shares the connections.
Implementations§
Source§impl HttpPool
impl HttpPool
Sourcepub fn builder() -> HttpPoolBuilder
pub fn builder() -> HttpPoolBuilder
A builder with the defaults.
The process-wide pool, for a caller who wants one line.
Safe defaults: Mozilla’s roots plus SSL_CERT_FILE / SSL_CERT_DIR,
the proxy variables, certificate verification on, and no way to turn
verification off. It is created on first use, with the environment as
it is then, and every later call returns a handle to the same pool.
Sourcepub fn origins(&self) -> Vec<OriginSnapshot>
pub fn origins(&self) -> Vec<OriginSnapshot>
Every origin this pool keeps state for, sorted by origin: calls in flight, and whether it is ejected. Empty for a pool without per-origin policies and without balanced clients.
Sourcepub fn is_same_pool(&self, other: &HttpPool) -> bool
pub fn is_same_pool(&self, other: &HttpPool) -> bool
The pool behind self and other is the same one.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for HttpPool
impl !UnwindSafe for HttpPool
impl Forget for HttpPool
impl Freeze for HttpPool
impl Move for HttpPool
impl Send for HttpPool
impl Sync for HttpPool
impl Unpin for HttpPool
impl UnsafeUnpin for HttpPool
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].