pub struct ClientBuilder { /* private fields */ }
Expand description
Client builder.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new() -> ClientBuilder
pub fn new() -> ClientBuilder
Creates a ClientBuilder
Sourcepub fn from_config(
path: impl Into<PathBuf>,
) -> Result<ClientBuilder, ConfigError>
pub fn from_config( path: impl Into<PathBuf>, ) -> Result<ClientBuilder, ConfigError>
Creates a ClientBuilder
using a configuration file as the initial state.
Sourcepub fn client(self) -> Result<Client, Vec<String>>
pub fn client(self) -> Result<Client, Vec<String>>
Yields a Client
from the values set by the builder. If the builder is not in a valid state
it will return a list of errors.
Sourcepub fn config(self) -> ClientConfig
pub fn config(self) -> ClientConfig
Yields a ClientConfig
from the values set by the builder.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Tests if the builder is in a valid state to be able to yield a Client
.
Sourcepub fn application_name(self, application_name: impl Into<String>) -> Self
pub fn application_name(self, application_name: impl Into<String>) -> Self
Sets the application name.
Sourcepub fn application_uri(self, application_uri: impl Into<String>) -> Self
pub fn application_uri(self, application_uri: impl Into<String>) -> Self
Sets the application uri
Sourcepub fn product_uri(self, product_uri: impl Into<String>) -> Self
pub fn product_uri(self, product_uri: impl Into<String>) -> Self
Sets the product uri.
Sourcepub fn create_sample_keypair(self, create_sample_keypair: bool) -> Self
pub fn create_sample_keypair(self, create_sample_keypair: bool) -> Self
Sets whether the client should generate its own key pair if there is none found in the pki directory.
Sourcepub fn certificate_path(self, certificate_path: impl Into<PathBuf>) -> Self
pub fn certificate_path(self, certificate_path: impl Into<PathBuf>) -> Self
Sets a custom client certificate path. The path is required to be provided as a partial path relative to the PKI directory. If set, this path will be used to read the client certificate from disk. The certificate can be in either the .der or .pem format.
Sourcepub fn private_key_path(self, private_key_path: impl Into<PathBuf>) -> Self
pub fn private_key_path(self, private_key_path: impl Into<PathBuf>) -> Self
Sets a custom private key path. The path is required to be provided as a partial path relative to the PKI directory. If set, this path will be used to read the private key from disk.
Sourcepub fn trust_server_certs(self, trust_server_certs: bool) -> Self
pub fn trust_server_certs(self, trust_server_certs: bool) -> Self
Sets whether the client should automatically trust servers. If this is not set then
the client will reject the server upon first connect and the server’s certificate
must be manually moved from pki’s /rejected
folder to the /trusted
folder. If it is
set, then the server cert will automatically be stored in the /trusted
folder.
Sourcepub fn verify_server_certs(self, verify_server_certs: bool) -> Self
pub fn verify_server_certs(self, verify_server_certs: bool) -> Self
Sets whether the client should verify server certificates. Regardless of this setting,
server certificates are always checked to see if they are trusted and have a valid key
length. In addition (if verify_server_certs
is unset or is set to true
) it will
verify the hostname, application uri and the not before / after values to ensure validity.
Sourcepub fn pki_dir(self, pki_dir: impl Into<PathBuf>) -> Self
pub fn pki_dir(self, pki_dir: impl Into<PathBuf>) -> Self
Sets the pki directory where client’s own key pair is stored and where /trusted
and
/rejected
server certificates are stored.
Sourcepub fn preferred_locales(self, preferred_locales: Vec<String>) -> Self
pub fn preferred_locales(self, preferred_locales: Vec<String>) -> Self
Sets the preferred locales of the client. These are passed to the server during session creation to ensure localized strings are in the preferred language.
Sourcepub fn default_endpoint(self, endpoint_id: impl Into<String>) -> Self
pub fn default_endpoint(self, endpoint_id: impl Into<String>) -> Self
Sets the id of the default endpoint to connect to.
Sourcepub fn endpoint(
self,
endpoint_id: impl Into<String>,
endpoint: ClientEndpoint,
) -> Self
pub fn endpoint( self, endpoint_id: impl Into<String>, endpoint: ClientEndpoint, ) -> Self
Adds an endpoint to the list of endpoints the client knows of.
Sourcepub fn endpoints(
self,
endpoints: Vec<(impl Into<String>, ClientEndpoint)>,
) -> Self
pub fn endpoints( self, endpoints: Vec<(impl Into<String>, ClientEndpoint)>, ) -> Self
Adds multiple endpoints to the list of endpoints the client knows of.
Sourcepub fn user_token(
self,
user_token_id: impl Into<String>,
user_token: ClientUserToken,
) -> Self
pub fn user_token( self, user_token_id: impl Into<String>, user_token: ClientUserToken, ) -> Self
Adds a user token to the list supported by the client.
Sourcepub fn channel_lifetime(self, channel_lifetime: u32) -> Self
pub fn channel_lifetime(self, channel_lifetime: u32) -> Self
Requested secure channel token lifetime, in milliseconds. The channel will be renewed once 3/4 of the lifetime has elapsed. Setting this too low is likely to cause issues.
Sourcepub fn session_retry_limit(self, session_retry_limit: i32) -> Self
pub fn session_retry_limit(self, session_retry_limit: i32) -> Self
Sourcepub fn session_retry_initial(self, session_retry_initial: Duration) -> Self
pub fn session_retry_initial(self, session_retry_initial: Duration) -> Self
Initial time between retries when backing off on session reconnects.
Sourcepub fn session_retry_max(self, session_retry_max: Duration) -> Self
pub fn session_retry_max(self, session_retry_max: Duration) -> Self
Maximum time between retries when backing off on session reconnects.
Sourcepub fn keep_alive_interval(self, keep_alive_interval: Duration) -> Self
pub fn keep_alive_interval(self, keep_alive_interval: Duration) -> Self
Time between making simple Read requests to the server to check for liveness and avoid session timeouts.
Sourcepub fn max_array_length(self, max_array_length: usize) -> Self
pub fn max_array_length(self, max_array_length: usize) -> Self
Maximum number of array elements. 0 actually means 0, i.e. no array permitted
Sourcepub fn max_byte_string_length(self, max_byte_string_length: usize) -> Self
pub fn max_byte_string_length(self, max_byte_string_length: usize) -> Self
Maximum length in bytes of a byte string. 0 actually means 0, i.e. no byte strings permitted.
Sourcepub fn max_chunk_count(self, max_chunk_count: usize) -> Self
pub fn max_chunk_count(self, max_chunk_count: usize) -> Self
Sets the maximum number of chunks in an outgoing message. 0 means no limit.
Sourcepub fn max_chunk_size(self, max_chunk_size: usize) -> Self
pub fn max_chunk_size(self, max_chunk_size: usize) -> Self
Maximum size of each individual outgoing message chunk.
Sourcepub fn max_incoming_chunk_size(self, max_incoming_chunk_size: usize) -> Self
pub fn max_incoming_chunk_size(self, max_incoming_chunk_size: usize) -> Self
Maximum size of each incoming chunk.
Sourcepub fn max_message_size(self, max_message_size: usize) -> Self
pub fn max_message_size(self, max_message_size: usize) -> Self
Sets the maximum outgoing message size in bytes. 0 means no limit.
Sourcepub fn max_string_length(self, max_string_length: usize) -> Self
pub fn max_string_length(self, max_string_length: usize) -> Self
Maximum length in bytes of a string. 0 actually means 0, i.e. no string permitted.
Sourcepub fn max_failed_keep_alive_count(
self,
max_failed_keep_alive_count: u64,
) -> Self
pub fn max_failed_keep_alive_count( self, max_failed_keep_alive_count: u64, ) -> Self
Maximum number of failed keep alives before the client will be forcibly closed. Set this to zero to never close the connection due to failed keepalives.
Note that this should not be necessary to set if the server is compliant, only if it ends up in a bad state that cannot be recovered from easily.
Sourcepub fn request_timeout(self, request_timeout: Duration) -> Self
pub fn request_timeout(self, request_timeout: Duration) -> Self
Set the timeout on requests sent to the server.
Sourcepub fn publish_timeout(self, publish_timeout: Duration) -> Self
pub fn publish_timeout(self, publish_timeout: Duration) -> Self
Set the timeout on publish requests sent to the server.
Sourcepub fn min_publish_interval(self, min_publish_interval: Duration) -> Self
pub fn min_publish_interval(self, min_publish_interval: Duration) -> Self
Set the lowest allowed publishing interval by the client. The server may also enforce its own minimum.
Sourcepub fn ignore_clock_skew(self, ignore_clock_skew: bool) -> Self
pub fn ignore_clock_skew(self, ignore_clock_skew: bool) -> Self
Sets whether the client should ignore clock skew so the client can make a successful connection to the server, even when the client and server clocks are out of sync.
Sourcepub fn recreate_monitored_items_chunk(
self,
recreate_monitored_items_chunk: usize,
) -> Self
pub fn recreate_monitored_items_chunk( self, recreate_monitored_items_chunk: usize, ) -> Self
When a session is recreated on the server, the client will attempt to transfer monitored subscriptions from the old session to the new. This is the maximum number of monitored items to create per request.
Sourcepub fn recreate_subscriptions(self, recreate_subscriptions: bool) -> Self
pub fn recreate_subscriptions(self, recreate_subscriptions: bool) -> Self
Automatically recreate subscriptions on reconnect, by first calling
crate::Session::transfer_subscriptions
, then attempting to recreate
subscriptions if that fails.
Defaults to true
. Note that if you disable this feature, you will need to
handle cleanup of the subscriptions in the session yourself.
Sourcepub fn session_name(self, session_name: impl Into<String>) -> Self
pub fn session_name(self, session_name: impl Into<String>) -> Self
Session name - the default name to use for a new session
Sourcepub fn session_timeout(self, session_timeout: u32) -> Self
pub fn session_timeout(self, session_timeout: u32) -> Self
Sets the session timeout period, in milliseconds.