Atom
Since Camel 1.2
Only consumer is supported
The Atom component is used for polling Atom feeds.
Camel will poll the feed every 60 seconds by default.
Note: The component currently only supports polling (consuming) feeds.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-atom</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Atom component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Atom endpoint is configured using URI syntax:
atom:feedUri
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The URI of the feed to poll. The Atom component reads an http or https URL with the feed reader, and any other URI as a Camel resource such as file: or classpath: (classpath when there is no prefix). The RSS component opens the URI as a java.net.URL (such as http, https or file), so it needs a scheme. Query parameters that are not options of this endpoint are kept in the feed URI. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Whether to sort the entries of the feed so the oldest comes first. With splitEntries=true the entries are then routed from the oldest to the newest updated date (the published date for an entry without an updated date). Without sorting, Atom routes them from the oldest to the newest published date (Atom with idempotent=true and the default idempotentStrategy always sorts), and RSS routes them from the last entry of the feed document to the first. With splitEntries=false, Atom sorts the List in the body from the oldest to the newest published date instead of the newest first, and RSS does not sort. | false | boolean | |
Whether to route each entry of the feed as its own message. The body is then the entry: an Item of RSS Reader (com.apptasticsoftware.rssreader.Item) for Atom, a copy of the ROME SyndFeed that holds only this entry for RSS. When false, each poll routes one message with the whole feed as body (the List of all the Items for Atom, the SyndFeed for RSS), and throttleEntries and the idempotent options of Atom do not apply. RSS has no idempotent check: each read of the feed routes all its entries, also those routed before. | true | boolean | |
Whether each poll routes at most one entry, when splitEntries=true. The next poll routes the next entry of the same read of the feed, and the feed is read again only after all its entries were routed; entries that the idempotent check of Atom skips do not count. When false, each poll reads the feed and routes all its entries (for Atom, those that pass the idempotent check). | true | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether to set the whole feed in a header of each message: the List of all the entries in the CamelAtomFeed header for Atom, the ROME SyndFeed in the CamelRssFeed header for RSS. | true | boolean | |
Whether to skip the entries that were routed already, when splitEntries=true. The idempotentStrategy option sets how such an entry is recognized; the default strategy compares the updated date (the published date when there is none) with that of the last routed entry, kept in memory. | true | boolean | |
The IdempotentRepository that stores the ids (the atom:id) of the routed entries, for idempotentStrategy=repository. Without it, an in-memory repository of 1000 ids is used. The default strategy does not use it. | IdempotentRepository | ||
How an entry that was routed already is recognized, when idempotent=true. default skips an entry whose updated date (the published date when it has none) is older than that of the last routed entry, or is the same and the entry with this id (the atom:id, else its link) was routed already; an entry without a date is always routed. repository skips an entry whose id (the atom:id) is in the idempotentRepository; an entry without an id is always routed. A custom org.apache.camel.component.atom.AtomIdempotentStrategy can be referred to with the # notation. Enum values:
| default | AtomIdempotentStrategy | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean |
Message Headers
The Atom component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The List of all the entries (com.apptasticsoftware.rssreader.Item) of the polled feed. Not set when feedHeader=false. | List |
Message Body
The message body at each side of the Atom component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| One entry of the feed, a com.apptasticsoftware.rssreader.Item with its title, link, author, dates and content; with splitEntries=false the List of all the entries, empty for a feed without entries. The CamelAtomFeed header carries the List of the entries unless feedHeader=false.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Exchange data format
Camel will set the In body on the returned Exchange with the entries. Depending on the splitEntries flag Camel will either return one entry (a com.apptasticsoftware.rssreader.Item) or a List<Item>.
| Option | Value | Behavior |
|---|---|---|
|
| Only a single entry from the currently being processed feed is set: |
|
| The entire list of entries from the feed is set: |
Camel sets the List<Item> of all the entries of the feed on the CamelAtomFeed header (see the feedHeader option to disable this).
Usage
Avoid reading the same entry more than once (idempotent consumer)
Camel supports Idempotent Consumer directly within the component, so it will skip already processed entries. This feature is enabled by default, but can be disabled by setting the idempotent=false option.
-
Java
-
XML
-
YAML
from("atom://http://macstrac.blogspot.com/feeds/posts/default?idempotent=false").to("..."); <route>
<from uri="atom://http://macstrac.blogspot.com/feeds/posts/default?idempotent=false"/>
<to uri="..."/>
</route> - route:
from:
uri: atom://http://macstrac.blogspot.com/feeds/posts/default
parameters:
idempotent: false
steps:
- to:
uri: "..." The default Idempotency strategy uses Atom published and updated timestamps to identify already read entries, by filtering all entries older that the last read entry. So that no entry is skipped, the consumer routes the entries with this strategy from the oldest to the newest updated date (the published date for an entry without an updated date), as with sortEntries=true. An entry with the same date as the last read entry is distinguished by its id (the atom:id, else its link).
The idempotency strategy can be changed by setting the idempotentStrategy option. The components support two strategies out-of-the-box, but custom strategies can be used, by referencing a subclass of org.apache.camel.component.atom.AtomIdempotentStrategy, with Apache Camel’s # notation.
-
Java
-
XML
-
YAML
from("atom://http://macstrac.blogspot.com/feeds/posts/default?idempotentStrategy=#myIdempotentStrategy").to("..."); <route>
<from uri="atom://http://macstrac.blogspot.com/feeds/posts/default?idempotentStrategy=#myIdempotentStrategy"/>
<to uri="..."/>
</route> - route:
from:
uri: atom://http://macstrac.blogspot.com/feeds/posts/default
parameters:
idempotentStrategy: "#myIdempotentStrategy"
steps:
- to:
uri: "..." Repository idempotent strategy
As an alternative to the default idempotent strategy, a repository based strategy can be use:
-
Java
-
XML
-
YAML
from("atom://http://macstrac.blogspot.com/feeds/posts/default?idempotentStrategy=repository").to("..."); <route>
<from uri="atom://http://macstrac.blogspot.com/feeds/posts/default?idempotentStrategy=repository"/>
<to uri="..."/>
</route> - route:
from:
uri: atom://http://macstrac.blogspot.com/feeds/posts/default
parameters:
idempotentStrategy: repository
steps:
- to:
uri: "..." This strategy checks for idempotency by storing the Atom Entry GUID in an IdempotentRepository. The strategy defaults a MemoryIdempotentRepository, but the repository can be changes to any subclass of IdempotentRepository, using the idempotentRepository option.
Examples
Consumer Example
In this sample, we poll James Strachan’s blog.
-
Java
-
XML
-
YAML
from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds"); <route>
<from uri="atom://http://macstrac.blogspot.com/feeds/posts/default"/>
<to uri="seda:feeds"/>
</route> - route:
from:
uri: atom://http://macstrac.blogspot.com/feeds/posts/default
steps:
- to:
uri: seda:feeds In this sample, we want to filter only good blogs we like to a SEDA queue. The sample also shows how to set up Camel standalone, not running in any Container or using Spring.