ContextBuilder

Struct ContextBuilder 

Source
pub struct ContextBuilder<PREFIX: ToAssign> { /* private fields */ }
Expand description

A builder for Context. Beyond what can be set by standard constructor, it allows tweaking pending publish ack backpressure settings.

§Examples

let client = async_nats::connect("demo.nats.io").await?;
let context = ContextBuilder::new()
    .timeout(Duration::from_secs(5))
    .api_prefix("MY.JS.API")
    .max_ack_inflight(1000)
    .build(client);

Implementations§

Source§

impl ContextBuilder<Yes>

Source

pub fn new() -> ContextBuilder<Yes>

Create a new ContextBuilder with default settings.

Source§

impl ContextBuilder<Yes>

Source

pub fn api_prefix<T: Into<String>>(self, prefix: T) -> ContextBuilder<No>

Set the prefix for the JetStream API.

Source

pub fn domain<T: Into<String>>(self, domain: T) -> ContextBuilder<No>

Set the domain for the JetStream API. Domain is the middle part of standard API prefix: $JS.{domain}.API.

Source§

impl<PREFIX> ContextBuilder<PREFIX>
where PREFIX: ToAssign,

Source

pub fn timeout(self, timeout: Duration) -> ContextBuilder<Yes>
where Yes: ToAssign,

Set the timeout for all JetStream API requests.

Source

pub fn ack_timeout(self, ack_timeout: Duration) -> ContextBuilder<Yes>
where Yes: ToAssign,

Sets the maximum time client waits for acks from the server when default backpressure is used.

Source

pub fn max_ack_inflight(self, capacity: usize) -> ContextBuilder<Yes>
where Yes: ToAssign,

Sets the maximum number of pending acks that can be in flight at any given time. If limit is reached, publish throws an error by default, or waits if backpressure is enabled.

Source

pub fn backpressure_on_inflight(self, enabled: bool) -> ContextBuilder<Yes>
where Yes: ToAssign,

Enable or disable backpressure when max inflight acks is reached. When enabled, publish will wait for permits to become available instead of returning an error. Default is false (errors on max inflight).

Source

pub fn concurrency_limit(self, limit: Option<usize>) -> ContextBuilder<Yes>
where Yes: ToAssign,

Sets the concurrency limit for the ack handler task. This might be useful in scenarios where Tokio runtime is under heavy load.

Source

pub fn build(self, client: Client) -> Context

Build the Context with the given settings.

Trait Implementations§

Source§

impl Default for ContextBuilder<Yes>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<PREFIX> Freeze for ContextBuilder<PREFIX>

§

impl<PREFIX> RefUnwindSafe for ContextBuilder<PREFIX>
where PREFIX: RefUnwindSafe,

§

impl<PREFIX> Send for ContextBuilder<PREFIX>
where PREFIX: Send,

§

impl<PREFIX> Sync for ContextBuilder<PREFIX>
where PREFIX: Sync,

§

impl<PREFIX> Unpin for ContextBuilder<PREFIX>
where PREFIX: Unpin,

§

impl<PREFIX> UnwindSafe for ContextBuilder<PREFIX>
where PREFIX: 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> Same for T

Source§

type Output = T

Should always be Self
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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,