Skip to main content

XdsServerBuilder

Struct XdsServerBuilder 

Source
pub struct XdsServerBuilder { /* private fields */ }
Expand description

Builder for creating an XdsServer.

§Example

use xds_server::XdsServerBuilder;
use xds_cache::ShardedCache;
use std::sync::Arc;
use std::time::Duration;

let cache = Arc::new(ShardedCache::new());
let _server = XdsServerBuilder::new()
    .cache(cache)
    .enable_sotw()
    .enable_delta()
    .enable_health_check()
    .enable_metrics()
    .graceful_shutdown(Duration::from_secs(30))
    .max_concurrent_streams(200)
    .build()?;

Implementations§

Source§

impl XdsServerBuilder

Source

pub fn new() -> Self

Create a new server builder.

Source

pub fn cache(self, cache: Arc<ShardedCache>) -> Self

Set the cache to use.

This is required.

Source

pub fn registry(self, registry: Arc<ResourceRegistry>) -> Self

Set the resource registry.

If not set, a default registry will be created.

Source

pub fn enable_sotw(self) -> Self

Enable State-of-the-World protocol (enabled by default).

Source

pub fn disable_sotw(self) -> Self

Disable State-of-the-World protocol.

Source

pub fn enable_delta(self) -> Self

Enable Delta xDS protocol.

Source

pub fn disable_delta(self) -> Self

Disable Delta xDS protocol.

Source

pub fn max_concurrent_streams(self, max: u32) -> Self

Set maximum concurrent streams per connection.

Source

pub fn keepalive_interval(self, interval: Duration) -> Self

Set keepalive interval.

Source

pub fn keepalive_timeout(self, timeout: Duration) -> Self

Set keepalive timeout.

Source

pub fn max_request_size(self, size: usize) -> Self

Set maximum request size in bytes.

Source

pub fn enable_compression(self) -> Self

Enable gzip compression for responses.

Source

pub fn compression(self, config: CompressionConfig) -> Self

Set custom compression configuration.

Source

pub fn enable_health_check(self) -> Self

Enable gRPC health checking (enabled by default).

Source

pub fn disable_health_check(self) -> Self

Disable gRPC health checking.

Source

pub fn enable_metrics(self) -> Self

Enable Prometheus metrics (enabled by default).

Source

pub fn disable_metrics(self) -> Self

Disable Prometheus metrics.

Source

pub fn enable_connection_tracking(self) -> Self

Enable connection tracking (enabled by default).

Source

pub fn disable_connection_tracking(self) -> Self

Disable connection tracking.

Source

pub fn graceful_shutdown(self, grace_period: Duration) -> Self

Set the graceful shutdown grace period.

During shutdown, the server will:

  1. Stop accepting new connections
  2. Mark health as not serving
  3. Wait for existing connections to drain (up to grace period)
  4. Force close remaining connections
Source

pub fn connection_limits(self, limits: ConnectionLimits) -> Self

Set connection limits.

Controls maximum total connections and per-IP limits.

Source

pub fn max_connections(self, max: u64) -> Self

Set maximum total connections.

Source

pub fn max_connections_per_ip(self, max: u64) -> Self

Set maximum connections per IP address.

Source

pub fn tls_config(self, config: ServerTlsConfig) -> Self

Available on crate feature tls only.

Configure TLS (and optionally mTLS) for the gRPC server.

Pass a tonic::transport::ServerTlsConfig populated with the server identity (identity()) and, for mTLS, the client CA (client_ca_root() / client_auth_optional()).

§Example
use tonic::transport::{Identity, ServerTlsConfig};

let cert = std::fs::read("server.pem")?;
let key = std::fs::read("server.key")?;
let tls = ServerTlsConfig::new().identity(Identity::from_pem(cert, key));

let _server = XdsServerBuilder::new()
    .cache(cache)
    .tls_config(tls)
    .build()?;

Available only when the tls feature is enabled.

Source

pub fn build(self) -> XdsResult<XdsServer>

Build the server.

§Errors

Returns an error if:

  • No cache was provided
  • Neither SotW nor Delta is enabled

Trait Implementations§

Source§

impl Debug for XdsServerBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for XdsServerBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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

Source§

fn into_request(self) -> Request<T>

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

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

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