http://www.mulesoft.org/schema/mule/atom
Atom Module Reference
The name Atom applies to a pair of related standards. The Atom Syndication Format is an XML language used for web feeds, while the Atom Publishing Protocol (AtomPup or APP) is a simple HTTP-based protocol for creating and updating web resources. Mule contains support for both.
Namespace and Syntax
XML namespace:
XML Schema location:
http://www.mulesoft.org/schema/mule/atom http://www.mulesoft.org/schema/mule/atom/3.4/mule-atom.xsd
Features
The Mule Atom Module includes an implementation of Apache Abdera, making it possible to integrate easily with Atom feeds and Atom Publishing Protocol servers from within a Mule configuration.
The module supports the following capabilities:
-
Consuming Atom feeds
-
Publishing Atom entries
-
Server side AtomPub support as a Mule application
Example Configurations
Consuming Feeds and Other Atom Resources
One of the most common patterns is for integrating with Atom is polling for feed updates. With Mule this can be done quite easily. You must first white your class which receives an Atom Entry:
EntryReceiver.java |
---|
|
Use an atom feed splitter to split an incoming feed into individual messages so the component method will be invoked for each entry in the feed. The flow configuration would look like so:
<flow name="eventConsumer">
<poll frequency="10000">
<http:outbound-endpoint address="http://localhost:9002/events"/>
</poll>
<atom:feed-splitter/>
<atom:entry-last-updated-filter/>
<component class="org.mule.module.atom.event.EntryReceiver"/>
</flow>
The atom:entry-last-updated-filter
is optional. It should only be used to filter older entries from the feed. Note that the atom:entry-last-updated-filter
should come after the atom:feed-splitter/
since you need to split the feed into entries so that the filter can process them. Also note that we do not set a lastUpdate
date on the filter. This implies the default behavior that all available entries will be read before the processing of any entries that are new as of the last read.
Accessing the Feed Itself
If you need access to the feed itself, parse it using the object-to-feed transformer:
<flow name="eventConsumer">
<poll frequency="10000">
<http:outbound-endpoint address="http://localhost:9002/events"/>
</poll>
<atom:object-to-feed-transformer/>
<component class="org.mule.module.atom.event.FeedReceiver"/>
</flow>
Now your component will only be invoked once for each feed change no matter how many entries were added or updated. The method on your component should expect a org.apache.abdera.model.Feed
object.
FeedReceiver.java |
---|
|
If you want access to the feed object while using the feed splitter, it is available via a header on the current message called \'feed.object'.
Accessing Feeds over Other Protocols
You can receive 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. For instance, an atom document is sent over JMS or polled from a file. The atom schema defines a atom:feed-splitter/
message processor that can split messages received from an endpoint, like so:
Consuming an Atom feed over JMS |
---|
|
Consuming an Atom feed from a file |
---|
|
Implementing an AtomPub Server
Abdera’s server side component centers on the notion of a Provider. A Provider manages a service’s Workspaces and Collections.
You can create an AtomPub service in Mule by using atom:component/
XML element and reference an Abdera service context.
Creating the Abdera Service Context
The following example shows how to create an Abdera context that builds a JCR repository to store atom entries. These entries can then be served as a feed.
abdera-config.xml |
---|
|
The <a:provider>
creates an Abdera DefaultProvider and allows you to add workspaces and collections to it. This provider
reference is used by the atom:component
in Mule to store any events sent to the component.
<flow name="atomPubEventStore">
<http:inbound-endpoint address="http://localhost:9002"/>
<atom:component provider-ref="provider"/>
</flow>
Publishing to the Atom Component
You may also want to publish Atom entries or media entries to the atom:component/
or to an external AtomPub collection. Here is a simple outbound endpoint which creates an Abdera Entry via the entry-builder-transformer
and POSTs it to the AtomPub collection:
<outbound-endpoint address="http://localhost:9002/events" mimeType="application/atom+xml;type=entry" connector-ref="HttpConnector">
<atom:entry-builder-transformer>
<atom:entry-property name="author" evaluator="string" expression="Ross Mason"/>
<atom:entry-property name="content" evaluator="payload" expression=""/>
<atom:entry-property name="title" evaluator="header" expression="title"/>
<atom:entry-property name="updated" evaluator="function" expression="now"/>
<atom:entry-property name="id" evaluator="function" expression="uuid"/>
</atom:entry-builder-transformer>
</outbound-endpoint>
You could also create the Entry manually for more flexibility and send it as your Mule message payload. Here’s a simple example of how to create an Abdera Entry:
Create an Abdera Entry |
---|
|
You can also post Media entries quite simply. In this case it will take whatever your message payload is and post it to the collection as a media entry. You can supply your own Slug via configuration or by setting a property on the mule message.
Post Message Payload as Media Entry |
---|
|
Route Filtering
The atom module also includes an atom:route-filter
. This allows ATOM requests to be filtered by request path and HTTP verb. The route attribute defines a type of URI Template loosely based on Ruby on Rails style Routes. For example:
"feed" or ":feed/:entry"
For reference, see the Ruby On Rails routing.
For example, this filter can be used for content-based routing in Mule:
Route Filtering |
---|
|
Configuration Reference
Component
Represents an Abdera component.
Name | Type | Required | Default | Description |
---|---|---|---|---|
provider-ref |
string |
no |
The ID of the Atom provider that is defined as Spring bean. |
No Child Elements of <component…>
Feed Splitter
Splits the entries of a feed into single entry objects. Each entry is a separate message in Mule.
No Child Elements of <feed-splitter…>
Filters
Entry Last Updated Filter
Will filter ATOM entry objects based on their last update date. This is useful for filtering older entries from the feed. This filter works only on Atom Entry objects not Feed objects.
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 2016-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. |
No Child Elements of <entry-last-updated-filter…>
Feed Last Updated Filter
Will filter the whole ATOM Feed based on its last update date. This is useful for processing a feed that has not been updated since a specific date.
This filter works only on Atom Feed objects.
Typically, it is better to set the lastUpdated attribute on an inbound ATOM endpoint with splitFeed=false rather than use this file, however, this filter can be used elsewhere in a flow.
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. |
No Child Elements of <feed-last-updated-filter…>
Route Filter
Allows ATOM requests to be filtered by request path and HTTP verb.
Name | Type | Required | Default | Description |
---|---|---|---|---|
route |
string |
no |
The URI request path made for an ATOM request. This matches against the path of the request URL. The route attribute defines a type of URI Template loosely based on Ruby on Rails style Routes. For example: "feed" or "feed:/entry". For reference, see the Ruby On Rails routing |
|
verbs |
string |
no |
A comma-seperated list of HTTP verbs that will be accepted by this filter. By default all verbs are accepted. |
No Child Elements of <route-filter…>
Transformer
Entry Builder Transformer
A transformer that uses expressions to configure an Atom Entry. The user can specify one or more expressions that are used to configure properties on the bean.
No Attributes of <entry-builder-transfomer…>
Name | Cardinality | Description |
---|---|---|
entry-property |
0..1 |
Schema
Namespace: http://www.mulesoft.org/schema/mule/atom
Targeting Schemas (1):
Targeting Components:
7 global elements, 1 local element, 5 complexTypes, 1 attribute group
Schema Summary | |
---|---|
The Mule ATOM support makes it possible to integrate easily with Atom feeds and Atom Publishing Protocol servers via the Apache Abdera projec. Target Namespace: Defined Components: 7 global elements, 1 local element, 5 complexTypes, 1 attribute group Default Namespace-Qualified Form: Local Elements: qualified; Local Attributes: unqualified Schema Location: Imports Schemas (4): mule-schemadoc.xsd, mule.xsd, spring-beans-3.1.xsd, xml.xsd Imported by Schema: _mule-all-included.xsd |
|
All Element Summary |
|
Represents an Abdera component. Type: atomComponentType Content: complex, 2 attributes, attr. wildcard, 8 elements Subst.Gr:may substitute for elements: mule:abstract-component, mule:abstract-message-processor Defined: globally in mule-atom.xsd; see XML source Used: never |
|
A transformer that uses expressions to configure an Atom Entry. Content: complex, 5 attributes, attr. wildcard, 2 elements Subst.Gr: may substitute for elements: mule:abstract-transformer, mule:abstract-message-processor Defined: globally in mule-atom.xsd; see XML source Used: never |
|
entry-last-updated-filter |
Filters the whole ATOM Feed based on its last update date. Type: feedLastUpdateFilterType Content: complex, 3 attributes, attr. wildcard, 1 element Subst.Gr: may substitute for elements: mule:abstract-filter, mule:abstract-message-processor Defined: globally in mule-atom.xsd Used: never |
feed-splitter |
Splits the entries of a feed into single entry objects. Type: mule:baseSplitterType Content: complex, 1 attribute, attr. wildcard, 2 elements Subst.Gr: may substitute for elements: mule:abstract-intercepting-message-processor, mule:abstract-message-processor Defined: globally in mule-atom.xsd Used: never |
object-to-feed-transformer |
Transforms the payload of the message to a Type: mule:abstractTransformerType Content: complex, 5 attributes, attr. wildcard, 1 element Subst.Gr: may substitute for elements: mule:abstract-transformer, mule:abstract-message-processor Defined: globally in mule-atom.xsd Used: never |
route-filter |
Allows ATOM requests to be filtered by request path and HTTP verb. Type: routeFilterType Content: complex, 3 attributes, attr. wildcard, 1 element Subst.Gr:may substitute for elements: mule:abstract-filter, mule:abstract-message-processor Defined: globally in mule-atom.xsd; see XML source Used: never |
Complex Type Summary |
|
atomComponentType |
Content: complex, 2 attributes, attr. wildcard, 8 elements Defined: globally in mule-atom.xsd Used: at 1 location |
entryBuilderTransformerType |
Content: complex, 5 attributes, attr. wildcard, 2 elements Defined: globally in mule-atom.xsd Includes: definition of 1 element Used: at 1 location |
entryLastUpdateFilterType |
Content: complex, 3 attributes, attr. wildcard, 1 element Defined: globally in mule-atom.xsd Includes: definitions of 2 attributes Used: at 1 location |
feedLastUpdateFilterType |
Content: complex, 3 [attributes], attr. wildcard, 1 element Defined: globally in mule-atom.xsd Includes: definitions of 2 attributes Used: at 1 location |
routeFilterType |
Content: complex, 3 attributes, attr. wildcard, 1 element Defined: globally in mule-atom.xsd Includes: definitions of 2 attributes Used: at 1 location |
Attributes Group Summary |
|
componentAttributes |
Content: 1 attribute Defined: globally in mule-atom.xsd; see XML source Includes: definition of 1 attribute Used: at 1 location |
Maven
The ATOM Module ca be included with the following dependency:
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-atom</artifactId>
<version>3.4.1</version>
</dependency>
Points of Etiquette When Polling Atom Feeds
-
Make use of HTTP cache. Send Etag and LastModified headers. Recognize 304 Not modified response. This way you can save a lot of bandwidth. Additionally some scripts recognize the LastModified header and return only partial contents (ie. only the two or three newest items instead of all 30 or so).
-
Don’t poll RSS from services that supports RPC Ping (or other PUSH service, such as PubSubHubBub). That is, if you’re receiving PUSH notifications from a service, you don’t have to poll the data in the standard interval — do it once a day to check if the mechanism still works or not (ping can be disabled, reconfigured, damaged, etc). This way you can fetch RSS only on receiving notification, not every hour or so.
-
Check the TTL (in RSS) or cache control headers (Expires in ATOM), and don’t fetch until resource expires.
-
Try to adapt to frequency of new items in each single RSS feed. If in the past week there were only two updates in particular feed, don’t fetch it more than once a day. AFAIR Google Reader does that.
-
Lower the rate at night hours or other time when the traffic on your site is low.