pub struct Client { /* private fields */ }Expand description
NATS Streaming client
Implementations§
Source§impl Client
impl Client
Sourcepub fn start(
nats_connection: Connection,
cluster_id: &str,
client_id: &str,
) -> Result<Client>
pub fn start( nats_connection: Connection, cluster_id: &str, client_id: &str, ) -> Result<Client>
Start a new client, establishing a new NATS Streaming connection, Same as stan::connect().
§Example:
let nats_url = "nats://127.0.0.1:4222";
let nc = nats::connect(nats_url)?;
let sc = stan::Client::start(nc, "test-cluster", "rust-client-1")?;Sourcepub fn publish(&self, subject: &str, msg: impl AsRef<[u8]>) -> Result<()>
pub fn publish(&self, subject: &str, msg: impl AsRef<[u8]>) -> Result<()>
Publish to a given subject. Will return an error if failed to receive a ack back from the streaming server.
§Example:
fn main() -> io::Result<()> {
let nats_url = "nats://127.0.0.1:4222";
let nc = nats::connect(nats_url)?;
sc.publish("foo", "hello from rust 1")Sourcepub fn subscribe(
&self,
subject: &str,
config: SubscriptionConfig<'_>,
) -> Result<Subscription>
pub fn subscribe( &self, subject: &str, config: SubscriptionConfig<'_>, ) -> Result<Subscription>
Start a subscription.
§Example:
use nats;
use std::{io, str::from_utf8};
fn main() -> io::Result<()> {
let nats_url = "nats://127.0.0.1:4222";
let nc = nats::connect(nats_url)?;
let sc = stan::connect(nc, "test-cluster", "rust-client-1")?;
sc.publish("foo", "hello from rust 1")?;
let sub = sc
.subscribe("foo", Default::default())?
.with_handler(|msg| {
println!("{:?}", from_utf8(&msg.data));
Ok(())
});
sc.publish("foo", "hello from rust 2")?;
sc.publish("foo", "hello from rust 3")
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more