Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. RSS Component

...


*Available as of Camel 2.0

...

*

The *rss:* component is used for polling RSS feeds. Camel will default poll the feed every 60th seconds.

...



Maven users will need to add the following dependency to their {{pom.xml}} for this component:

...


{code
:xml
xml
}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-rss</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

{code}

*Note:* The component currently only supports polling (consuming) feeds.

...



{note
Code Block
:title
=Using camel-rss in OSGi environment
}
Camel-rss uses [ROME|https://rome.dev.java.net/] 1.0 and below. This library has class loading issues in OSGi environment. We submitted issue [142|https://rome.dev.java.net/issues/show_bug.cgi?id=142] to ROME.


You can also find patched version in [this repository|http://repository.code-house.org/content/repositories/code-house.public.release/rome/rome/1.0-osgi/]. One thing you have to change is version - patched version is marked as 1.0-osgi.

URI format


{note}

h3. URI format

{code}
rss:rssUri
{code}

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, Camel splits a feed into its individual entries and returns each entry, poll by poll. For example, if a feed contains seven entries, 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, Camel contacts the remote RSS URI to obtain a new feed. If false, 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, 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

...

}}

h3. Options
{div:class=confluenceTableSmall}
|| Property || Default || Description ||
| {{splitEntries}} | {{true}} | If {{true}}, Camel splits a feed into its individual entries and returns each entry, poll by poll. For example, if a feed contains seven entries, 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, Camel contacts the remote RSS URI to obtain a new feed. If {{false}}, 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, 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

Camel initializes the In body on the Exchange with a ROME SyndFeed. Depending on the value of the splitEntries flag, 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

}}. | 
| {{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|http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html] in JDK for details. |
{div}

h3. Exchange data types

Camel initializes the In body on the Exchange with a ROME {{SyndFeed}}. Depending on the value of the {{splitEntries}} flag, Camel returns either a {{SyndFeed}} with one {{SyndEntry}} or a {{java.util.List}} of {{SyndEntrys}}.
{div:class=confluenceTableSmall}
|| 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. |
{div}

h3. Message Headers
{div:class=confluenceTableSmall}
|| Header || Description ||
| {{org.apache.camel.component.rss.feed

...

}} | Camel 1.x: The entire {{SyncFeed}} object.

...

CamelRssFeed

...

 |
| {{CamelRssFeed}} | 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:

Wiki Markup
. |
{div}

h3. 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:

{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssDataFormatTest.java}

The purpose of this feature is to make it possible to use Camel's lovely built-in expressions for manipulating RSS messages. As shown below, an XPath expression can be used to filter the RSS message:

...

Wiki Markup


{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java}

h3. Filtering entries

...



You can filter out entries quite easily using XPath, as shown in the data format section above. You can also exploit Camel's [Bean Integration] to implement your own conditions. For instance, a filter equivalent to the XPath example above would be:

...

Wiki Markup


{snippet:id=ex1|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssFilterTest.java}

The custom bean for this would be:

...

Wiki Markup


{snippet:id=ex2|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssFilterTest.java}

{include

...

:Endpoint See

...

 Also}
- [Atom]