Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
boost::mqtt5::mqtt_client::brokers

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

Synopsis
boost::mqtt5::mqtt_client&
brokers(
    std::string hosts,
    uint16_t default_port = 1883);
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.

Attention

This function has no effect while the Client is running. Call it before async_run, or after cancel or async_disconnect and before invoking async_run again.

Example

Some valid hosts string:

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

PrevUpHomeNext