ATOM Channel
ATOM Publishing protocol is a very common method of delivering data over HTTP on the Web, most blogs and news sites use ATOM to deliver their contents.
Since ATOM is delivered over HTTP, using the ATOM channel is very similar to using the HTTP channel, except the channel uri is prefixed with 'atom:'. Lets say you want to receive blog post entries from my blog when ever I add a new one (tip: you might be waiting a while
).
@Schedule(interval = 6000) @Receive(uri = "atom:http://rossmason.blogspot.com/feeds/posts/default") public void readFeed(Entry entry) throws Exception { //read the entry }
The @Schedule annotation tells iBeans to check the atom feed every minute. When there are entries available the readFeed method will be invoked. The Entry is a Java Object that wraps the ATOM XML making it easier to work with. For every new entry available on my blog feed, the readFeed method will get invoked. Behind the scenes iBeans splits the feed into entries for you and remembers what entries have already been received so that they are not processed again.
Channel Properties
The ATOM channel support the following properties.
| Property | Description |
|---|---|
| ATOM.LAST_UPDATE_DATE | Can be set on a channel to filter out any feed entries before the given date/time. This is only used if the feed is split. The format for the date is: yyyy-MM-dd HH:MM:ss, for example 2008-12-25 13:00:00. If only the date is important you can omit the time part. See the example below |
| ATOM.DONT_SPLIT_FEED | Whether to split the incoming feed into entries. By default this is true and for most use cases, splitting is what you want. Note that the Feed object itself is available as a header called ATOM.FEED_HEADER |
Examples
LAST_UPDATE_DATE Example
To consume feed enties that were create after August 1st 2009, you would configure the uri with a LAST_UPDATE_DATE property -
@Schedule(interval = 6000) @Receive(uri = "atom:http://rossmason.blogspot.com/feeds/posts/default", properties = ATOM.LAST_UPDATE_DATE + "=2009-08-01") public void readFeed(Entry entry) throws Exception ...
DON'T_SPLIT_FEED Example
Using the DON'T_SPLIT_FEED flag will just pass the Feed object to your method -
@Schedule(interval = 6000) @Receive(uri = "atom:http://rossmason.blogspot.com/feeds/posts/default", properties = ATOM.DONT_SPLIT_FEED) public void readFeed(Feed feed) throws Exception ...
Getting the Entry and the Feed
Usually it is desirable to have the Feed split into entries, but you may also want access to the Feed object it came from. The feed object is available as a Header that can be passed into your method -
@Schedule(interval = 6000) @Receive(uri = "atom:http://rossmason.blogspot.com/feeds/posts/default") public void readFeed(Entry entry, @ReceivedHeaders(ATOM.FEED_HEADER) Feed feed) throws Exception ...
Add Comment