在 executeScript 处理器中读取外部属性

hap*_*ppy 1 apache-nifi

我在 nifi.variable.registry.properties 的 nifi.properties 中配置了一个外部属性文件。我想在 python 的 executeScript 处理器中读取这个属性。我用过 str(context.getProperty('URL'))但它不工作

dag*_*ett 6

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-scripting-nar/1.9.1/org.apache.nifi.processors.script.ExecuteScript/index.html


  • 为 ExecuteScript 处理器声明一个动态属性。例如VAR_URL = ${URL}
  • 然后在脚本中您可以访问此属性: VAR_URL.evaluateAttributeExpressions(flowFile).getValue()

或者,如果您不想为处理器声明属性,并且确定在某处声明了该属性,则可以使用以下代码:

context.newPropertyValue( '${URL}' ).evaluateAttributeExpressions().getValue()
Run Code Online (Sandbox Code Playgroud)

注意:不要在周围使用双引号,${URL}因为在评估 nifi 表达式之前,此表达式将作为常规字符串处理...