Skip to main content

HttpPool

Struct HttpPool 

Source
pub struct HttpPool { /* private fields */ }
Available on crate feature 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:

origins shows the state.

Cloning is cheap and shares the connections.

Implementations§

Source§

impl HttpPool

Source

pub fn builder() -> HttpPoolBuilder

A builder with the defaults.

Source

pub fn shared() -> HttpPool

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.

Source

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.

Source

pub fn is_same_pool(&self, other: &HttpPool) -> bool

The pool behind self and other is the same one.

Trait Implementations§

Source§

impl Clone for HttpPool

Source§

fn clone(&self) -> HttpPool

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

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

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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