Created 02-18-2022 09:16 AM
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?
Created 02-20-2022 03:21 AM
Hi, @Nandy113 ,
One way to achieve this is to use the Wait/Notify pattern in NiFi, as shown below:
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:
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:
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:
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:
HTH,
André
Created 02-20-2022 03:21 AM
Hi, @Nandy113 ,
One way to achieve this is to use the Wait/Notify pattern in NiFi, as shown below:
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:
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:
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:
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:
HTH,
André
Created 02-23-2022 01:11 PM
@Nandy113 , does that answer your question?
Created 02-24-2022 09:04 AM
Hi @araujo. The solution looks feasible and as per my requirement. Thank you for the update.
Created 03-31-2022 07:20 PM
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.