pub struct Options { /* private fields */ }use the async-nats crate instead
Expand description
Connect options.
Implementations§
Source§impl Options
impl Options
Sourcepub fn new() -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn new() -> Options
use the async-nats crate instead
Options for establishing a new NATS Connection.
§Example
let options = nats::asynk::Options::new();
let nc = options.connect("demo.nats.io").await?;Sourcepub fn with_token(token: &str) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_token(token: &str) -> Options
use the async-nats crate instead
Authenticate with NATS using a token.
§Example
let nc = nats::asynk::Options::with_token("t0k3n!")
.connect("demo.nats.io")
.await?;Sourcepub fn with_user_pass(user: &str, password: &str) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_user_pass(user: &str, password: &str) -> Options
use the async-nats crate instead
Authenticate with NATS using a username and password.
§Example
let nc = nats::asynk::Options::with_user_pass("derek", "s3cr3t!")
.connect("demo.nats.io")
.await?;Sourcepub fn with_credentials(path: impl AsRef<Path>) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_credentials(path: impl AsRef<Path>) -> Options
use the async-nats crate instead
Authenticate with NATS using a .creds file.
§Example
let nc = nats::asynk::Options::with_credentials("path/to/my.creds")
.connect("connect.ngs.global")
.await?;Sourcepub fn with_jwt<J, S>(jwt_cb: J, sig_cb: S) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_jwt<J, S>(jwt_cb: J, sig_cb: S) -> Options
use the async-nats crate instead
Authenticate with a function that loads user JWT and a signature function.
§Example
let seed = "SUANQDPB2RUOE4ETUA26CNX7FUKE5ZZKFCQIIW63OX225F2CO7UEXTM7ZY";
let kp = nkeys::KeyPair::from_seed(seed).unwrap();
fn load_jwt() -> std::io::Result<String> {
todo!()
}
let nc = nats::asynk::Options::with_jwt(load_jwt, move |nonce| kp.sign(nonce).unwrap())
.connect("localhost")
.await?;Sourcepub fn with_nkey<F>(nkey: &str, sig_cb: F) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_nkey<F>(nkey: &str, sig_cb: F) -> Options
use the async-nats crate instead
Authenticate with NATS using a public key and a signature function.
§Example
let nkey = "UAMMBNV2EYR65NYZZ7IAK5SIR5ODNTTERJOBOF4KJLMWI45YOXOSWULM";
let seed = "SUANQDPB2RUOE4ETUA26CNX7FUKE5ZZKFCQIIW63OX225F2CO7UEXTM7ZY";
let kp = nkeys::KeyPair::from_seed(seed).unwrap();
let nc = nats::asynk::Options::with_nkey(nkey, move |nonce| kp.sign(nonce).unwrap())
.connect("localhost")
.await?;Sourcepub fn client_cert(
self,
cert: impl AsRef<Path>,
key: impl AsRef<Path>,
) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn client_cert( self, cert: impl AsRef<Path>, key: impl AsRef<Path>, ) -> Options
use the async-nats crate instead
Set client certificate and private key files.
§Example
let nc = nats::asynk::Options::new()
.client_cert("client-cert.pem", "client-key.pem")
.connect("nats://localhost:4443")
.await?;Sourcepub fn with_name(self, name: &str) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn with_name(self, name: &str) -> Options
use the async-nats crate instead
Add a name option to this configuration.
§Example
let nc = nats::asynk::Options::new()
.with_name("My App")
.connect("demo.nats.io")
.await?;Sourcepub fn no_echo(self) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn no_echo(self) -> Options
use the async-nats crate instead
Select option to not deliver messages that we have published.
§Example
let nc = nats::asynk::Options::new()
.no_echo()
.connect("demo.nats.io")
.await?;Sourcepub fn retry_on_failed_connect(self) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn retry_on_failed_connect(self) -> Options
use the async-nats crate instead
Select option to enable reconnect with backoff
on first failed connection attempt.
The reconnect logic with max_reconnects and the
reconnect_delay_callback will be specified the same
as before but will be invoked on the first failed
connection attempt.
§Example
let nc = nats::asynk::Options::new()
.retry_on_failed_connect()
.connect("demo.nats.io")
.await?;Sourcepub fn max_reconnects<T: Into<Option<usize>>>(
self,
max_reconnects: T,
) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn max_reconnects<T: Into<Option<usize>>>( self, max_reconnects: T, ) -> Options
use the async-nats crate instead
Set the maximum number of reconnect attempts. If no servers remain that are under this threshold, then no further reconnect shall be attempted. The reconnect attempt for a server is reset upon successful connection. If None then there is no maximum number of attempts.
§Example
let nc = nats::asynk::Options::new()
.max_reconnects(3)
.connect("demo.nats.io")
.await?;Sourcepub fn reconnect_buffer_size(self, reconnect_buffer_size: usize) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn reconnect_buffer_size(self, reconnect_buffer_size: usize) -> Options
use the async-nats crate instead
Set the maximum amount of bytes to buffer when accepting outgoing traffic in disconnected mode.
The default value is 8mb.
§Example
let nc = nats::asynk::Options::new()
.reconnect_buffer_size(64 * 1024)
.connect("demo.nats.io")
.await?;Sourcepub async fn connect<I>(self, nats_url: I) -> Result<Connection>where
I: IntoServerList,
👎Deprecated since 0.26.0: use the async-nats crate instead
pub async fn connect<I>(self, nats_url: I) -> Result<Connection>where
I: IntoServerList,
use the async-nats crate instead
Establish a Connection with a NATS server.
Multiple servers may be specified by separating them with commas.
§Example
let options = nats::asynk::Options::new();
let nc = options.connect("demo.nats.io").await?;In the below case, the second server is configured
to use TLS but the first one is not. Using the
tls_required method can ensure that all
servers are connected to with TLS, if that is
your intention.
let options = nats::asynk::Options::new();
let nc = options
.connect("nats://demo.nats.io:4222,tls://demo.nats.io:4443")
.await?;Sourcepub fn disconnect_callback<F>(self, cb: F) -> Self
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn disconnect_callback<F>(self, cb: F) -> Self
use the async-nats crate instead
Set a callback to be executed when connectivity to a server has been lost.
§Example
let nc = nats::asynk::Options::new()
.disconnect_callback(|| println!("connection has been lost"))
.connect("demo.nats.io")
.await?;Sourcepub fn reconnect_callback<F>(self, cb: F) -> Self
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn reconnect_callback<F>(self, cb: F) -> Self
use the async-nats crate instead
Set a callback to be executed when connectivity to a server has been reestablished.
§Example
let nc = nats::asynk::Options::new()
.reconnect_callback(|| println!("connection has been reestablished"))
.connect("demo.nats.io")
.await?;Sourcepub fn close_callback<F>(self, cb: F) -> Self
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn close_callback<F>(self, cb: F) -> Self
use the async-nats crate instead
Set a callback to be executed when the client has been closed due to exhausting reconnect retries to known servers or by completing a drain request.
§Example
let nc = nats::asynk::Options::new()
.close_callback(|| println!("connection has been closed"))
.connect("demo.nats.io")
.await?;Sourcepub fn reconnect_delay_callback<F>(self, cb: F) -> Self
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn reconnect_delay_callback<F>(self, cb: F) -> Self
use the async-nats crate instead
Set a callback to be executed for calculating the backoff duration to wait before a server reconnection attempt.
The function takes the number of reconnects as an argument
and returns the Duration that should be waited before
making the next connection attempt.
It is recommended that some random jitter is added to
your returned Duration.
§Example
let nc = nats::asynk::Options::new()
.reconnect_delay_callback(|c| Duration::from_millis(std::cmp::min((c * 100) as u64, 8000)))
.connect("demo.nats.io")
.await?;Sourcepub fn tls_required(self, tls_required: bool) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn tls_required(self, tls_required: bool) -> Options
use the async-nats crate instead
Setting this requires that TLS be set for all server connections.
If you only want to use TLS for some server connections, you may
declare them separately in the connect string by prefixing them
with tls://host:port instead of nats://host:port.
§Examples
let nc = nats::asynk::Options::new()
.tls_required(true)
.connect("tls://demo.nats.io:4443")
.await?;Sourcepub fn add_root_certificate(self, path: impl AsRef<Path>) -> Options
👎Deprecated since 0.26.0: use the async-nats crate instead
pub fn add_root_certificate(self, path: impl AsRef<Path>) -> Options
use the async-nats crate instead
Adds a root certificate file.
The file must be PEM encoded. All certificates in the file will be used.
§Examples
let nc = nats::asynk::Options::new()
.add_root_certificate("my-certs.pem")
.connect("tls://demo.nats.io:4443")
.await?;