nandorsoma commented on code in PR #7032:
URL: https://github.com/apache/nifi/pull/7032#discussion_r1143140131


##########
nifi-nar-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/adapters/PahoMqttClientAdapter.java:
##########
@@ -189,4 +172,53 @@ private static org.eclipse.paho.client.mqttv3.MqttClient 
createClient(URI broker
         }
     }
 
+    /**
+     * Paho API uses the same callback for the publisher and consumer as well.
+     * Because of that, DefaultMqttCallback sets some reasonable default logs
+     * to make it easier to track misconfiguration errors.
+     * <p>
+     * In case of subscribing clients messageArrived needs to be overridden.
+     */
+    private class DefaultMqttCallback implements MqttCallback {
+
+        @Override
+        public void connectionLost(Throwable cause) {
+            logger.error("Connection to {} lost", 
clientProperties.getRawBrokerUris(), cause);
+        }
+
+        @Override
+        public void messageArrived(String topic, MqttMessage message) {
+            logger.error(String.format("MQTT message arrived { topic:%s; 
payload:%s}", topic, Arrays.toString(message.getPayload())));

Review Comment:
   In the original code, a comment implied that it was an unlikely situation. 
The main issue is that the Paho library uses the same interface regardless of 
whether the client is a subscriber or publisher. In the case of the publisher, 
this callback doesn't make sense. That's why it is logged with an error. But I 
see it is confusing, so I'll add that comment back.



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to