[][src]Struct natsclient::Client

pub struct Client { /* fields omitted */ }

The main entry point for your application to consume NATS services. This client manages connections, connection retries, adjusts to new servers as they enter the cluster, and much more.

Methods

impl Client[src]

pub fn from_options(opts: ClientOptions) -> Result<Client>[src]

Creates a new client from a set of options, which can be created directly or through a ClientOptionsBuilder

pub fn new(url: &str) -> Result<Client>[src]

Creates a new client using the default options and the given URL. A client created this way will attempt to establish an anonymous connection with the given NATS server

pub fn subscribe<F>(&self, subject: &str, handler: F) -> Result<()> where
    F: Fn(&Message) -> Result<()> + Sync + Send,
    F: 'static, 
[src]

Creates a subscription to a new subject. The subject can be a specfic subject or a wildcard. The handler supplied will be given a reference to delivered messages as they arrive, and can return a Result to indicate processing failure

pub fn queue_subscribe<F>(
    &self,
    subject: &str,
    queue_group: &str,
    handler: F
) -> Result<()> where
    F: Fn(&Message) -> Result<()> + Sync + Send,
    F: 'static, 
[src]

Creates a subscription for a queue group, allowing message delivery to be spread round-robin style across all clients expressing interest in that subject. For more information on how queue groups work, consult the NATS documentation.

pub fn request<T>(
    &self,
    subject: T,
    payload: &[u8],
    timeout: Duration
) -> Result<Message> where
    T: AsRef<str>, 
[src]

Perform a synchronous request by publishing a message on the given subject and waiting an expiration period indicated by the timeout parameter. If the timeout expires before a reply arrives on the inbox subject, an Err result will be returned.

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

Unsubscribe from a subject or wildcard

pub fn publish(
    &self,
    subject: &str,
    payload: &[u8],
    reply_to: Option<&str>
) -> Result<()>
[src]

Asynchronously publish a message. This is a fire-and-forget style message and an Ok result here does not imply that interested parties have received the message, only that the message was successfully sent to NATS.

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

Connect a client to the NATS server(s) indicated by previously supplied configuration

Trait Implementations

impl Clone for Client[src]

impl Default for Client[src]

fn default() -> Client[src]

Creates a default client, using anonymous authentication and pointing to the localhost NATS server

Auto Trait Implementations

impl RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl UnwindSafe for Client

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> Clear for T where
    T: InitializableFromZeroed + ?Sized

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

impl<T> InitializableFromZeroed for T where
    T: Default

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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>,