[][src]Struct nats::Connection

pub struct Connection { /* fields omitted */ }

A NATS connection.

Methods

impl Connection[src]

pub fn subscribe(&self, subject: &str) -> Result<Subscription>[src]

Create a subscription for the given NATS connection.

Example

let sub = nc.subscribe("foo")?;

pub fn queue_subscribe(
    &self,
    subject: &str,
    queue: &str
) -> Result<Subscription>
[src]

Create a queue subscription for the given NATS connection.

Example

let sub = nc.queue_subscribe("foo", "production")?;

pub fn publish(&self, subject: &str, msg: impl AsRef<[u8]>) -> Result<()>[src]

Publish a message on the given subject.

Example

nc.publish("foo", "Hello World!")?;

pub fn publish_request(
    &self,
    subject: &str,
    reply: &str,
    msg: impl AsRef<[u8]>
) -> Result<()>
[src]

Publish a message on the given subject with a reply subject for responses.

Example

let reply = nc.new_inbox();
let rsub = nc.subscribe(&reply)?;
nc.publish_request("foo", &reply, "Help me!")?;

pub fn new_inbox(&self) -> String[src]

Create a new globally unique inbox which can be used for replies.

Example

let reply = nc.new_inbox();
let rsub = nc.subscribe(&reply)?;

pub fn request(&self, subject: &str, msg: impl AsRef<[u8]>) -> Result<Message>[src]

Publish a message on the given subject as a request and receive the response.

Example

let resp = nc.request("foo", "Help me?")?;

pub fn request_timeout(
    &self,
    subject: &str,
    msg: impl AsRef<[u8]>,
    timeout: Duration
) -> Result<Message>
[src]

Publish a message on the given subject as a request and receive the response. This call will return after the timeout duration if no response is received.

Example

let resp = nc.request_timeout("foo", "Help me?", std::time::Duration::from_secs(2))?;

pub fn request_multi(
    &self,
    subject: &str,
    msg: impl AsRef<[u8]>
) -> Result<Subscription>
[src]

Publish a message on the given subject as a request and allow multiple responses.

Example

for msg in nc.request_multi("foo", "Help")?.iter().take(1) {}

pub fn flush(&self) -> Result<()>[src]

Flush a NATS connection by sending a PING protocol and waiting for the responding PONG.

Example

nc.flush()?;

pub fn close(self) -> Result<()>[src]

Close a NATS connection.

Example

nc.close()?;

Trait Implementations

impl Clone for Connection[src]

impl Debug for Connection[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,