Hello everyone, In this post, you will learn How to Poll RSS Feed using Apache Camel. The example has been tested and shared in the post.

Maven Dependencies

<dependency>
<groupid>org.apache.camel</groupid>
<artifactid>camel-core</artifactid>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupid>org.apache.camel</groupid>
<artifactid>camel-rss</artifactid>
<version>${camel-rss-version}</version>
</dependency>

Example Program

package com.dineshkrish.example7;
import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
/**
* 
* @author Dinesh Krishnan
*
*/
public class PollRSSFeed {
public static void main(String[] args) throws Exception {
// creating camel context
CamelContext context = new DefaultCamelContext();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("rss:http://www.feedforall.com/sample.xml?alt=rss&splitEntries=false&consumer.delay=1000")
.to("seda:end");
}
});
// creating a consumer template
ConsumerTemplate template = context.createConsumerTemplate();
while (true) {
context.start();
// receiving the RSS feed
String rssFeed = template.receiveBody("seda:end", String.class);
System.out.println(rssFeed);
}
} catch (Exception e) {
context.stop();
System.out.println(e.getMessage());
}
}
}

Output

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
<!--?xml version="1.0" encoding="UTF-8"?-->
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
<channel>
<title>FeedForAll Sample Feed</title>
<link>http://www.feedforall.com/industry-solutions.htm
<description>RSS is a fascinating technology. The uses for RSS are expanding daily. Take a closer look at how various industries are using the benefits of RSS in their businesses.</description>
<language>en-us</language>
<copyright>Copyright 2004 NotePage, Inc.</copyright>
<pubdate>Tue, 19 Oct 2004 17:38:55 GMT</pubdate>
<category domain="www.dmoz.com">Computers/Software/Internet/Site Management/Content Management</category>
<dc:creator>marketing@feedforall.com</dc:creator>
<dc:subject>
<rdf:description>
<taxo:topic rdf:resource="www.dmoz.com">
<rdf:value>Computers/Software/Internet/Site Management/Content Management</rdf:value>
</taxo:topic></rdf:description>
</dc:subject>
<dc:date>2004-10-19T17:38:55Z</dc:date>
<dc:language>en-us</dc:language>
<dc:rights>Copyright 2004 NotePage, Inc.</dc:rights>
................
.................
</channel></rss>

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *