Over a million developers have joined DZone.

Spring Integration Feed Adapter: How to receive RSS feeds using Spring?

DZone 's Guide to

Spring Integration Feed Adapter: How to receive RSS feeds using Spring?

· Java Zone ·
Free Resource

Spring Integration provides a feed adapter for Web Syndication to subscribe to an RSS or an ATOM feed.

Maven Dependency

The following Maven dependency is required for the feed adapter


Spring Configuration

The feed adapter is configured by providing the URL of the RSS feed and the channel where the feed will be sent. The below sample configuration shows that feed adapter will listen to the RSS feed at http://www.skilledmonster.com/feed/ and will send a message to the channel feedChannel.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    <int:channel id="feedChannel">
        <int:queue />
    <feed:inbound-channel-adapter id="feedAdapter"
        channel="feedChannel" url="http://www.skilledmonster.com/feed/">
        <int:poller fixed-rate="30000" max-messages-per-poll="1" />

The message will have a payload of the type com.sun.syndication.feed.syn.SyndEntry, which encapsulates information about the news item including content, dates, and authors. A poller element is required for the feed adapter, because it is a poller consumer.

Note that the feed adapter is slightly different than other polling consumers. When the feed adapter is first started and does its first poll, a com.sun.syndication.feed.synd.SyndEntryFeed instance is received. This object contains multiple SyndEntry objects and each entry is stored in a local entry queue and released based on the max-messages-per-poll property of the poller. This queue will be refreshed if it becomes empty and there are additional new entries available.

Test Run

This a simple test class where I create a Spring context and messages are pulled from the message channel feedChannel.

The payload coming from the feed adapter is of the type SyndEntry. The main class logs the published date and the title of the entry. Additional information such as the context may also be derived from the SyndEntry instance

The feed adapter may be tested using the main class as shown below

package com.skilledmonster.spring.integration.rss;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.core.PollableChannel;
import com.skilledmonster.spring.integration.twitter.TwitterMessageConsumer;
import com.sun.syndication.feed.synd.SyndEntry;
* Feed adapter for pulling rss feeds from my own website
* @author Jagadeesh
public class WebSyndicationInbound {
    private static Logger LOG = Logger.getLogger(TwitterMessageConsumer.class);
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
        // create a pollable channel
        PollableChannel feedChannel = context.getBean("feedChannel", PollableChannel.class);
        for (int i = 0; i < 10; i++) {
            // receive the message feed
            Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
            if (message != null) {
                SyndEntry entry = message.getPayload();
                // display
                LOG.info(entry.getPublishedDate() + " - " + entry.getTitle());
            } else {

Now, perhaps with little more work you can start building your own RSS reader!



Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}