pub struct PushSubscription(/* private fields */);use the async-nats crate instead
Expand description
A PushSubscription receives Messages published
to specific NATS Subjects.
Implementations§
Source§impl PushSubscription
impl PushSubscription
Sourcepub fn next(&self) -> Option<Message>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn next(&self) -> Option<Message>
use the async-nats crate instead
Get the next message non-protocol message, or None if the subscription has been unsubscribed or the connection closed.
§Example
if let Some(message) = subscription.next() {
println!("Received {}", message);
}Sourcepub fn try_next(&self) -> Option<Message>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn try_next(&self) -> Option<Message>
use the async-nats crate instead
Try to get the next non-protocol message, or None if no messages are present or if the subscription has been unsubscribed or the connection closed.
§Example
if let Some(message) = subscription.try_next() {
println!("Received {}", message);
}Sourcepub fn next_timeout(&self, timeout: Duration) -> Result<Message>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn next_timeout(&self, timeout: Duration) -> Result<Message>
use the async-nats crate instead
Get the next message, or a timeout error if no messages are available for timeout.
§Example
if let Ok(message) = subscription.next_timeout(std::time::Duration::from_secs(1)) {
println!("Received {}", message);
}Sourcepub fn messages(&self) -> Iter<'_> ⓘ
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn messages(&self) -> Iter<'_> ⓘ
use the async-nats crate instead
Returns a blocking message iterator.
Same as calling iter().
§Example
for message in subscription.messages() {
println!("Received message {:?}", message);
}Sourcepub fn try_iter(&self) -> TryIter<'_> ⓘ
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn try_iter(&self) -> TryIter<'_> ⓘ
use the async-nats crate instead
Sourcepub fn timeout_iter(&self, timeout: Duration) -> TimeoutIter<'_> ⓘ
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn timeout_iter(&self, timeout: Duration) -> TimeoutIter<'_> ⓘ
use the async-nats crate instead
Returns a blocking message iterator with a time deadline for blocking.
§Example
for message in subscription.timeout_iter(std::time::Duration::from_secs(1)) {
println!("Received message {:?}", message);
}Sourcepub fn with_handler<F>(self, handler: F) -> Handler
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_handler<F>(self, handler: F) -> Handler
use the async-nats crate instead
Attach a closure to handle messages. This closure will execute in a
separate thread. The result of this call is a Handler which can
not be iterated and must be unsubscribed or closed directly to
unregister interest. A Handler will not unregister interest with
the server when drop(&mut self) is called.
§Example
context
.subscribe("with_handler")?
.with_handler(move |message| {
println!("received {}", &message);
Ok(())
});
Sourcepub fn with_process_handler<F>(self, handler: F) -> Handler
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_process_handler<F>(self, handler: F) -> Handler
use the async-nats crate instead
Attach a closure to process and acknowledge messages. This closure will execute in a separate thread.
The result of this call is a Handler
which can not be iterated and must be unsubscribed or closed directly to
unregister interest. A Handler will not unregister interest with
the server when drop(&mut self) is called.
§Example
context
.subscribe("with_process_handler")?
.with_process_handler(|message| {
println!("Received {}", &message);
Ok(())
});
Sourcepub fn process<R, F: Fn(&Message) -> Result<R>>(&mut self, f: F) -> Result<R>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn process<R, F: Fn(&Message) -> Result<R>>(&mut self, f: F) -> Result<R>
use the async-nats crate instead
Process and acknowledge a single message, waiting indefinitely for one to arrive.
Does not acknowledge the processed message if the closure returns an Err.
Example
let mut subscription = context.subscribe("process")?;
subscription.process(|message| {
println!("Received message {:?}", message);
Ok(())
})?;Sourcepub fn process_timeout<R, F: Fn(&Message) -> Result<R>>(
&mut self,
timeout: Duration,
f: F,
) -> Result<R>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn process_timeout<R, F: Fn(&Message) -> Result<R>>( &mut self, timeout: Duration, f: F, ) -> Result<R>
use the async-nats crate instead
Process and acknowledge a single message, waiting up to timeout configured timeout before
returning a timeout error.
Does not ack the processed message if the internal closure returns an Err.
Example
let mut subscription = context.subscribe("process_timeout")?;
subscription.process_timeout(std::time::Duration::from_secs(1), |message| {
println!("Received message {:?}", message);
Ok(())
})?;Sourcepub fn consumer_info(&self) -> Result<ConsumerInfo>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn consumer_info(&self) -> Result<ConsumerInfo>
use the async-nats crate instead
Sends a request to fetch current information about the target consumer.
§Example
let subscription = context.subscribe("consumer_info")?;
let info = subscription.consumer_info()?;Sourcepub fn unsubscribe(self) -> Result<()>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn unsubscribe(self) -> Result<()>
use the async-nats crate instead
Unsubscribe a subscription immediately without draining.
Use drain instead if you want any pending messages
to be processed by a handler, if one is configured.
§Example
let subscription = context.subscribe("unsubscribe")?;
subscription.unsubscribe()?;Sourcepub fn close(self) -> Result<()>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn close(self) -> Result<()>
use the async-nats crate instead
Close a subscription. Same as unsubscribe
Use drain instead if you want any pending messages
to be processed by a handler, if one is configured.
§Example
let subscription = context.subscribe("close")?;
subscription.close()?;Sourcepub fn drain(&self) -> Result<()>
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn drain(&self) -> Result<()>
use the async-nats crate instead
Send an unsubscription and flush the connection,
allowing any unprocessed messages to be handled
by a Subscription
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 on the Connection struct
which will drain all subscriptions for the NATS
client, and transition the entire system into
the closed state afterward.
§Example
let mut subscription = context.subscribe("drain")?;
context.publish("drain", "foo")?;
context.publish("drain", "bar")?;
context.publish("drain", "baz")?;
subscription.drain()?;
assert!(subscription.next().is_some());
Trait Implementations§
Source§impl Clone for PushSubscription
impl Clone for PushSubscription
Source§fn clone(&self) -> PushSubscription
fn clone(&self) -> PushSubscription
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more