Struct async_nats::client::Request
source · pub struct Request { /* private fields */ }
Expand description
Used for building customized requests.
Implementations§
source§impl Request
impl Request
pub fn new() -> Request
sourcepub fn payload(self, payload: Bytes) -> Request
pub fn payload(self, payload: Bytes) -> Request
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", request).await?;
sourcepub fn headers(self, headers: HeaderMap) -> Request
pub fn headers(self, headers: HeaderMap) -> Request
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", request).await?;
sourcepub fn timeout(self, timeout: Option<Duration>) -> Request
pub fn timeout(self, timeout: Option<Duration>) -> Request
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", request).await?;
sourcepub fn inbox(self, inbox: String) -> Request
pub fn inbox(self, inbox: String) -> Request
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", request).await?;
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnwindSafe for Request
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more