PahoMqttCpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions
mqtt::connect_options_builder Class Reference

#include <connect_options.h>

Public Types

using self = connect_options_builder
 

Public Member Functions

 connect_options_builder (int ver=MQTTVERSION_DEFAULT)
 
 connect_options_builder (const connect_options &opts)
 
 connect_options_builder (const connect_options &&opts)
 
auto clean_session (bool on=true) -> self &
 
template<class Rep , class Period >
auto keep_alive_interval (const std::chrono::duration< Rep, Period > &interval) -> self &
 
template<class Rep , class Period >
auto connect_timeout (const std::chrono::duration< Rep, Period > &timeout) -> self &
 
auto user_name (string_ref userName) -> self &
 
auto password (binary_ref password) -> self &
 
auto max_inflight (int n) -> self &
 
auto will (const will_options &will) -> self &
 
auto will (will_options &&will) -> self &
 
auto will (const message &msg) -> self &
 
auto ssl (const ssl_options &ssl) -> self &
 
auto ssl (ssl_options &&ssl) -> self &
 
auto token (const token_ptr &tok) -> self &
 
auto servers (const_string_collection_ptr serverURIs) -> self &
 
auto mqtt_version (int ver) -> self &
 
auto automatic_reconnect (bool on=true) -> self &
 
template<class Rep1 , class Period1 , class Rep2 , class Period2 >
auto automatic_reconnect (const std::chrono::duration< Rep1, Period1 > &minRetryInterval, const std::chrono::duration< Rep2, Period2 > &maxRetryInterval) -> self &
 
auto clean_start (bool on=true) -> self &
 
auto properties (const mqtt::properties &props) -> self &
 
auto properties (mqtt::properties &&props) -> self &
 
auto http_headers (const name_value_collection &headers) -> self &
 
auto http_headers (name_value_collection &&headers) -> self &
 
auto http_proxy (const string &httpProxy) -> self &
 
auto https_proxy (const string &httpsProxy) -> self &
 
connect_options finalize ()
 

Static Public Member Functions

static connect_options_builder v3 ()
 
static connect_options_builder v5 ()
 
static connect_options_builder ws ()
 
static connect_options_builder v5_ws ()
 

Detailed Description

Class to build connect options.

Member Typedef Documentation

◆ self

This class

Constructor & Destructor Documentation

◆ connect_options_builder() [1/3]

mqtt::connect_options_builder::connect_options_builder ( int  ver = MQTTVERSION_DEFAULT)
inlineexplicit

Default constructor.

Parameters
verThe MQTT version for the connection. Defaults to the most recent v3 supported by the server.

◆ connect_options_builder() [2/3]

mqtt::connect_options_builder::connect_options_builder ( const connect_options opts)
inlineexplicit

Copy constructor from an existing set of options.

◆ connect_options_builder() [3/3]

mqtt::connect_options_builder::connect_options_builder ( const connect_options &&  opts)
inlineexplicit

Move constructor from an existing set of options.

Member Function Documentation

◆ v3()

static connect_options_builder mqtt::connect_options_builder::v3 ( )
inlinestatic

Creates the default options builder for an MQTT v3.x connection.

Returns
An options builder for an MQTT v3.x connection.

◆ v5()

static connect_options_builder mqtt::connect_options_builder::v5 ( )
inlinestatic

Creates the default options builder for an MQTT v5 connection.

Returns
An options builder for an MQTT v5 connection.

◆ ws()

static connect_options_builder mqtt::connect_options_builder::ws ( )
inlinestatic

Creates the default options builder for an MQTT v3.x connection using WebSockets.

The keepalive interval is set to 45 seconds to avoid webserver 60 second inactivity timeouts.

Returns
An options builder for an MQTT v3.x connection using websockets.

◆ v5_ws()

static connect_options_builder mqtt::connect_options_builder::v5_ws ( )
inlinestatic

Creates the default options for an MQTT v5 connection using WebSocketsThe keepalive interval is set to 45 seconds to avoid webserver 60 second inactivity timeouts.

Returns
An options builder for an MQTT v5 connection using websockets.

◆ clean_session()

auto mqtt::connect_options_builder::clean_session ( bool  on = true) -> self&
inline

Sets whether the server should remember state for the client across reconnects. (MQTT v3.x only)

Parameters
ontrue if the server should NOT remember state for the client across reconnects, false otherwise.

◆ keep_alive_interval()

template<class Rep , class Period >
auto mqtt::connect_options_builder::keep_alive_interval ( const std::chrono::duration< Rep, Period > &  interval) -> self&
inline

Sets the "keep alive" interval with a chrono duration. This is the maximum time that should pass without communications between client and server. If no messages pass in this time, the client will ping the broker.

Parameters
intervalThe keep alive interval.

◆ connect_timeout()

template<class Rep , class Period >
auto mqtt::connect_options_builder::connect_timeout ( const std::chrono::duration< Rep, Period > &  timeout) -> self&
inline

Sets the connect timeout with a chrono duration. This is the maximum time that the underlying library will wait for a connection before failing.

Parameters
timeoutThe connect timeout in seconds.

◆ user_name()

auto mqtt::connect_options_builder::user_name ( string_ref  userName) -> self&
inline

Sets the user name for the connection.

Parameters
userNameThe user name for the connection.

◆ password()

auto mqtt::connect_options_builder::password ( binary_ref  password) -> self&
inline

Sets the password for the connection.

Parameters
passwordThe password for the connection.

◆ max_inflight()

auto mqtt::connect_options_builder::max_inflight ( int  n) -> self&
inline

Sets the maximum number of messages that can be in-flight simultaneously.

Parameters
nThe maximum number of inflight messages.

◆ will() [1/3]

auto mqtt::connect_options_builder::will ( const will_options will) -> self&
inline

Sets the "Last Will and Testament" (LWT) for the connection.

Parameters
willThe LWT options.

◆ will() [2/3]

auto mqtt::connect_options_builder::will ( will_options &&  will) -> self&
inline

Sets the "Last Will and Testament" (LWT) for the connection.

Parameters
willThe LWT options.

◆ will() [3/3]

auto mqtt::connect_options_builder::will ( const message msg) -> self&
inline

Sets the "Last Will and Testament" (LWT) as a message

Parameters
msgThe LWT message

◆ ssl() [1/2]

auto mqtt::connect_options_builder::ssl ( const ssl_options ssl) -> self&
inline

Sets the SSL options for the connection. These will only have an effect if compiled against the SSL version of the Paho C library, and connecting with a secure URI.

Parameters
sslThe SSL options.

◆ ssl() [2/2]

auto mqtt::connect_options_builder::ssl ( ssl_options &&  ssl) -> self&
inline

Sets the SSL options for the connection. These will only have an effect if compiled against the SSL version of the Paho C library, and connecting with a secure URI.

Parameters
sslThe SSL options.

◆ token()

auto mqtt::connect_options_builder::token ( const token_ptr tok) -> self&
inline

Sets the callback context to a delivery token.

Parameters
tokThe delivery token to be used as the callback context.

◆ servers()

auto mqtt::connect_options_builder::servers ( const_string_collection_ptr  serverURIs) -> self&
inline

Sets the list of servers to which the client will connect.

Parameters
serverURIsA pointer to a collection of server URI's. Each entry should be of the form protocol://host:port where protocol must be tcp or ssl. For host, you can specify either an IP address or a domain name.

◆ mqtt_version()

auto mqtt::connect_options_builder::mqtt_version ( int  ver) -> self&
inline

Sets the version of MQTT to be used on the connect.

This will also set other connect options to legal values dependent on the selected version.

Parameters
verThe MQTT protocol version to use for the connection:
  • MQTTVERSION_DEFAULT (0) = default: start with 3.1.1, and if that fails, fall back to 3.1
  • MQTTVERSION_3_1 (3) = only try version 3.1
  • MQTTVERSION_3_1_1 (4) = only try version 3.1.1
  • MQTTVERSION_5 (5) = only try version 5
Note that it is preferable to create the options builder for the desired version rather than using this function to change the version after some parameters have already been set. If you do use this function, call it before setting any other version-specific options.
See also
connect_options_builder::v5()

◆ automatic_reconnect() [1/2]

auto mqtt::connect_options_builder::automatic_reconnect ( bool  on = true) -> self&
inline

Enable or disable automatic reconnects. The retry intervals are not affected.

Parameters
onWhether to turn reconnects on or off

◆ automatic_reconnect() [2/2]

template<class Rep1 , class Period1 , class Rep2 , class Period2 >
auto mqtt::connect_options_builder::automatic_reconnect ( const std::chrono::duration< Rep1, Period1 > &  minRetryInterval,
const std::chrono::duration< Rep2, Period2 > &  maxRetryInterval 
) -> self&
inline

Enable or disable automatic reconnects.

Parameters
minRetryIntervalMinimum retry interval. Doubled on each failed retry.
maxRetryIntervalMaximum retry interval. The doubling stops here on failed retries.

◆ clean_start()

auto mqtt::connect_options_builder::clean_start ( bool  on = true) -> self&
inline

Sets the 'clean start' flag for the connection. (MQTT v5 only)

Parameters
ontrue to set the 'clean start' flag for the connect, false otherwise.

◆ properties() [1/2]

auto mqtt::connect_options_builder::properties ( const mqtt::properties props) -> self&
inline

Sets the properties for the connect message.

Parameters
propsThe properties for the connect message.

◆ properties() [2/2]

auto mqtt::connect_options_builder::properties ( mqtt::properties &&  props) -> self&
inline

Sets the properties for the connect message.

Parameters
propsThe properties for the connect message.

◆ http_headers() [1/2]

auto mqtt::connect_options_builder::http_headers ( const name_value_collection headers) -> self&
inline

Sets the HTTP headers for the connection.

Parameters
headersThe header nam/value collection.

◆ http_headers() [2/2]

auto mqtt::connect_options_builder::http_headers ( name_value_collection &&  headers) -> self&
inline

Sets the HTTP headers for the connection.

Parameters
headersThe header nam/value collection.

◆ http_proxy()

auto mqtt::connect_options_builder::http_proxy ( const string httpProxy) -> self&
inline

Sets the HTTP proxy setting.

Parameters
httpProxyThe HTTP proxy setting. An empty string means no proxy.

◆ https_proxy()

auto mqtt::connect_options_builder::https_proxy ( const string httpsProxy) -> self&
inline

Sets the secure HTTPS proxy setting.

Parameters
httpsProxyThe HTTPS proxy setting. An empty string means no proxy.

◆ finalize()

connect_options mqtt::connect_options_builder::finalize ( )
inline

Finish building the options and return them.

Returns
The option struct as built.

The documentation for this class was generated from the following file: