- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
NiFi: Rolling Window Restful API Polling
- Labels:
-
Apache NiFi
Created ‎11-24-2017 08:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Have been recently investing a lot of time in learning and using NiFi for a multitude of cases. On in particular we have a hard time understand how to accomplish is pulling events from a remote restful API endpoint with a rolling time window.
We have successfully used invokehttp processor to pull the desired events using a specific query that includes a time parameter (in this case its an epoch timestamp). While this is great the timestamp is static and the goal would be to update the timestamp with the time in which the last successful invokhttp request occurred.
Does anyone know how this would be accomplished within NiFi?
Thanks
~Regards
Created on ‎11-25-2017 01:15 PM - edited ‎08-17-2019 09:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should be able to do this using an UpdateAttribute with the state feature. You can add an UpdateAttribute to the flow:
And configure it as follows:
This way, each flow file going to InvokeHttp will have two attributes:
- Timestamp : the current time
- previousTimestamp : the time of the previous execution. You can use this in your InvokeHttp.
Here's an example of attributes that InvokeHttp will have access to (in my case I execute this every minute as you can see)
Is this what you are looking for?
Created on ‎11-25-2017 01:15 PM - edited ‎08-17-2019 09:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should be able to do this using an UpdateAttribute with the state feature. You can add an UpdateAttribute to the flow:
And configure it as follows:
This way, each flow file going to InvokeHttp will have two attributes:
- Timestamp : the current time
- previousTimestamp : the time of the previous execution. You can use this in your InvokeHttp.
Here's an example of attributes that InvokeHttp will have access to (in my case I execute this every minute as you can see)
Is this what you are looking for?
Created ‎11-28-2017 03:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the most part yes, especially since i didn't know how state functioned in XYZ processors. However in this setup the timestamp is always updated regardless of the success or failure of the invokehttp processor. In a failure scenario the poll would potential miss a period of time (and thus any events/data within) so the timestamp can only be updated under a success condition of a request.
At the moment the only thing i can think of is using the distributed cache feature, but that seems like overkill ...
Created ‎11-28-2017 04:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's another feature in the UpdateProcessor that you can use which Rules : https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-update-attribute-nar/1.4.0/or...
This feature is available in the advanced settings and you can use to define conditions and actions. So you can say if condition than update timestamps, else do not.
Look at my answer to this question to see how you can use it : https://community.hortonworks.com/questions/140060/nifi-how-to-load-a-value-in-memory-one-time-from-...
