Using a Python processor
Python processors in MiNiFi C++ are loaded from external files, and they keep running a function, while retaining the interpreter state. This makes them well-suited for tasks that require maintaining state between runs or executing initialization logic to be run only once. Learn how to integrate custom code seamlessly into a MiNiFi C++ agent by utilizing custom Python processors. You can unlock the full potential of your MiNiFi C++ agent by enhancing its functionality with the flexibility offered by Python processors.
- At startup, the MiNiFi C++ agent reads the Python script directory specified
minifi.propertiesfile as the value of the
nifi.python.processor.dirproperty. By default, this directory is set to MINIFI_HOME/minifi-python.
- The agent scans the directory for compatible scripts and automatically registers them for use.
- Python files are evaluated during startup. Their
onSchedulefunction is invoked before starting a flow and their
onTriggerfunction is called regularly as the processor is scheduled.
#!/usr/bin/env python def describe(processor): processor.setDescription("Adds an attribute to your flow files") def onInitialize(processor): processor.setSupportsDynamicProperties() def onTrigger(context, session): flow_file = session.get() if flow_file is not None: flow_file.addAttribute("Python attribute", "attributevalue") session.transfer(flow_file, REL_SUCCESS)
To add or update processors, place the Python files in the designated script directory and restart the agent.