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 Fri, 07 Sep 2012 20:58:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/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/~muellerc">Christian
Mueller</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Header || Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">{{org.apache.camel.component.rss.feed}}</span>
<span class="diff-added-words"style="background-color: #dfd;">{{CamelRssFeed}}</span>
| <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">Camel
1.x:</span> The entire {{SyncFeed}} object. | <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
{{CamelRssFeed}} | Camel 2.0: The entire {{SyncFeed}} object. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <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>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>Camel-rss internally uses a <a
href="http://svn.apache.org/repos/asf/servicemix/smx4/bundles/trunk/rome-1.0/" class="external-link"
rel="nofollow">patched version</a> of <a href="http://rometools.org/" class="external-link"
rel="nofollow">ROME</a> hosted on ServiceMix to solve some OSGi <a href="https://issues.apache.org/jira/browse/SMX4-510"
class="external-link" rel="nofollow">class loading issues</a>.</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="confluenceTableSmall"><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>
</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="confluenceTableSmall"><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>
</div>

<h3><a name="RSS-MessageHeaders"></a>Message Headers</h3>
<div class="confluenceTableSmall"><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>CamelRssFeed</tt> </td>
<td class='confluenceTd'> The entire <tt>SyncFeed</tt> object. </td>
</tr>
</tbody></table>
</div>
</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>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Query parameters</b><br
/>If the URL for the RSS feed uses query parameters, this component will understand them
as well, for example if the feed uses <tt>alt=rss</tt>, then you can for example
do<br/>
<tt>from("rss:<a href="http://someserver.com/feeds/posts/default?alt=rss&amp;splitEntries=false&amp;consumer.delay=1000"
class="external-link" rel="nofollow">http://someserver.com/feeds/posts/default?alt=rss&amp;splitEntries=false&amp;consumer.delay=1000</a>").to("bean:rss");</tt></td></tr></table></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>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Atom" title="Atom">Atom</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=25&originalVersion=24">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