2

The DBCPConnectionPool Service requires 5 connection parameters to establish connection to a database as shown in the picture below [Marked Yellow] enter image description here

I used UpdateAttribute Processor to manually add these 5 connection parameters and gave them their respective values as shown in the picture below [Marked Yellow] enter image description here

Now, when I was trying to read the values for the connection parameters in DBCPConnectionPool Service through these attributes (Shown in picture below) , I was unable to read them. enter image description here

To know the reason why the DBCPConnectionPool Service was unable to read the Flowfile attributes, I went ahead to check the source code for both DBCPConnectionPool Service and UpdateAttribute Processor.

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java

Souce code for DBCPConnectionPool Service : enter image description here

Souce code for UpdateAttribute Processor : enter image description here

Thus, I came to know the reason why it was unable to read the values from FlowFile attributes. This is because the ExpressionLanguageScope is limited to VARIABLE_REGISTRY and not FLOWFILE_ATTRIBUTES.

Now, My Question is that why the ExpressionLanguageScope for DBCPConnectionPool Service is limited to VARIABLE_REGISTRY. What is the reason for this limitation? The reason why I am asking this question is because I want to read the values for the connection parameters through FlowFile attributes.

4

1 回答 1

6

对于在NiFi 开发者邮件列表中提出的相同问题,安迪以最好的方式回答了它。DBCPConnectionPool服务或任何控制器服务使用的原因ExpressionLanguageScope.VARIABLE_REGISTRY是,控制器服务无权访问流文件,因此它不会读取流文件的属性。而对于这个问题,为什么它只支持VARIABLE_REGISTRY是:

  • 仅仅因为它不读取流文件属性并不意味着它不应该使用其他地方的属性。
  • 引入的主要原因之一VARIABLE_REGISTRY是避免暴露敏感值,当我们将这些值作为流文件属性传递时就是这种情况。控制器服务适合这种情况,因为其中许多使用敏感属性,例如Password.

而且,如果您假设只需将这些属性的范围更改为 就可以使其工作,那ExpressionLanguageScope.FLOWFILE_ATTRIBUTES您就错了。更改它们没有意义并且不起作用,原因再次是控制器服务永远无法访问流文件。

如果您有特定要求,您需要为不同的流文件使用不同的属性值,Andy 在原始开发线程中分享了一些我再次发布的链接:

于 2018-04-12T10:29:53.380 回答