问题
Using GetFile I’m collecting files that include JSON records. Each record includes a parameter (let's name it Sensor) that have the Value A or B.
Based on that value I wish to route each record to a different output port – which module I should use? Do I need to split the records or I can stay at the level of the file?
An example of a record that can be found in the file
{"EventTime":"2020-12-07 04:49:00",
"Sensor":"A",
"Keywords":-9223372036854775808,
"EventType":"INFO",
"SeverityValue":2,
"Severity":"INFO",}
回答1:
You could use PartitionRecord with a dynamic property 'Sensor' with value /Sensor
.
If you have 1 FlowFile with 100 Records, which are 20 Sensor A and 80 Sensor B, you'd end up with 2 FlowFiles: FF1 = 20 Records of Sensor A, with an Attribute 'Sensor' = A FF2 = 80 Records of Sensor B, with an Attribute 'Sensor' = B
Then you could RouteOnAttribute on the 'Sensor' attribute.
Alternatively, QueryRecord will let you write a SQL-like query against the records and route the results to a Dynamic Relationship. You could add a Dynamic Property 'SensorA' with value SELECT * FROM FLOWFILE WHERE Sensor = 'A'
, which will send all Records with Sensor = A to a Dynamic Relationship called 'SensorA'. Then add another Dynamic Property for Sensor B. (I didn't test that SQL, adjust as needed)
来源:https://stackoverflow.com/questions/65195628/how-to-route-a-record-event-based-on-content