Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NIFI HTTP

avatar
New Contributor

I have a flow-file1. I need to generate an authentication token in the next step using a different flow-file2 through InvokeHttp processor which gives the response in another flow-file3. Now, using this token in this flow-file3, in the next step, I need to send flow-file1 to another HTTP endpoint using InvokeHttp. I am not able to figure out this flow. How to keep the flow-file1 and also handle other flow files which are completely for different purpose than the flow-file1? 

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi, @Nandy113 ,

 

One way to achieve this is to use the Wait/Notify pattern in NiFi, as shown below:

araujo_1-1645355533337.png

 

 

The original flowfile is routed to a Wait processor, where it's going to wait until the authentication token is obtained. The same flowfile is also routed to a ReplaceText processor where its content is replaced with the body content to obtain the access token. The InvokeHTTP processor on the right then makes the call to authenticate and get the token. The response (token) is stored in a "token" attribute of the original flowfile due to the following setting:

 

araujo_2-1645355642025.png

 

Note that the output relationship of that process is "Original" rather than "Response".

That flowfile is then sent to a Notify processor, which will send a notification to the Wait processor to continue to process the flowfile that was waiting. Both the Wait and the Notify processors are configured with the following, so that the authentication for each flowfile notifies the corresponding one that's waiting:

 

araujo_3-1645355779368.png

The notify process also has the following setting, which will cause the token to be put in the distributed cache and copied to the flowfile that's waiting:

 

araujo_4-1645355855938.png

 

Once the flowfile is released from the wait, it will have the token attribute, and then we can use that token on the following InvokeHttp processor to authenticate with the server by setting the following header with a dynamic property:

 

araujo_6-1645356012692.png

 

HTH,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

View solution in original post

4 REPLIES 4

avatar
Super Guru

Hi, @Nandy113 ,

 

One way to achieve this is to use the Wait/Notify pattern in NiFi, as shown below:

araujo_1-1645355533337.png

 

 

The original flowfile is routed to a Wait processor, where it's going to wait until the authentication token is obtained. The same flowfile is also routed to a ReplaceText processor where its content is replaced with the body content to obtain the access token. The InvokeHTTP processor on the right then makes the call to authenticate and get the token. The response (token) is stored in a "token" attribute of the original flowfile due to the following setting:

 

araujo_2-1645355642025.png

 

Note that the output relationship of that process is "Original" rather than "Response".

That flowfile is then sent to a Notify processor, which will send a notification to the Wait processor to continue to process the flowfile that was waiting. Both the Wait and the Notify processors are configured with the following, so that the authentication for each flowfile notifies the corresponding one that's waiting:

 

araujo_3-1645355779368.png

The notify process also has the following setting, which will cause the token to be put in the distributed cache and copied to the flowfile that's waiting:

 

araujo_4-1645355855938.png

 

Once the flowfile is released from the wait, it will have the token attribute, and then we can use that token on the following InvokeHttp processor to authenticate with the server by setting the following header with a dynamic property:

 

araujo_6-1645356012692.png

 

HTH,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
Super Guru

@Nandy113 , does that answer your question?

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
New Contributor

Hi @araujo. The solution looks feasible and as per my requirement. Thank you for the update. 

avatar
New Contributor

You could also have 2 Flows under 1 group. First flow gets the token and caches it .. second retrieves cached token to use where needed.