Chapter 121. RSS


RSS Component

The rss: component is used for polling RSS feeds. Apache Camel will default poll the feed every 60th seconds.
Note: The component currently only supports polling (consuming) feeds.
Note
Camel-rss internally uses a patched version of ROME hosted on ServiceMix to solve some OSGi class loading issues.

URI format

rss:rssUri
Where rssUri is the URI to the RSS feed to poll.
You can append query options to the URI in the following format, ?option=value&option=value&...

Options

Property Default Description
splitEntries true If true, Apache Camel splits a feed into its individual entries and returns each entry, poll by poll. For example, if a feed contains seven entries, Apache Camel returns the first entry on the first poll, the second entry on the second poll, and so on. When no more entries are left in the feed, Apache Camel contacts the remote RSS URI to obtain a new feed. If false, Apache Camel obtains a fresh feed on every poll and returns all of the feed's entries.
filter true Use in combination with the splitEntries option in order to filter returned entries. By default, Apache Camel applies the UpdateDateFilter filter, which returns only new entries from the feed, ensuring that the consumer endpoint never receives an entry more than once. The filter orders the entries chronologically, with the newest returned last.
throttleEntries true Camel 2.5: Sets whether all entries identified in a single feed poll should be delivered immediately. If true, only one entry is processed per consumer.delay. Only applicable when splitEntries is set to true.
lastUpdate null Use in combination with the filter option to block entries earlier than a specific date/time (uses the entry.updated timestamp). The format is: yyyy-MM-ddTHH:MM:ss. Example: 2007-12-24T17:45:59.
feedHeader true Specifies whether to add the ROME SyndFeed object as a header.
sortEntries false If splitEntries is true, this specifies whether to sort the entries by updated date.
consumer.delay 60000 Delay in milliseconds between each poll.
consumer.initialDelay 1000 Milliseconds before polling starts.
consumer.userFixedDelay false Set to true to use fixed delay between pools, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.

Exchange data types

Apache Camel initializes the In body on the Exchange with a ROME SyndFeed. Depending on the value of the splitEntries flag, Apache Camel returns either a SyndFeed with one SyndEntry or a java.util.List of SyndEntrys.
Option Value Behavior
splitEntries true A single entry from the current feed is set in the exchange.
splitEntries false The entire list of entries from the current feed is set in the exchange.

Message Headers

Header Description
CamelRssFeed Apache Camel 2.0: The entire SyncFeed object.

RSS Dataformat

The RSS component ships with an RSS dataformat that can be used to convert between String (as XML) and ROME RSS model objects.
  • marshal = from ROME SyndFeed to XML String
  • unmarshal = from XML String to ROME SyndFeed
A route using this would look something like this:
from("rss:file:src/test/data/rss20.xml?splitEntries=false&consumer.delay=1000").marshal().rss().to("mock:marshal");
The purpose of this feature is to make it possible to use Apache Camel's lovely built-in expressions for manipulating RSS messages. As shown below, an XPath expression can be used to filter the RSS message:
// only entries with Apache Camel in the title will get through the filter
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100")
    .marshal().rss().filter().xpath("//item/title[contains(.,'Camel')]").to("mock:result");
Query parameters
If the URL for the RSS feed uses query parameters, this component will understand them as well, for example if the feed uses alt=rss, then you can for example do from("rss:http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&consumer.delay=1000").to("bean:rss");

Filtering entries

You can filter out entries quite easily using XPath, as shown in the data format section above. You can also exploit Apache Camel's Bean Integration to implement your own conditions. For instance, a filter equivalent to the XPath example above would be:
// only entries with Camel in the title will get through the filter
from("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100").
    filter().method("myFilterBean", "titleContainsCamel").to("mock:result");
The custom bean for this would be:
public static class FilterBean {
    public boolean titleContainsCamel(@Body SyndFeed feed) {
        SyndEntry firstEntry = (SyndEntry) feed.getEntries().get(0);
        return firstEntry.getTitle().contains("Camel");
    }
}

See also

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.