Cannot (reconnect) to mosquitto after broker restarted [message #1849822] |
Thu, 03 February 2022 15:15 |
Tamir Michael Messages: 2 Registered: February 2022 |
Junior Member |
|
|
Hello and thanks for reading,
I have trouble re-connecting to mosquitto after it has been restrated.
At first, my program is registered to mosquitto as expected. However, after the broker is restarted (creating a new instance of the broker; I have no control over that) I must re-establish connection with it but the call to connect() below hangs:
mosquitto_lib_cleanup();
reinitialise(("mosq/" + m_ClientId + "/" + m_ServiceName + "//").c_str(), true);
if (mosqpp::lib_init() != MOSQ_ERR_SUCCESS)
{
throw std::runtime_error("CMQTTCommunicator: can't intialize library.");
}
mosqpp::mosquittopp::int_option(MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5);
// Last will and testament
const std::string WillMessage = Json(Json::object{{ "service", m_ServiceName }, {"status", "Disconnected"}}).dump();
will_set((m_FullServiceIdentifier + "status").c_str(), WillMessage.length(), WillMessage.c_str(), static_cast<int>(EQualityOfService::DeliverAtLeastOnce));
if (connect(m_MQTTBrokerAddress.GetIPAddress().ToString().c_str(), m_MQTTBrokerAddress.GetPort(), KeepAliveSec) != MOSQ_ERR_SUCCESS)
{
throw CApplicationException("CMQTTCommunicator: could not connect to mosquitto broker");
}
I do not think I can use reconnect() here at the broker is restarted.
Do you see why this is the case? What am I missing?
Thanks in advance!
[Updated on: Fri, 04 February 2022 08:04] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.83015 seconds