Struct async_nats::ConnectOptions
source · [−]pub struct ConnectOptions { /* private fields */ }
Expand description
Connect options.
Implementations
sourceimpl ConnectOptions
impl ConnectOptions
sourcepub fn new() -> Self
pub fn new() -> Self
Enables customization of NATS connection.
Examples
let mut options = async_nats::ConnectOptions::new();
let nc = options.connect("demo.nats.io").await?;
sourcepub async fn connect<A: ToServerAddrs>(&mut self, addrs: A) -> Result<Client>
pub async fn connect<A: ToServerAddrs>(&mut self, addrs: A) -> Result<Client>
Connect to the NATS Server leveraging all passed options.
Examples
let nc = async_nats::ConnectOptions::new().require_tls(true).connect("demo.nats.io").await?;
sourcepub fn add_root_certificates(&mut self, path: PathBuf) -> &mut ConnectOptions
pub fn add_root_certificates(&mut self, path: PathBuf) -> &mut ConnectOptions
Loads root certificates by providing the path to them.
Examples
let nc =
async_nats::ConnectOptions::new().add_root_certificates("mycerts.pem".into()).connect("demo.nats.io").await?;
sourcepub fn add_client_certificate(
&mut self,
cert: PathBuf,
key: PathBuf
) -> &mut ConnectOptions
pub fn add_client_certificate(
&mut self,
cert: PathBuf,
key: PathBuf
) -> &mut ConnectOptions
Loads client certificate by providing the path to it.
Examples
let nc =
async_nats::ConnectOptions::new().add_client_certificate("cert.pem".into(), "key.pem".into()).connect("demo.nats.io").await?;
sourcepub fn require_tls(&mut self, is_required: bool) -> &mut ConnectOptions
pub fn require_tls(&mut self, is_required: bool) -> &mut ConnectOptions
Sets or disables TLS requirement. If TLS connection is impossible while options.require_tls(true)
connection will return error.
Examples
let nc =
async_nats::ConnectOptions::new().require_tls(true).connect("demo.nats.io").await?;
sourcepub fn flush_interval(
&mut self,
flush_interval: Duration
) -> &mut ConnectOptions
pub fn flush_interval(
&mut self,
flush_interval: Duration
) -> &mut ConnectOptions
Sets the interval for flushing. NATS connection will send buffered data to the NATS Server whenever buffer limit is reached, but it is also necessary to flush once in a while if client is sending rarely and small messages. Flush interval allows to modify that interval.
Examples
async_nats::ConnectOptions::new().flush_interval(Duration::from_millis(100)).connect("demo.nats.io").await?;
sourcepub fn ping_interval(&mut self, ping_interval: Duration) -> &mut ConnectOptions
pub fn ping_interval(&mut self, ping_interval: Duration) -> &mut ConnectOptions
Sets how often Client sends PING message to the server.
Examples
async_nats::ConnectOptions::new().flush_interval(Duration::from_millis(100)).connect("demo.nats.io").await?;
Trait Implementations
sourceimpl Clone for ConnectOptions
impl Clone for ConnectOptions
sourcefn clone(&self) -> ConnectOptions
fn clone(&self) -> ConnectOptions
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ConnectOptions
impl Debug for ConnectOptions
sourceimpl Default for ConnectOptions
impl Default for ConnectOptions
sourcefn default() -> ConnectOptions
fn default() -> ConnectOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for ConnectOptions
impl Send for ConnectOptions
impl Sync for ConnectOptions
impl Unpin for ConnectOptions
impl !UnwindSafe for ConnectOptions
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more