[][src]Struct rants::Client

pub struct Client { /* fields omitted */ }

The entry point to the NATS client protocol

Methods

impl Client[src]

pub fn new(addresses: Vec<Address>) -> Self[src]

Create a new Client with a default Connect

Arguments

  • addresses - the list of addresses to try and establish a connection to a server

pub fn with_connect(addresses: Vec<Address>, connect: Connect) -> Self[src]

Create a new Client with the provided Connect

Arguments

  • addresses - the list of addresses to try and establish a connection to a server

pub async fn state<'_>(&'_ self) -> ClientState[src]

Get the current state of the Client

pub async fn state_stream<'_>(&'_ self) -> WatchReceiver<ClientState>[src]

Get a watch stream of Client state transitions

pub async fn info<'_>(&'_ self) -> Info[src]

Get a the most recent Info sent from the server

pub async fn connect_mut<'_, '_>(&'_ self) -> ClientRefMut<'_, Connect>[src]

Get a mutable reference to this Client's Connect

pub async fn addresses_mut<'_, '_>(&'_ self) -> ClientRefMut<'_, [Address]>[src]

Get a mutable reference to the list of addresses used to try and establish a connection to a server.

pub async fn tcp_connect_timeout<'_>(&'_ self) -> Duration[src]

Get the configured TCP connect timeout. [default = 10s]

This is the timeout of a single connect attempt. It is not the timeout of the connect future which has no internal timeout.

pub async fn set_tcp_connect_timeout<'_, '_>(
    &'_ self,
    tcp_connect_timeout: Duration
) -> &'_ Self
[src]

Set the TCP connect timeout.

pub async fn delay_generator_mut<'_, '_>(
    &'_ self
) -> ClientRefMut<'_, DelayGenerator>
[src]

Get the DelayGenerator

The default generator is generated with generate_delay_generator with the following parameters:

  • connect_series_attempts_before_cool_down = 3
  • connect_delay = 0s
  • connect_series_delay = 5s
  • cool_down = 60s

pub async fn sids<'_>(&'_ self) -> Vec<Sid>[src]

Get a list of all currently subscribed subscription IDs

pub async fn subscription<'_, '_>(
    &'_ self,
    sid: Sid
) -> Option<ClientRef<'_, Subscription>>
[src]

Return a reference to a Subscription if the client is aware of the specified subscription ID

pub async fn send_connect<'_>(&'_ self) -> Result<()>[src]

Send a CONNECT message to the server using the configured Connect.

Note: connect automatically sends a CONNECT message. This is only needed in the case that you want to change the connection parameters after already establishing a connection.

pub async fn connect<'_>(&'_ self)[src]

Connect to a NATS server

This will randomly shuffle a list consisting of all explicitly specified addresses and addresses received in an INFO message's connect_urls. A randomized list of addresses is used to avoid a thundering herd. The client will continuously try to connect to each address in this list. The timeout of each connect attempt is specified by the tcp_connect_timeout. The delay between each connect attempt is specified by the delay_generator_mut.

When this future resolves, we are guaranteed to have entered the Connected state. Unless, disconnect was called.

pub async fn disconnect<'_>(&'_ self)[src]

Disconnect from the NATS server

When this future resolves, we are guaranteed to have entered the Disconnected state.

Note: Client does not disconnect when it is Dropped. In order to avoid leaking futures, you must explicitly call disconnect.

pub async fn publish<'_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    payload: &'_ [u8]
) -> Result<()>
[src]

Convenience wrapper around publish_with_optional_reply

pub async fn publish_with_reply<'_, '_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    reply_to: &'_ Subject,
    payload: &'_ [u8]
) -> Result<()>
[src]

Convenience wrapper around publish_with_optional_reply

pub async fn publish_with_optional_reply<'_, '_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    reply_to: Option<&'_ Subject>,
    payload: &'_ [u8]
) -> Result<()>
[src]

PUBlish a message

Arguments

  • subject - The subject to publish to
  • reply_to - The optional reply to subject
  • payload - The actual contents of the message

pub async fn request<'_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    payload: &'_ [u8]
) -> Result<Msg>
[src]

Implements the request-reply pattern

Note: This uses the old method of request reply. It creates a temporary subscription that is immediately unsubscribed from. See here for an improved implementation.

pub async fn subscribe<'_, '_>(
    &'_ self,
    subject: &'_ Subject,
    buffer: usize
) -> Result<(Sid, MpscReceiver<Msg>)>
[src]

Convenience wrapper around subscribe_with_optional_queue_group

pub async fn subscribe_with_queue_group<'_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    queue_group: &'_ str,
    buffer: usize
) -> Result<(Sid, MpscReceiver<Msg>)>
[src]

Convenience wrapper around subscribe_with_optional_queue_group

pub async fn subscribe_with_optional_queue_group<'_, '_, '_>(
    &'_ self,
    subject: &'_ Subject,
    queue_group: Option<&'_ str>,
    buffer: usize
) -> Result<(Sid, MpscReceiver<Msg>)>
[src]

SUBscribe to a Subject

Returns the subscription ID of the newly created subscription and a channel to receive incoming messages on.

Arguments

  • subject - The subject to subscribe to
  • reply_to - The optional queue group to join
  • buffer - The size of the underlying mpsc channel

pub async fn unsubscribe<'_>(&'_ self, sid: Sid) -> Result<()>[src]

Convenience wrapper around unsubscribe_optional_max_msgs

pub async fn unsubscribe_with_max_msgs<'_>(
    &'_ self,
    sid: Sid,
    max_msgs: u64
) -> Result<()>
[src]

Convenience wrapper around unsubscribe_optional_max_msgs

pub async fn unsubscribe_optional_max_msgs<'_>(
    &'_ self,
    sid: Sid,
    max_msgs: Option<u64>
) -> Result<()>
[src]

UNSUBscribe from a subscription ID

Arguments

  • sid - The subscription id to unsubscribe from
  • max_msgs - Unsubscribe after receiving the specified number of messages. If this is None, the subscription is immediately unsubscribed.

pub async fn unsubscribe_all<'_>(&'_ self) -> Result<()>[src]

Unsubscribe from all subscriptions

pub async fn info_stream<'_>(&'_ self) -> WatchReceiver<Info>[src]

Get a watch stream of INFO messages received from the server

pub async fn ping_stream<'_>(&'_ self) -> WatchReceiver<()>[src]

Get a watch stream of PING messages received from the server

pub async fn pong_stream<'_>(&'_ self) -> WatchReceiver<()>[src]

Get a watch stream of PONG messages received from the server

pub async fn ok_stream<'_>(&'_ self) -> WatchReceiver<()>[src]

Get a watch stream of +OK messages received from the server

pub async fn err_stream<'_>(&'_ self) -> WatchReceiver<ProtocolError>[src]

Get a watch stream of -ERR messages received from the server

pub async fn ping<'_>(&'_ self) -> Result<()>[src]

Send a PING to the server.

This method, coupled with a pong_stream, can be a useful way to check that the client is still connected to the server.

pub async fn pong<'_>(&'_ self) -> Result<()>[src]

Send a PONG to the server.

Note: you do not have to manually send a PONG as part of the servers ping/pong keep alive. The client library automatically handles replying to pings. You should not need to use this method.

pub async fn ping_pong<'_>(&'_ self) -> Result<()>[src]

Send a PONG and wait for a PONG from the server

Trait Implementations

impl Drop for Client[src]

impl Clone for Client[src]

Auto Trait Implementations

impl Send for Client

impl Unpin for Client

impl Sync for Client

impl !UnwindSafe for Client

impl !RefUnwindSafe for Client

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> Erased for T[src]

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