camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > RSS
Date Mon, 29 Mar 2010 01:29:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/RSS">RSS</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="RSS-RSSComponent"></a>RSS Component</h2>

<p>The <b>rss:</b> component is used for polling RSS feeds. Camel will default
poll the feed every 60th seconds.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-rss&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<p><b>Note:</b> The component currently only supports polling (consuming)
feeds.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Using camel-rss in OSGi
environment</b><br /><p>Camel-rss uses <a href="https://rome.dev.java.net/"
rel="nofollow">ROME</a> 1.0 and below. This library has class loading issues in OSGi
environment. We submitted issue <a href="https://rome.dev.java.net/issues/show_bug.cgi?id=142"
rel="nofollow">142</a> to ROME.<br/>
You can also find patched version in <a href="http://repository.code-house.org/content/repositories/code-house.public.release/rome/rome/1.0-osgi/"
rel="nofollow">this repository</a>. One thing you have to change is version - patched
version is marked as 1.0-osgi.</p></td></tr></table></div>

<p><b>New in Camel 2.0</b></p>

<h3><a name="RSS-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
rss:rssUri
</pre>
</div></div>

<p>Where <tt>rssUri</tt> is the URI to the RSS feed to poll. </p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="RSS-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, 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 <tt>false</tt>, Camel obtains a fresh feed on every poll
and returns all of the feed's entries. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>filter</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  Use in combination with the <tt>splitEntries</tt>
option in order to filter returned entries. By default, Camel applies the <tt>UpdateDateFilter</tt>
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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>lastUpdate</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Use in combination with the <tt>filter</tt> option
to block entries earlier than a specific date/time (uses the <tt>entry.updated</tt>
timestamp). The format is: <tt>yyyy-MM-ddTHH:MM:ss</tt>. Example: <tt>2007-12-24T17:45:59</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>feedHeader</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Specifies whether to add the ROME <tt>SyndFeed</tt>
object as a header. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sortEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>splitEntries</tt> is <tt>true</tt>,
this specifies whether to sort the entries by updated date. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use fixed delay between
pools, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html"
rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
</tbody></table>

<h3><a name="RSS-Exchangedatatypes"></a>Exchange data types</h3>

<p>Camel initializes the In body on the Exchange with a ROME <tt>SyndFeed</tt>.
Depending on the value of the <tt>splitEntries</tt> flag, Camel returns either
a <tt>SyndFeed</tt> with one <tt>SyndEntry</tt> or a <tt>java.util.List</tt>
of <tt>SyndEntrys</tt>.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Value </th>
<th class='confluenceTh'> Behavior </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'>  A single entry from the current feed is set in the exchange.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>splitEntries</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> The entire list of entries from the current feed is set in
the exchange. </td>
</tr>
</tbody></table>

<h3><a name="RSS-MessageHeaders"></a>Message Headers</h3>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>org.apache.camel.component.rss.feed</tt> </td>
<td class='confluenceTd'> Camel 1.x: The entire <tt>SyncFeed</tt> object.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelRssFeed</tt> </td>
<td class='confluenceTd'> Camel 2.0: The entire <tt>SyncFeed</tt> object.
</td>
</tr>
</tbody></table>

<h3><a name="RSS-RSSDataformat"></a>RSS Dataformat</h3>

<p>The RSS component ships with an RSS dataformat that can be used to convert between
String (as XML) and ROME RSS model objects. </p>

<ul>
	<li>marshal = from ROME <tt>SyndFeed</tt> to XML <tt>String</tt></li>
	<li>unmarshal = from XML <tt>String</tt> to ROME <tt>SyndFeed</tt></li>
</ul>


<p>A route using this would look something like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span
class="code-keyword">false</span>&amp;consumer.delay=1000"</span>).marshal().rss().to(<span
class="code-quote">"mock:marshal"</span>);
</pre>
</div></div>

<p>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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// only entries with Camel in
the title will get through the filter
</span>from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span
class="code-keyword">true</span>&amp;consumer.delay=100"</span>)
    .marshal().rss().filter().xpath(<span class="code-quote">"<span class="code-comment">//item/title[contains(.,'Camel')]"</span>).to(<span
class="code-quote">"mock:result"</span>);</span>
</pre>
</div></div>

<h3><a name="RSS-Mergingmultipleincomingfeeds"></a>Merging multiple incoming
feeds</h3>

<p>To merge multiple incoming feeds into a single feed, you can apply the custom aggregator,
<tt>AggregationCollection</tt>, provided with camel-rss. For example:</p>
<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>

<p>Here we use a <a href="/confluence/display/CAMEL/SEDA" title="SEDA">SEDA</a>
queue to gather up entries from two RSS feeds. The entries are then fed into the custom aggregator
which combines these entries into a single ROME <tt>SyndFeed</tt> object.</p>

<h3><a name="RSS-Filteringentries"></a>Filtering entries</h3>

<p>You can filter out entries quite easily using XPath, as shown in the data format
section above. You can also exploit Camel's <a href="/confluence/display/CAMEL/Bean+Integration"
title="Bean Integration">Bean Integration</a> to implement your own conditions. For
instance, a filter equivalent to the XPath example above would be:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// only entries with Camel in
the title will get through the filter
</span>from(<span class="code-quote">"rss:file:src/test/data/rss20.xml?splitEntries=<span
class="code-keyword">true</span>&amp;consumer.delay=100"</span>).
    filter().method(<span class="code-quote">"myFilterBean"</span>, <span class="code-quote">"titleContainsCamel"</span>).to(<span
class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>The custom bean for this would be:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span
class="code-keyword">static</span> class FilterBean {
    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
titleContainsCamel(@Body SyndFeed feed) {
        SyndEntry firstEntry = (SyndEntry) feed.getEntries().get(0);
        <span class="code-keyword">return</span> firstEntry.getTitle().contains(<span
class="code-quote">"Camel"</span>);
    }
}
</pre>
</div></div>

<h3><a name="RSS-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/RSS">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=103882&revisedVersion=16&originalVersion=15">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/RSS?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message