NiFi 如何使用(Java)通过自定义处理器获取当前处理器名称和处理器组名称 [英] NiFi How to get the current processor Name and Processor group name through the custom processor using (Java)

查看:71
本文介绍了NiFi 如何使用(Java)通过自定义处理器获取当前处理器名称和处理器组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java 创建 NiFi 自定义处理器,其中一项要求是使用 java 代码获取先前的处理器名称和处理器组(如面包屑).

I'm Creating the NiFi Custom processor using Java, one of the requirement is to get the previous processor name and processor group (like a breadcrumb) using java code.

推荐答案

之前的处理器名称和进程组名称不能立即(也不打算)提供给处理器,您能否详细解释一下您的用例?您也许可以使用 SiteToSiteProvenanceReportingTask 将出处信息发送回您自己的 NiFi 实例(例如输入端口)并找到与 FlowFiles 进入您的自定义处理器对应的事件,这些事件应该具有源(前一个)处理器和目标(您的自定义)处理器.

The previous processor name and process group name is not immediately (nor meant to be) available to processors, can you explain more about your use case? You can perhaps use a SiteToSiteProvenanceReportingTask to send provenance information back to your own NiFi instance (an Input Port, e.g.) and find the events that correspond to FlowFiles entering your custom processor, the events should have the source (previous) processor and destination (your custom) processor.

例如,如果您使用 InvokeScriptedProcessor 和 Groovy 编写自定义处理器,那么您可以改变规则";并获取先前的处理器名称等,因为 Groovy 允许访问私有成员,并且您可以假设 onTrigger 中的 ProcessContext 的实现是 StandardProcessContext 的实例,因此您可以获取其成员,其中包括上游连接以及前一个处理器.但是,对于特定的 FlowFile,我不确定您是否可以使用这种方法来了解它来自哪个上游处理器.

If instead you code your custom processor using InvokeScriptedProcessor with Groovy for example, then you can "bend the rules" and get at the previous processor name and such, as Groovy allows access to private members and you can assume the implementation of the ProcessContext in onTrigger is an instance of StandardProcessContext, so you can get at its members which include upstream connections and thus the previous processor. For a particular FlowFile though, I'm not sure you can use this approach to know which upstream processor it came from.

或者,您可以在每个前一个处理器"之后添加一个 UpdateAttribute.使用有关该处理器的信息设置属性,但必须对其进行硬编码并应用于流程的每个相应部分.

Alternatively, you could add an UpdateAttribute after each "previous processor" to set attribute(s) with the information about that processor, but that has to be hardcoded and applied to every corresponding part of the flow.

这篇关于NiFi 如何使用(Java)通过自定义处理器获取当前处理器名称和处理器组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆