Wednesday, December 10, 2008

RSS support in Camel

We've had Atom connectivity in Camel for a while now and so to not leave any RSS users out in the cold, I put in RSS support as well. We try to integrate with pretty much every messaging system in Camel after-all :)

Under the hood I'm using the ROME project. Its pretty much the standard Java framework for dealing with RSS feeds.

To consume from an RSS feed, just start your route like

from("rss:http://feeds.feedburner.com/JonAnsteysBlog")...

Then you can do all sorts of neat stuff like,

Filtering entries

Only entries with Camel in the title will get through this filter.

from("rss:feedUri?splitEntries=true").
filter().method("myFilterBean", "titleContainsCamel").
to("mock:result");

Merging multiple incoming feeds

Sometimes you may need to merge feeds from several different sources.

from("rss:feedUri").to("seda:temp");
from("rss:someOtherFeedUri").to("seda:temp");

from("seda:temp").aggregate(new AggregateRssFeedCollection()).
to("mock:result");

Marshal between XML and ROME objects

Here we perform the same filtering as above but instead marshal to XML and use XPath.

from("rss:feedUri?splitEntries=true").
marshal().rss().
filter().xpath("//item/title[contains(.,'Camel')]").
to("mock:result");

For more info, check out the wiki documentation.