问题
I want to access multiple databases depending on the 'database.name' attribute sent in the input flowfile to ExecuteGroovyStript processor.
In 'ExecuteGroovyStript' processor I have a property 'SQL.clientdb' which point to 'lookup' service. At the same time I have commissioned a 'DBCPConnectionPool' service with all the required details and its 'name' property similar to value of 'database.name'.
The way in which I'm trying to access the pool service is:
def clientDb = SQL.clientdb.getConnection(flowFile.getAttributes())
Error which I receive after running the Groovy processor is
org.apache.nifi.processor.exception.ProcessException: Attributes must contain an attribute name 'database.name': org.apache.nifi.processor.exception.ProcessException: Attributes must contain an attribute name 'database.name'
Please find below links of images which shows further details:
- Configuration of 'ExecuteScript'
- Connection pool services
- Attributes of input file
回答1:
Check the additional details documentation of the ExecuteGroovyScript processor
For all SQL.*
parameters connection to the database obtained from corresponding connection pool automatically on trigger. And SQL.xxx
variable references groovy.sql.Sql object
If you want to access any controller service - use CTL.
prefix for your parameter.
In this case the variable CTL.xxx
provides a link to a ControllerService directly.
来源:https://stackoverflow.com/questions/57883900/how-to-use-dbcpconnectionpoollookup-controllor-service-in-executegroovyscript