Reputation: 53
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.
Upvotes: 2
Views: 2542
Reputation: 196
I faced this some time back. I used InvokeHTTP
processor and used nifi-api/process-groups/${process_group_id}
Web Service
This is how I implemented:
InvokeHTTP
processor and set HTTP Method
to GET
Remote URL
to http://{nifi-instance}:{port}/nifi-api/process-groups/${action_group_process_group_id}
Please let me know if you need the XML file that I am using. I can share that. It just works fine for me
Upvotes: 0
Reputation: 12103
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.
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.
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.
Upvotes: 1