[][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() -> Result<Client>[src]

Creates a new client using the default options. A client created this way will attempt to establish an anonymous connection with a local NATS server running at 0.0.0.0:4222

pub fn subscribe<T, F>(&self, subject: T, handler: F) -> Result<()> where
    F: Fn(&Message) -> Result<()> + Sync + Send,
    F: 'static,
    T: Into<String> + Clone
[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<T, F>(
    &self,
    subject: T,
    queue_group: T,
    handler: F
) -> Result<()> where
    F: Fn(&Message) -> Result<()> + Sync + Send,
    F: 'static,
    T: Into<String> + Clone
[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<String>
) -> 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]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Client

impl Sync for Client

Blanket Implementations

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

type Owned = T

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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<T> Same for T

type Output = T

Should always be Self