adamdebreceni commented on code in PR #1432:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1432#discussion_r1018980685
##########
extensions/mqtt/processors/AbstractMQTTProcessor.cpp:
##########
@@ -137,19 +148,45 @@ void AbstractMQTTProcessor::onSchedule(const
std::shared_ptr<core::ProcessContex
void AbstractMQTTProcessor::reconnect() {
if (!client_) {
- logger_->log_error("MQTT client is not existing while trying to
reconnect");
- return;
+ throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "MQTT
client is not existing while trying to reconnect");
}
if (MQTTAsync_isConnected(client_)) {
- logger_->log_info("Already connected to %s, no need to reconnect", uri_);
+ logger_->log_debug("Already connected to %s, no need to reconnect", uri_);
return;
}
- MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;
+
+ MQTTAsync_connectOptions conn_opts;
+ MQTTProperties connect_props = MQTTProperties_initializer;
+ MQTTProperties will_props = MQTTProperties_initializer;
+
+ if (mqtt_version_.value() == MqttVersions::V_5_0) {
+ conn_opts = MQTTAsync_connectOptions_initializer5;
+ conn_opts.onSuccess5 = connectionSuccess5;
+ conn_opts.onFailure5 = connectionFailure5;
+ conn_opts.connectProperties = &connect_props;
+ } else {
+ conn_opts = MQTTAsync_connectOptions_initializer;
+ conn_opts.onSuccess = connectionSuccess;
+ conn_opts.onFailure = connectionFailure;
+ }
+
+ if (mqtt_version_.value() == MqttVersions::V_3_1_0) {
+ conn_opts.MQTTVersion = MQTTVERSION_3_1;
+ } else if (mqtt_version_.value() == MqttVersions::V_3_1_1) {
+ conn_opts.MQTTVersion = MQTTVERSION_3_1_1;
+ }
+
conn_opts.keepAliveInterval = gsl::narrow<int>(keep_alive_interval_.count());
- conn_opts.cleansession = getCleanSession();
- conn_opts.context = this;
- conn_opts.onSuccess = connectionSuccess;
- conn_opts.onFailure = connectionFailure;
+ if (mqtt_version_.value() == MqttVersions::V_5_0) {
+ setMqtt5ConnectOptions(conn_opts, connect_props, will_props);
+ } else {
+ conn_opts.cleansession = getCleanSession();
+ }
+ std::packaged_task<void(MQTTAsync_successData*, MQTTAsync_successData5*,
MQTTAsync_failureData*, MQTTAsync_failureData5*)> connect_finished_task(
+ [this] (MQTTAsync_successData* success_data, MQTTAsync_successData5*
success_data_5, MQTTAsync_failureData* failure_data, MQTTAsync_failureData5*
failure_data_5) {
+ onConnectFinished(success_data, success_data_5, failure_data,
failure_data_5);
+ });
+ conn_opts.context = &connect_finished_task;
Review Comment:
~why do we need this layer of indirection, could we use `this` as
`conn_opts.context` and directly call `onConnectionFinished` on it in the
callbacks?~
Edit: I see that we would like to wait for its completion, makes sense
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]