PrevUpHomeNext
mqtt_client::brokers

Assign a list of Brokers that the Client will attempt to connect to.

mqtt_client & brokers(
    std::string hosts,
    uint16_t default_port = 1883
) = default;
Description

The Client will cycle through the list of hosts, attempting to establish a connection with each until it successfully establishes a connection.

Parameters

Name

Description

hosts

List of Broker addresses and ports. Address and ports are separated with a colon : while pairs of addresses and ports are separated with a comma ,.

default_port

The default port to connect to in case the port is not explicitly specified in the hosts list.

[Important] Important

This function takes action when the client is in a non-operational state, meaning the mqtt_client::async_run function has not been invoked. Furthermore, you can use this function after the mqtt_client::cancel function has been called, before the mqtt_client::async_run function is invoked again.

Example

Some valid hosts string:

std::string valid_hosts_1 = "broker1:1883, broker2, broker3:1883";
std::string valid_hosts_2 = "broker1";

PrevUpHomeNext