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, 27 Sep 2010 15:21:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/RSS">RSS</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (5)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-unchanged" >h2. RSS Component <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*Available
as of Camel 2.0* <br></td></tr>
            <tr><td class="diff-unchanged" > <br>The *rss:* component is
used for polling RSS feeds. Camel will default poll the feed every 60th seconds. <br>
<br>Maven users will need to add the following dependency to their {{pom.xml}} for this
component: <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code<span
class="diff-added-chars"style="background-color: #dfd;">:xml</span>}</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;dependency&gt; <br>
   &lt;groupId&gt;org.apache.camel&lt;/groupId&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{note} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*New
in Camel 2.0* <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. URI format <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{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&#39;s entries. | <br>| {{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. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{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. | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{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}}.
|  <br>| {{feedHeader}} | {{true}} | Specifies whether to add the ROME {{SyndFeed}}
object as a header. | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/dataformat/rss/RssFilterWithXPathTest.java}
<br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3.
Merging multiple incoming feeds <br> <br>To merge multiple incoming feeds into
a single feed, you can apply the custom aggregator, {{AggregationCollection}}, provided with
camel-rss. For example: <br>{snippet:id=ex|lang=java|url=camel/trunk/components/camel-rss/src/test/java/org/apache/camel/component/rss/RssCustomAggregatorTest.java}
<br> <br>Here we use a [Seda] 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 {{SyndFeed}} object. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Filtering entries <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="RSS-RSSComponent"></a>RSS Component</h2>
<p><b>Available as of Camel 2.0</b></p>

<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-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-rss<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</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 />Camel-rss uses <a href="https://rome.dev.java.net/" class="external-link"
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"
class="external-link" 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/"
class="external-link" rel="nofollow">this repository</a>. One thing you have to change
is version - patched version is marked as 1.0-osgi.</td></tr></table></div>

<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>

<div class='table-wrap'>
<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>throttleEntries</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> 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. </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"
class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details.
</td>
</tr>
</tbody></table>
</div>


<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>

<div class='table-wrap'>
<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>
</div>


<h3><a name="RSS-MessageHeaders"></a>Message Headers</h3>
<div class='table-wrap'>
<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>
</div>


<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-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="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/RSS">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=103882&revisedVersion=17&originalVersion=16">View
Changes</a>
                |
        <a href="https://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