[][src]Struct nats::ConnectionOptions

pub struct ConnectionOptions<TypeState> { /* fields omitted */ }

A configuration object for a NATS connection.

Methods

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]

Authenticate with NATS using a username and password.

Example

let nc = nats::ConnectionOptions::new()
    .with_user_pass("derek", "s3cr3t!")
    .connect("demo.nats.io")?;

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]

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]

Set the maximum amount of bytes to buffer when accepting outgoing traffic in disconnected mode.

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.

Example

let options = nats::ConnectionOptions::new();
let nc = options.connect("demo.nats.io")?;

pub fn set_disconnect_callback<F>(self, cb: F) -> Self where
    F: Fn(&ServerInfo) + Send + Sync + 'static, 
[src]

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(&ServerInfo) + Send + Sync + 'static, 
[src]

Set a callback to be executed when connectivity to a server has been established.

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("demo.nats.io")?;

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 mut tls_connector = nats::tls::builder()
    .identity(nats::tls::Identity::from_pkcs12(b"der_bytes", "my_password").unwrap())
    .add_root_certificate(nats::tls::Certificate::from_pem(b"my_pem_bytes").unwrap())
    .build()
    .unwrap();

let nc = nats::ConnectionOptions::new()
    .tls_connector(tls_connector)
    .connect("demo.nats.io")?;

Trait Implementations

impl<T> Debug for ConnectionOptions<T>[src]

impl Default for ConnectionOptions<NoAuth>[src]

Auto Trait Implementations

impl<TypeState> !RefUnwindSafe for ConnectionOptions<TypeState>

impl<TypeState> Send for ConnectionOptions<TypeState> where
    TypeState: Send

impl<TypeState> Sync for ConnectionOptions<TypeState> where
    TypeState: Sync

impl<TypeState> Unpin for ConnectionOptions<TypeState> where
    TypeState: Unpin

impl<TypeState> !UnwindSafe for ConnectionOptions<TypeState>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,