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>
impl ContextBuilder<Yes>
Sourcepub fn new() -> ContextBuilder<Yes>
pub fn new() -> ContextBuilder<Yes>
Create a new ContextBuilder with default settings.
Source§impl ContextBuilder<Yes>
impl ContextBuilder<Yes>
Sourcepub fn api_prefix<T: Into<String>>(self, prefix: T) -> ContextBuilder<No>
pub fn api_prefix<T: Into<String>>(self, prefix: T) -> ContextBuilder<No>
Set the prefix for the JetStream API.
Source§impl<PREFIX> ContextBuilder<PREFIX>where
PREFIX: ToAssign,
impl<PREFIX> ContextBuilder<PREFIX>where
PREFIX: ToAssign,
Sourcepub fn timeout(self, timeout: Duration) -> ContextBuilder<Yes>
pub fn timeout(self, timeout: Duration) -> ContextBuilder<Yes>
Set the timeout for all JetStream API requests.
Sourcepub fn ack_timeout(self, ack_timeout: Duration) -> ContextBuilder<Yes>
pub fn ack_timeout(self, ack_timeout: Duration) -> ContextBuilder<Yes>
Sets the maximum time client waits for acks from the server when default backpressure is used.
Sourcepub fn max_ack_inflight(self, capacity: usize) -> ContextBuilder<Yes>
pub fn max_ack_inflight(self, capacity: usize) -> ContextBuilder<Yes>
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.
Sourcepub fn backpressure_on_inflight(self, enabled: bool) -> ContextBuilder<Yes>
pub fn backpressure_on_inflight(self, enabled: bool) -> ContextBuilder<Yes>
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).
Sourcepub fn concurrency_limit(self, limit: Option<usize>) -> ContextBuilder<Yes>
pub fn concurrency_limit(self, limit: Option<usize>) -> ContextBuilder<Yes>
Sets the concurrency limit for the ack handler task. This might be useful in scenarios where Tokio runtime is under heavy load.