Rust

connection

Module

The connection: handshake, publish, subscribe, request-reply, keepalive, reconnection and the server's errors.

Contents

use utopia_nats::Connection;
Rust
pub struct Connection

A connection to a NATS server (or cluster).

One owner drives it: every call takes &mut self, and nothing happens between calls. Messages for subscriptions are read and dispatched by Connection::process_message, Connection::wait, Connection::next_message and the request calls; keepalives by those and Connection::tick.

Rust
use utopia_nats::{Connection, ConnectionOptions};

let Ok(mut connection) = Connection::connect(options).await else { return Ok(()) };
let orders = connection.subscribe("orders.*", None, None).await?;
connection.publish("orders.new", "{\"id\":1}", None, None).await?;
let message = connection.next_message(&orders, Some(std::time::Duration::from_secs(1))).await?.unwrap();
assert_eq!(message.subject, "orders.new");
connection.close().await?;
Also implements Debug.
use utopia_nats::RequestMany;
Rust
pub struct RequestMany

Stop conditions of Connection::request_many.

use utopia_nats::Status;
Rust
pub enum Status

Where a connection is in its life.