问题描述
我正在使用 GetFile 收集包含 JSON 记录的文件.每条记录都包含一个具有值 A 或 B 的参数(让我们将其命名为 Sensor).
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",}
推荐答案
你可以使用 PartitionRecord 具有值为 /的动态属性 'Sensor'传感器
.
You could use PartitionRecord with a dynamic property 'Sensor' with value /Sensor
.
如果您有 1 个包含 100 个记录的 FlowFile,即 20 个传感器 A 和 80 个传感器 B,您最终会得到 2 个 FlowFile:FF1 = 传感器 A 的 20 条记录,属性传感器"= AFF2 = 传感器 B 的 80 条记录,属性为传感器"= B
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' = AFF2 = 80 Records of Sensor B, with an Attribute 'Sensor' = B
然后您可以在传感器"属性上使用 RouteOnAttribute.
Then you could RouteOnAttribute on the 'Sensor' attribute.
或者,QueryRecord 将让您针对记录编写类似 SQL 的查询并将结果路由到动态关系.您可以添加值为 SELECT * FROM FLOWFILE WHERE Sensor = 'A'
的动态属性SensorA",这会将所有 Sensor = A 的记录发送到名为SensorA"的动态关系.然后为传感器 B 添加另一个动态属性.(我没有测试那个 SQL,根据需要调整)
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)
这篇关于如何根据内容路由记录\事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!