The RSS Catalog Reader application is based on the RSS Feed example, extending it to simultaneously monitor a large catalog of individual RSS feeds. The application uses a JSON configuration file (see rss_catalog.json) to specify the RSS feeds of interest, monitors them and produces 'rssFeed' events containing information about any new feed items found.

The design of the application is based on the producer-consumer pattern, which nicely divides the work between two state machines rssRequest and rssCatalog respectively (see rss_catalog.js). The producer (rssRequest) periodically makes HTTP requests and emits 'data' events containing the downloaded XML feed data. When the consumer (rssCatalog) receives a 'data' event it parses the XML, looking for new feed items. If any are found it emits a 'rssFeed' event containing details of the new feed items.

Information about feed locations is shared between the two machines by both having access to the catalog array. Each element of the array contains an object with the feed URL and a date when the feed was last published. When rssRequest starts it is passed catalog along with an integer number of milliseconds indicating how often to check for feed updates. The Request state uses the each plug-in to iterate over catalog, making HTTP requests to the URL given in each element. The machine then loops back on itself via Regulate, where waits for the specified number of milliseconds (refresh) using the timeout plug-in.

rssCatalog starts in the state LoadCatalog, responsible for loading the JSON configuration file. It then moves to StartSource which starts rssRequest and registers the machine as an event emitter called 'dataSource'. From here it loops over the three remaining states, ManageQueue -> ParseXml -> Broadcast, until being stopped by an API stop method call. During the loop cycles, when events are received from 'dataSource' they are added to a queue (queue) maintained by the machine.

In ManageQueue entries from the queue are removed causing the machine to initiate another loop cycle. If the queue is empty, the machine remains in the ManageQueue state until additional events are received.

Example Output

$ ./bin/ignite examples/apps/reader/rss_catalog.js
00:36:14 London riots hit sports fixtures
21:01:43 Arsenal sign Oxlade-Chamberlain
21:53:03 Ill Lampard out of England squad
20:54:27 Wilkinson deserves place - Flood
18:01:03 Pro boxers 'could fight in 2016'
18:09:55 O'Driscoll ready for Irish return
11:09:30 Sneijder believes he is for sale
14:09:47 Tevez back training with Man City
20:13:28 Bopara aims to grab Test chance
_

See