blob: c48800d8aa5fac88c01c6f19512b7907b70c9529 [file]
= RSS Component
:doctitle: RSS
:shortname: rss
:artifactid: camel-rss
:description: Poll RSS feeds.
:since: 2.0
:supportlevel: Stable
:tabs-sync-option:
:component-header: Only consumer is supported
*Since Camel {since}*
*{component-header}*
The RSS component is used for polling RSS feeds. By default, Camel will
poll the feed every 60th second.
Maven users will need to add the following dependency to their `pom.xml`
for this component:
[source,xml]
----
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rss</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
----
NOTE: The component currently only supports consuming feeds.
== URI format
----
rss:rssUri
----
Where `rssUri` is the URI to the RSS feed to poll.
// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
include::partial$component-endpoint-headers.adoc[]
// component options: END
== Usage
=== Exchange data types
Camel initializes the In body on the Exchange with a ROME `SyndFeed`.
Depending on the value of the `splitEntries` flag, Camel returns either
a `SyndFeed` with one `SyndEntry` or a `java.util.List` of `SyndEntrys`.
[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Option |Value |Behavior
|`splitEntries` |`true` |A single entry from the current feed is set in the exchange.
|`splitEntries` |`false` |The entire list of entries from the current feed is set in the exchange.
|=======================================================================
== Example
If the URL for the RSS feed uses query parameters, this component will
resolve them. For example, if the feed uses `alt=rss`, then the following example will be resolved:
[tabs]
====
Java::
+
[source,java]
----
from("rss:http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&delay=1000")
.to("bean:rss");
----
XML::
+
[source,xml]
----
<route>
<from uri="rss:http://someserver.com/feeds/posts/default?alt=rss&amp;splitEntries=false&amp;delay=1000"/>
<to uri="bean:rss"/>
</route>
----
YAML::
+
[source,yaml]
----
- route:
from:
uri: "rss:http://someserver.com/feeds/posts/default?alt=rss&splitEntries=false&delay=1000"
steps:
- to:
uri: bean:rss
----
====
=== Filtering entries
You can filter out entries using XPath, as shown in the
data format section above. You can also exploit Camel's
Bean Integration to implement your own
conditions. For instance, a filter equivalent to the XPath example above
would be:
[tabs]
====
Java::
+
[source,java]
----
from("rss:file:src/test/data/rss20.xml?splitEntries=true&delay=100")
.filter().method("myFilterBean", "titleContainsCamel")
.to("mock:result");
----
XML::
+
[source,xml]
----
<route>
<from uri="rss:file:src/test/data/rss20.xml?splitEntries=true&amp;delay=100"/>
<filter>
<method ref="myFilterBean" method="titleContainsCamel"/>
<to uri="mock:result"/>
</filter>
</route>
----
YAML::
+
[source,yaml]
----
- route:
from:
uri: rss:file:src/test/data/rss20.xml
parameters:
splitEntries: true
delay: 100
steps:
- filter:
method:
ref: myFilterBean
method: titleContainsCamel
steps:
- to:
uri: mock:result
----
====
The custom bean for this would be:
._Java-only: bean class definition with annotations and type casts_
[source,java]
----
public static class FilterBean {
public boolean titleContainsCamel(@Body SyndFeed feed) {
SyndEntry firstEntry = (SyndEntry) feed.getEntries().get(0);
return firstEntry.getTitle().contains("Camel");
}
}
----
== Proxy Support in Camel RSS Component
The Camel RSS component does not natively support proxy configuration. However, you can work around this limitation by using the Camel HTTP component with a proxy and then processing the raw RSS feed using RSS dataformat.
Alternative Approach: Using the HTTP Component with Proxy
Instead of directly using `from("rss:...")`, you can configure an HTTP client with proxy settings and fetch the RSS feed via the HTTP component. Then, zhe RSS dataformat can be used to parse the raw response into a structured RSS feed.
=== Configuring Proxy for HTTP Component and Processing RSS
Below is an example that sets up an HTTP client with a proxy (including authentication support) and uses it to retrieve and process an RSS feed:
._Java-only: programmatic proxy configuration with HttpClientConfigurer, registry binding, and RouteBuilder class_
[source,java]
----
protected RoutesBuilder createRouteBuilder() throws Exception {
String proxyHost = "myProxyHost";
Integer proxyPort = 8888;
String proxyUserName = "username";
String proxyPassword = "password";
context().getRegistry().bind("myHttpClientConfigurer", new HttpClientConfigurer() {
@Override
public void configureHttpClient(HttpClientBuilder clientBuilder) {
var routePlanner = new DefaultProxyRoutePlanner(new HttpHost(proxyHost, proxyPort)) {
@Override
protected HttpHost determineProxy(HttpHost host, HttpContext context) throws HttpException {
// Custom logic for filtering specific hosts
return super.determineProxy(host, context);
}
};
clientBuilder.setRoutePlanner(routePlanner);
clientBuilder.setProxyAuthenticationStrategy(new DefaultAuthenticationStrategy());
var credentials = new UsernamePasswordCredentials(
proxyUserName,
proxyPassword.toCharArray()
);
var credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(proxyHost, proxyPort),
credentials
);
clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
});
from("timer://mytimer?fixedRate=false&period=60&synchronous=true")
.to("http://feeds.aps.org/rss/recent/prstper.xml?httpClientConfigurer=#myHttpClientConfigurer")
.unmarshal(new RssDataFormat())
.to("mock:result");
}
----