package org.mule.module.rss;
import com.sun.syndication.feed.synd.SyndEntry;
public class EntryReceiver
{
public void readEntry(@Payload SyndEntry entry) throws Exception
{
//do stuff
}
}
RSS Module Reference
The Mule RSS support makes it possible to integrate easily with RSS feeds.
Consuming Feeds
The use of RSS endpoints is deprecated. RSS endpoints were removed in Mule 3.2.0. Use the approach described in the Mixing HTTP and RSS Endpoints section. |
One of the most common patterns is for integrating with RSS is polling for feed updates. With Mule this can be done easily. You must first write your class which receives an RSS Syndication Entry:
EntryReceiver.java
By default the RSS feed is split into entries for you, so for each entry the component method is invoked with the next entry in the feed. The flow configuration would look like:
<flow name="eventConsumer">
<rss:inbound-endpoint address="http://localhost:9002/events"/>
<component class="org.mule.module.rss.EntryReceiver"/>
</flow>
ETags
The Atom HTTP endpoint respects ETags and the 304 Not Modified response code by default, so you don’t need to worry about consuming unnecessary updates.
Accessing the Feed Itself
If you want access to the feed itself, it is available via a header on the current message called 'feed.object'. You could have this injected into your entry point method using annotations -
EntryReceiver.java
public void processEntry(@Payload Entry entry, @Expr("#[header:invocation:feed.object]") Feed feed) throws Exception
The @Expr annotation is only available in the Mule Community Edition. |
Your component should expect a com.sun.syndication.feed.synd.SyndFeed
object or just a org.w3c.dom.Document
if you want to process the XML model or even an java.io.InputStream
or java.lang.String
to get a raw representation.
FeedReceiver.java
public void processFeed(@Payload SyndFeed feed) throws Exception
{
//do stuff
}
Mixing HTTP and RSS Endpoints
The rss:endpoint
elements are a shortcut for creating a polling http endpoint and splitting a feed. If you are using another non-polling HTTP endpoint in your configuration you will need to configure a HTTP polling endpoint as well and reference it on your atom endpoint.
<http:connector name="HttpConnector"/>
<http:polling-connector name="PollingHttpConnector" pollingFrequency="1000" discardEmptyContent="false"/>
<flow name="eventConsumer">
<http:inbound-endpoint address="http://localhost:9002/events" connector-ref="PollingHttpConnector"/>
<component class="org.mule.module.rss.EntryReceiver"/>
</flow>
Accessing Feeds Over Other Protocols
You can process feeds and process them using other Mule connectors such as JMS, File or XMPP. To do this the ATOM feed needs to be served over the connector, such as when an RSS document is sent over JMS or polled from a file. The RSS schema defines a <rss:feed-splitter/>
that can split messages received from an endpoint.
Over JMS
<flow name="feedSplitterConsumer">
<jms:inbound-endpoint queue="feed.in">
<rss:feed-splitter/>
</jms:inbound-endpoint>
<component class="org.mule.module.atom.event.EntryReceiver"/>
</flow>
Over a File
<flow name="feedSplitterConsumer">
<file:inbound-endpoint path="${mule.working.dir}" pollingFrequency="1000" >
<file:filename-wildcard-filter pattern="*.rss"/>
<rss:feed-splitter/>
</file:inbound-endpoint>
<component class="org.mule.module.atom.event.EntryReceiver"/>
</flow>
Processing Feeds Without an RSS Endpoint
For reference, the follow example shows the explicit configuration for reading an ATOM feed without using the rss:endpoint
.
<http:polling-connector name="PollingHttpConnector" pollingFrequency="1000" discardEmptyContent="false"/>
<flow name="feedConsumer">
<http:inbound-endpoint address="http://rossmason.blogspot.com/feeds/posts/default" connector-ref="PollingHttpConnector">
<rss:feed-splitter/>
<rss:entry-last-updated-filter/>
</http:inbound-endpoint>
<component class="org.mule.module.rss.EntryReceiver"/>
</flow>
Note: The rss:entry-last-updated-filter
should come after the <rss:feed-splitter/>
since you need to split the feeds so that the filter can process them. Also note that we do not set a lastUpdate
date on the filter which implies the default behavior that all available entries is read and then only new entries since the last read is processed.
Feed Splitter
Splits the entries of a feed into single entry objects. Each entry will be a separate message in Mule.
No Child Elements of <feed-splitter…>
Entry Last Updated Filter
Will filter RSS entry objects based on their last update date. This is useful for filtering older entries from the feed. This filter works only on RSS SyndEntry objects not SyndFeed objects.
Attributes of <entry-last-updated-filter…>
Name | Type | Required | Default | Description |
---|---|---|---|---|
lastUpdate |
string |
no |
The date from which to filter events from. Any entries that were last updated before this date will not be accepted. The date format is: yyyy-MM-dd hh:mm:ss, for example 2008-12-25 13:00:00. If only the date is important you can omit the time part. You can set the value to 'now' to set the date and time that the server is started. Do not set this attribute if you want to receive all available entries then any new entries going forward. This is the default behavior and suitable for many scenarios. |
|
acceptWithoutUpdateDate |
boolean |
no |
true |
Whether an entry should be accepted if it doesn’t have a Last Update date set. |