Struct async_nats::Request

source ·
pub struct Request { /* private fields */ }
Expand description

Used for building customized requests.

Implementations

Sets the payload of the request. If not used, empty payload will be sent.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let request = async_nats::Request::new().payload("data".into());
client.send_request("service".into(), request).await?;

Sets the headers of the requests.

Examples
use std::str::FromStr;
let client = async_nats::connect("demo.nats.io").await?;
let mut headers = async_nats::HeaderMap::new();
headers.insert("X-Example", async_nats::HeaderValue::from_str("Value").unwrap());
let request = async_nats::Request::new()
    .headers(headers)
    .payload("data".into());
client.send_request("service".into(), request).await?;

Sets the custom timeout of the request. Overrides default Client timeout. Setting it to Option::None disables the timeout entirely which might result in deadlock. To use default timeout, simply do not call this function.

Examples
let client = async_nats::connect("demo.nats.io").await?;
let request = async_nats::Request::new()
    .timeout(Some(std::time::Duration::from_secs(15)))
    .payload("data".into());
client.send_request("service".into(), request).await?;

Sets custom inbox for this request. Overrides both customized and default Client Inbox.

Examples
use std::str::FromStr;
let client = async_nats::connect("demo.nats.io").await?;
let request = async_nats::Request::new()
    .inbox("custom_inbox".into())
    .payload("data".into());
client.send_request("service".into(), request).await?;

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more