You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "nandorsoma (via GitHub)" <gi...@apache.org> on 2023/06/07 11:39:06 UTC

[GitHub] [nifi] nandorsoma commented on a diff in pull request #7352: NIFI-11609 Support Request-Response pattern in MQTT5 Processors

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


##########
nifi-nar-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/PublishMQTT.java:
##########
@@ -328,21 +439,57 @@ public void process(ProcessContext context, FlowFile flowfile, InputStream in, S
 
                     baos.reset();
 
+                    String topic;
+                    if (topicRecordPath != null) {
+                        topic = extractRecordValue(record, topicRecordPath);
+                    } else {
+                        topic = context.getProperty(PROP_TOPIC).evaluateAttributeExpressions(flowfile).getValue();;
+                    }
+
+                    String correlationData;
+                    if (correlationDataRecordPath != null) {
+                        correlationData = extractRecordValue(record, correlationDataRecordPath);
+                    } else {
+                        correlationData = context.getProperty(PROP_CORRELATION_DATA).evaluateAttributeExpressions(flowfile).getValue();
+                    }
+
                     try (final RecordSetWriter writer = writerFactory.createWriter(logger, schema, baos, flowfile)) {
                         writer.write(record);
                         writer.flush();
                     }
 
                     final byte[] messageContent = baos.toByteArray();
 
-                    publishMessage(context, flowfile, topic, messageContent);
+                    publishMessage(context, flowfile, topic, correlationData, messageContent);
                     processedRecords.getAndIncrement();
                 }
             } catch (SchemaNotFoundException | MalformedRecordException e) {
                 throw new ProcessException("An error happened during creating components for serialization.", e);
             }
         }
 
+        private String extractRecordValue(Record record, RecordPath recordPath) {
+            final Optional<FieldValue> fv = recordPath.evaluate(record).getSelectedFields().findFirst();
+            if (fv.isPresent()) {

Review Comment:
   It is a bit misleading, because FieldValue is present even when there is no result with a given record path. This makes me wonder that is it a valid scenario when fv is empty.



-- 
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-unsubscribe@nifi.apache.org

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