Struct nats::Connection [−][src]
pub struct Connection(_);
A NATS connection.
Implementations
impl NatsClient
[src]
impl NatsClient
[src]pub fn create_stream<S>(&self, stream_config: S) -> Result<StreamInfo> where
StreamConfig: From<S>,
[src]
StreamConfig: From<S>,
Create a JetStream
stream.
Requires the jetstream
feature.
pub fn update_stream(&self, cfg: &StreamConfig) -> Result<StreamInfo>
[src]
Update a JetStream
stream.
Requires the jetstream
feature.
pub fn stream_names(&self) -> PagedIterator<'_, String>ⓘNotable traits for PagedIterator<'a, T>
impl<'a, T> Iterator for PagedIterator<'a, T> where
T: DeserializeOwned + Debug, type Item = Result<T>;
[src]
Notable traits for PagedIterator<'a, T>
impl<'a, T> Iterator for PagedIterator<'a, T> where
T: DeserializeOwned + Debug, type Item = Result<T>;
List all JetStream
stream names. If you also want stream information,
use the list_streams
method instead.
Requires the jetstream
feature.
pub fn list_streams(&self) -> PagedIterator<'_, StreamInfo>ⓘNotable traits for PagedIterator<'a, T>
impl<'a, T> Iterator for PagedIterator<'a, T> where
T: DeserializeOwned + Debug, type Item = Result<T>;
[src]
Notable traits for PagedIterator<'a, T>
impl<'a, T> Iterator for PagedIterator<'a, T> where
T: DeserializeOwned + Debug, type Item = Result<T>;
List all JetStream
streams.
Requires the jetstream
feature.
pub fn list_consumers<S>(
&self,
stream: S
) -> Result<PagedIterator<'_, ConsumerInfo>> where
S: AsRef<str>,
[src]
&self,
stream: S
) -> Result<PagedIterator<'_, ConsumerInfo>> where
S: AsRef<str>,
List JetStream
consumers for a stream.
Requires the jetstream
feature.
pub fn stream_info<S: AsRef<str>>(&self, stream: S) -> Result<StreamInfo>
[src]
Query JetStream
stream information.
Requires the jetstream
feature.
pub fn purge_stream<S: AsRef<str>>(&self, stream: S) -> Result<PurgeResponse>
[src]
Purge JetStream
stream messages.
Requires the jetstream
feature.
pub fn delete_message<S: AsRef<str>>(
&self,
stream: S,
sequence_number: u64
) -> Result<bool>
[src]
&self,
stream: S,
sequence_number: u64
) -> Result<bool>
Delete message in a JetStream
stream.
Requires the jetstream
feature.
pub fn delete_stream<S: AsRef<str>>(&self, stream: S) -> Result<bool>
[src]
Delete JetStream
stream.
Requires the jetstream
feature.
pub fn create_consumer<S, C>(&self, stream: S, cfg: C) -> Result<Consumer> where
S: AsRef<str>,
ConsumerConfig: From<C>,
[src]
S: AsRef<str>,
ConsumerConfig: From<C>,
Create a JetStream
consumer.
Requires the jetstream
feature.
pub fn delete_consumer<S, C>(&self, stream: S, consumer: C) -> Result<bool> where
S: AsRef<str>,
C: AsRef<str>,
[src]
S: AsRef<str>,
C: AsRef<str>,
Delete a JetStream
consumer.
Requires the jetstream
feature.
pub fn consumer_info<S, C>(
&self,
stream: S,
consumer: C
) -> Result<ConsumerInfo> where
S: AsRef<str>,
C: AsRef<str>,
[src]
&self,
stream: S,
consumer: C
) -> Result<ConsumerInfo> where
S: AsRef<str>,
C: AsRef<str>,
Query JetStream
consumer information.
Requires the jetstream
feature.
pub fn account_info(&self) -> Result<AccountInfo>
[src]
Query JetStream
account information.
Requires the jetstream
feature.
impl Connection
[src]
impl Connection
[src]pub fn subscribe(&self, subject: &str) -> Result<Subscription>
[src]
pub fn queue_subscribe(
&self,
subject: &str,
queue: &str
) -> Result<Subscription>
[src]
&self,
subject: &str,
queue: &str
) -> Result<Subscription>
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]
pub fn publish_request(
&self,
subject: &str,
reply: &str,
msg: impl AsRef<[u8]>
) -> Result<()>
[src]
&self,
subject: &str,
reply: &str,
msg: impl AsRef<[u8]>
) -> Result<()>
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]
&self,
subject: &str,
msg: impl AsRef<[u8]>,
timeout: Duration
) -> Result<Message>
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]
&self,
subject: &str,
msg: impl AsRef<[u8]>
) -> Result<Subscription>
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
. Will fail with TimedOut
if the server does not
respond with in 10 seconds. Will fail with NotConnected
if the
server is not currently connected. Will fail with BrokenPipe
if
the connection to the server is lost.
Example
nc.flush()?;
pub fn flush_timeout(&self, duration: Duration) -> Result<()>
[src]
Flush a NATS connection by sending a PING
protocol and waiting for the
responding PONG
. Will fail with TimedOut
if the server takes
longer than this duration to respond. Will fail with NotConnected
if the server is not currently connected. Will fail with
BrokenPipe
if the connection to the server is lost.
Example
nc.flush()?;
pub fn close(self)
[src]
Close a NATS connection. All clones of
this Connection
will also be closed,
as the backing IO threads are shared.
If the client is currently connected to a server, the outbound write buffer will be flushed in the process of shutting down.
Example
nc.close();
pub fn rtt(&self) -> Result<Duration>
[src]
Calculates the round trip time between this client and the server,
if the server is currently connected. Fails with TimedOut
if
the server takes more than 10 seconds to respond.
Example
println!("server rtt: {:?}", nc.rtt());
pub fn client_ip(&self) -> Result<IpAddr>
[src]
Returns the client IP as known by the server. Supported as of server version 2.1.6.
Example
println!("ip: {:?}", nc.client_ip());
pub fn client_id(&self) -> u64
[src]
Returns the client ID as known by the most recently connected server.
Example
println!("ip: {:?}", nc.client_id());
pub fn drain(&self) -> Result<()>
[src]
Send an unsubscription for all subs then flush the connection, allowing any unprocessed messages to be handled by a handler function if one is configured.
After the flush returns, we know that a round-trip to the server has happened after it received our unsubscription, so we shut down the subscriber afterwards.
A similar method exists for the Subscription
struct which will drain
a single Subscription
without shutting down the entire connection
afterward.
Example
let received = Arc::new(AtomicBool::new(false)); let received_2 = received.clone(); nc.subscribe("test.drain")?.with_handler(move |m| { received_2.store(true, SeqCst); Ok(()) }); nc.publish("test.drain", "message")?; nc.drain()?; assert!(received.load(SeqCst));
pub fn publish_with_reply_or_headers(
&self,
subject: &str,
reply: Option<&str>,
headers: Option<&Headers>,
msg: impl AsRef<[u8]>
) -> Result<()>
[src]
&self,
subject: &str,
reply: Option<&str>,
headers: Option<&Headers>,
msg: impl AsRef<[u8]>
) -> Result<()>
Publish a message which may have a reply subject or headers set.
Example
let sub = nc.subscribe("foo.headers")?; let headers = [("header1", "value1"), ("header2", "value2")].iter().collect(); let reply_to = None; nc.publish_with_reply_or_headers("foo.headers", reply_to, Some(&headers), "Hello World!")?; nc.flush()?; let message = sub.next_timeout(std::time::Duration::from_secs(2)).unwrap(); assert_eq!(message.headers.unwrap().len(), 2);
Trait Implementations
impl Clone for Connection
[src]
impl Clone for Connection
[src]fn clone(&self) -> Connection
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl !RefUnwindSafe for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Send for Connection
impl Sync for Connection
impl Sync for Connection
impl Unpin for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
impl !UnwindSafe for Connection