[−][src]Struct nats::ConnectionOptions
A configuration object for a NATS connection.
Implementations
impl ConnectionOptions<NoAuth>
[src]
pub fn new() -> ConnectionOptions<NoAuth>
[src]
ConnectionOptions
for establishing a new NATS Connection
.
Example
let options = nats::ConnectionOptions::new(); let nc = options.connect("demo.nats.io")?;
pub fn with_token(self, token: &str) -> ConnectionOptions<Authenticated>
[src]
Authenticate with NATS using a token.
Example
let nc = nats::ConnectionOptions::new() .with_token("t0k3n!") .connect("demo.nats.io")?;
pub fn with_user_pass(
self,
user: &str,
password: &str
) -> ConnectionOptions<Authenticated>
[src]
self,
user: &str,
password: &str
) -> ConnectionOptions<Authenticated>
Authenticate with NATS using a username and password.
Example
let nc = nats::ConnectionOptions::new() .with_user_pass("derek", "s3cr3t!") .connect("demo.nats.io")?;
pub fn with_credentials(
self,
path: impl AsRef<Path>
) -> ConnectionOptions<Authenticated>
[src]
self,
path: impl AsRef<Path>
) -> ConnectionOptions<Authenticated>
Authenticate with NATS using a credentials file
Example
let nc = nats::ConnectionOptions::new() .with_credentials("path/to/my.creds") .connect("connect.ngs.global")?;
impl<TypeState> ConnectionOptions<TypeState>
[src]
pub fn with_name(self, name: &str) -> ConnectionOptions<TypeState>
[src]
Add a name option to this configuration.
Example
let nc = nats::ConnectionOptions::new() .with_name("My App") .connect("demo.nats.io")?;
pub const fn no_echo(self) -> ConnectionOptions<TypeState>
[src]
Select option to not deliver messages that we have published.
Example
let nc = nats::ConnectionOptions::new() .no_echo() .connect("demo.nats.io")?;
pub const fn max_reconnects(
self,
max_reconnects: Option<usize>
) -> ConnectionOptions<TypeState>
[src]
self,
max_reconnects: Option<usize>
) -> ConnectionOptions<TypeState>
Set the maximum number of reconnect attempts. If no servers remain that are under this threshold, all servers will still be attempted.
Example
let nc = nats::ConnectionOptions::new() .max_reconnects(Some(3)) .connect("demo.nats.io")?;
pub const fn reconnect_buffer_size(
self,
reconnect_buffer_size: usize
) -> ConnectionOptions<TypeState>
[src]
self,
reconnect_buffer_size: usize
) -> ConnectionOptions<TypeState>
Set the maximum amount of bytes to buffer when accepting outgoing traffic in disconnected mode.
The default value is 8mb.
Example
let nc = nats::ConnectionOptions::new() .reconnect_buffer_size(64 * 1024) .connect("demo.nats.io")?;
pub fn connect(self, nats_url: &str) -> Result<Connection>
[src]
Establish a Connection
with a NATS server.
Multiple servers may be specified by separating them with commas.
Example
let options = nats::ConnectionOptions::new(); let nc = options.connect("demo.nats.io")?;
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::ConnectionOptions::new(); let nc = options.connect("nats://demo.nats.io:4222,tls://demo.nats.io:4443")?;
pub fn set_disconnect_callback<F>(self, cb: F) -> Self where
F: Fn() + Send + Sync + 'static,
[src]
F: Fn() + Send + Sync + 'static,
Set a callback to be executed when connectivity to a server has been lost.
pub fn set_reconnect_callback<F>(self, cb: F) -> Self where
F: Fn() + Send + Sync + 'static,
[src]
F: Fn() + Send + Sync + 'static,
Set a callback to be executed when connectivity to a server has been established.
pub fn set_close_callback<F>(self, cb: F) -> Self where
F: Fn() + Send + Sync + 'static,
[src]
F: Fn() + Send + Sync + 'static,
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.
pub fn set_reconnect_delay_callback<F>(self, cb: F) -> Self where
F: Fn(usize) -> Duration + Send + Sync + 'static,
[src]
F: Fn(usize) -> Duration + Send + Sync + 'static,
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
.
pub const fn tls_required(self, tls_required: bool) -> Self
[src]
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
.
If you want to use a particular TLS configuration, see
the nats::tls::tls_connector
method and the
nats::ConnectionOptions::tls_connector
method below
to apply the desired configuration to all server connections.
Examples
let nc = nats::ConnectionOptions::new() .tls_required(true) .connect("tls://demo.nats.io:4443")?;
pub fn tls_connector(self, connector: TlsConnector) -> Self
[src]
Allows a particular TLS configuration to be set for upgrading TCP connections to TLS connections.
Note that this also enforces that TLS will be enabled for all connections to all servers.
Examples
let tls_connector = nats::tls::builder() .identity(nats::tls::Identity::from_pkcs12(b"der_bytes", "my_password")?) .add_root_certificate(nats::tls::Certificate::from_pem(b"my_pem_bytes")?) .build()?; let nc = nats::ConnectionOptions::new() .tls_connector(tls_connector) .connect("tls://demo.nats.io:4443")?;
Trait Implementations
impl<T> Debug for ConnectionOptions<T>
[src]
impl Default for ConnectionOptions<NoAuth>
[src]
fn default() -> ConnectionOptions<NoAuth>
[src]
Auto Trait Implementations
impl<TypeState> !RefUnwindSafe for ConnectionOptions<TypeState>
impl<TypeState> Send for ConnectionOptions<TypeState> where
TypeState: Send,
TypeState: Send,
impl<TypeState> Sync for ConnectionOptions<TypeState> where
TypeState: Sync,
TypeState: Sync,
impl<TypeState> Unpin for ConnectionOptions<TypeState> where
TypeState: Unpin,
TypeState: Unpin,
impl<TypeState> !UnwindSafe for ConnectionOptions<TypeState>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,