英文:
Nifi: append an flowfile attribute to the flowfile content (at the end)
问题
I am using putdatabaserecord to store a value into DB.
我正在使用putdatabaserecord将一个值存储到数据库中。
I also have a flow based on failure link to (this processor), so that failed record will be stored in disc for troubleshooting.
我还有一个基于失败链接的流程,以便将失败的记录存储在磁盘上以进行故障排除。
I can store the failed record in disc by using putfile processor.
我可以使用putfile处理器将失败的记录存储在磁盘上。
Now i wanted it to be more informative during debugging. As the attribute "putdatabaserecord.error" contains the error reason, i want to append the flowfile content with this error reason as well.
现在,在调试过程中,我希望它更具信息性。由于属性"putdatabaserecord.error"包含错误原因,我想将flowfile内容与此错误原因一起附加。
I tried to achieve this using below flow. (attached visualization)
我尝试使用下面的流程来实现这一点。(附有可视化)
putsql/putdbrecord -> failure -> updateattribute (this is to give the flowfile a realistic name) -> attributesToJson (destination flowfileattribute/content -> putfile
putsql/putdbrecord -> 失败 -> updateattribute(这是为了给flowfile一个逼真的名称) -> attributesToJson(目标flowfileattribute/content -> putfile
but in attributesTOJson , if the destination is kept as flowfileattribute, the flowfile don't get this attribute and if destination is kept as flowfile content, original flowfile content is overrided.
但在attributesToJson中,如果目标保持为flowfileattribute,flowfile不会获得此属性,如果目标保持为flowfile content,则原始flowfile内容会被覆盖。
My requirement is to append this single attribute to the existing flowfile content and not to override it.
我的要求是将这个单一属性附加到现有的flowfile内容,而不是覆盖它。
Any help or suggestion is greatly appreciated.
非常感谢任何帮助或建议。
英文:
I am using putdatabaserecord to store a value into DB.
I also have a flow based on failure link to (this processor), so that failed record will be stored in disc for troubleshooting.
I can store the failed record in disc by using putfile processor.
Now i wanted it to be more informative during debugging. As the attribute "putdatabaserecord.error" contains the error reason, i want to append the flowfile content with this error reason as well.
I tried to achieve this using below flow. (attached visualization)
putsql/putdbrecord -> failure-> updateattribute (this is to give the flowfile a realistic name)-> attributesToJson (destination flowfileattribute/content -> putfile
but in attributesTOJson , if the destination is kept as flowfileattribute, the flowfile don't get this attribute and if destination is kept as flowfile content, original flowfile content is overrided.
My requirement is to append this single attribute to the existing flowfile content and not to override it.
答案1
得分: 1
以下是翻译好的部分:
使用ScriptedTransformRecord
processor:
记录读取器
:JsonTreeReader
记录写入器
:JsonRecordSetWriter
脚本语言
:Groovy
脚本内容
:
record.setValue("error_msg", attributes["putdatabaserecord.error"])
record
输入(JSON):
[
{
"id": 280,
"index_id": 1,
"state_id": 1
}
]
输出(JSON):
[
{
"id": 280,
"index_id": 1,
"state_id": 1,
"error_msg": "来自属性的值"
}
]
英文:
Use a ScriptedTransformRecord
processor:
Record Reader
:JsonTreeReader
Record Writer
:JsonRecordSetWriter
Script Language
:Groovy
Script Body
:
record.setValue("error_msg", attributes["putdatabaserecord.error"])
record
Input (JSON):
[
{
"id": 280,
"index_id": 1,
"state_id":1
}
]
Output (JSON):
[
{
"id": 280,
"index_id": 1,
"state_id": 1,
"error_msg": "value from attribute"
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论