Skip to main content
azure
Gold ⭐️
Jan 12, 2019 2:53 AM UTC
Solved

Nifi: Multiple databases , same query, how do pass database name to the connection string?

Hi,

I'm trying to connect to different databases that all have the same structure and execute the same query on them. However, i can't figure out how to give this to nifi execute SQL processor and i'm having to create a processor for every connection to the database. IS there a way for me to create a list of connection strings and then simply loop through them?

i.e. i need to dynamically assign the connection pooling service to the processor. How?

Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
Jan 12, 2019 10:58 AM UTC

@Yasir Khokhar

Starting from NiFi-1.7 version we can dynamically assign connection pooling service by using

DBCPConnectionPoolLookup controller service.

From documentation:

1.Provides a DBCPService that can be used to dynamically select another DBCPService. This service requires an attribute named 'database.name' to be passed in when asking for a connection, and will throw an exception if the attribute is missing.
2.The value of 'database.name' will be used to select the DBCPService that has been registered with that name.
3.This will allow multiple DBCPServices to be defined and registered, and then selected dynamically at runtime by tagging flow files with the appropriate 'database.name' attribute

If you are using NiFi version <1.7.0 then we need to have to define each DBCPConnection controller service for each connection of ExecuteSql processor.

7 replies

Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
Jan 12, 2019 10:58 AM UTC

@Yasir Khokhar

Starting from NiFi-1.7 version we can dynamically assign connection pooling service by using

DBCPConnectionPoolLookup controller service.

From documentation:

1.Provides a DBCPService that can be used to dynamically select another DBCPService. This service requires an attribute named 'database.name' to be passed in when asking for a connection, and will throw an exception if the attribute is missing.
2.The value of 'database.name' will be used to select the DBCPService that has been registered with that name.
3.This will allow multiple DBCPServices to be defined and registered, and then selected dynamically at runtime by tagging flow files with the appropriate 'database.name' attribute

If you are using NiFi version <1.7.0 then we need to have to define each DBCPConnection controller service for each connection of ExecuteSql processor.

Translate
azure
azureAuthor
Gold ⭐️
Jan 12, 2019 7:18 PM UTC

@shu

Many thanks for responding--however, with this solution I will need multiple ExecuteSQL processors each specifying the database.name attribute value, correct? I'll end up with dozens of ExecuteSQL processors that have the same SQL but different Database.name.

Is my understanding correct or am i missing a trick?

I guess, the question is, how/where do i set the database.name attribute? I've configured the service, but how is the execute SQL processor configured?

Translate
azure
azureAuthor
Gold ⭐️
Jan 21, 2019 6:41 PM UTC

The solution worked! I had some strange error my side that disappeared after a clean setup of the flow. Thanks @Shu!

Translate
Siddhanta
Silver ⭐️
Aug 2, 2019 5:33 AM UTC

@Yasir Khokhar

Can you please upload the template xml. I have similar requirement and it will help me start with.

Translate