Struct async_nats::Client
source · [−]pub struct Client { /* private fields */ }Expand description
Client is a Clonable handle to NATS connection.
Client should not be created directly. Instead, one of two methods can be used:
crate::connect and crate::ConnectOptions::connect
Implementations
sourceimpl Client
impl Client
sourcepub fn server_info(&self) -> ServerInfo
pub fn server_info(&self) -> ServerInfo
Returns last received info from the server.
Examples
let client = async_nats::connect("demo.nats.io").await?;
println!("info: {:?}", client.server_info());sourcepub fn is_server_compatible(&self, major: i64, minor: i64, patch: i64) -> bool
pub fn is_server_compatible(&self, major: i64, minor: i64, patch: i64) -> bool
Returns true if the server version is compatible with the version components.
Examples
let client = async_nats::connect("demo.nats.io").await?;
assert!(client.is_server_compatible(2, 8, 4));pub async fn publish(
&self,
subject: String,
payload: Bytes
) -> Result<(), PublishError>
pub async fn publish_with_headers(
&self,
subject: String,
headers: HeaderMap,
payload: Bytes
) -> Result<(), Error>
pub async fn publish_with_reply(
&self,
subject: String,
reply: String,
payload: Bytes
) -> Result<(), Error>
pub async fn publish_with_reply_and_headers(
&self,
subject: String,
reply: String,
headers: HeaderMap,
payload: Bytes
) -> Result<(), PublishError>
pub async fn request(
&self,
subject: String,
payload: Bytes
) -> Result<Message, Error>
pub async fn request_with_headers(
&self,
subject: String,
headers: HeaderMap,
payload: Bytes
) -> Result<Message, Error>
sourcepub fn new_inbox(&self) -> String
pub fn new_inbox(&self) -> String
Create a new globally unique inbox which can be used for replies.
Examples
let reply = nc.new_inbox();
let rsub = nc.subscribe(reply).await?;pub async fn subscribe(&self, subject: String) -> Result<Subscriber, Error>
pub async fn queue_subscribe(
&self,
subject: String,
queue_group: String
) -> Result<Subscriber, Error>
pub async fn flush(&self) -> Result<(), Error>
sourcepub fn connection_state(&self) -> State
pub fn connection_state(&self) -> State
Returns the current state of the connection.
Examples
let client = async_nats::connect("demo.nats.io").await?;
println!("connection state: {}", client.connection_state());Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more