Spring Integration – Manipulate RSS Feed Data and Write to Files


In this tutorial we will create an example on how to manipulate data from RSS Feed and write to files periodically using Spring Integration framework. This guide uses Spring Integration using Java configuration to retrieve data from RSS feed, manipulate and write to files.

In this example we will create both gradle and maven based build configurations to build our application. We will read the feed data from URL https://spring.io/blog.atom. We will transform to return the feed title, author and URL in a single line and write to the files. The files are generated under system’s temp directory under folder spring-integration/rss-feed. The file name ends with .msg. You can open such file using Notepad or Notepad++.


Eclipse 4.12, Spring Boot 2.2.3, Spring Integration 5.2.3, Java at least 8, Gradle 5.6, Maven 3.6.1

Create Project

Create a gradle or maven based project in Eclipse with the project’s name as spring-integration-rss-feed-to-file.

Update the maven based pom.xml or gradle based build.gradle build file with the corresponding content as shown below.


<project xmlns="http://maven.apache.org/POM/4.0.0"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">





					<source>at least 8</source>
					<target>at least 8</target>


buildscript {
	ext {
		springBootVersion = '2.2.2.RELEASE'
    repositories {
    dependencies {

plugins {
    id 'java-library'
    id 'org.springframework.boot' version '2.2.3.RELEASE'

sourceCompatibility = 12
targetCompatibility = 12

repositories {

dependencies {

Spring Configuration

Now we will create Spring Integration configuration class to read data from RSS feed, transform and write to file under temp directory.

Create a class called FlowConfig and annotate with @Configuration.

Add RSS feed URL in this class as follows:

@Value(value = "https://spring.io/blog.atom")
private Resource feedResource;

Write to files under temp/spring-integration directory:

public MessageHandler targetDirectory() {
	FileWritingMessageHandler handler = new FileWritingMessageHandler(
			new File(System.getProperty("java.io.tmpdir") + "/spring-integration/rss-feed"));
	// handler.setCharset("UTF-8");
	return handler;

If the directory spring-integration/rss-feed does not exist then we create the directory automatically by setting flag to true. Under this directory you will find files are generated with the content.

We don’t want reply so we set to false.

Transform or manipulate data from RSS feed:

public AbstractPayloadTransformer<SyndEntry, String> extractLinkFromFeed() {
	return new AbstractPayloadTransformer<SyndEntry, String>() {
		protected String transformPayload(SyndEntry payload) {
			return payload.getTitle() + " " + payload.getAuthor() + " " + payload.getLink();


We just append the title, author and URL from RSS feed into a single string. You may have different purpose but for simplicity we have kept the simple logic. You may also need to work on other fields of RSS feed.

Now integrate all flows together to read data from RSS feed, transform and write to file:

public IntegrationFlow feedFlow() {
	return IntegrationFlows
			.from(Feed.inboundAdapter(this.feedResource, "news"), e -> e.poller(p -> p.fixedDelay(5000)))
			// .handle(System.out::println)

So every 5 seconds data will be read from RSS feed and written to file.

I have also commented one line handle(System.out::println) and this line is used to print or log into the standard console.

Main Class

A class with main method and @SpringBootApplication annotation is enough to deploy the application into embedded Tomcat server.

package com.roytuts.spring.integration.rss.feed.to.file;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringIntegrationRSSFeedToFileApp {

	public static void main(String[] args) {
		SpringApplication.run(SpringIntegrationRSSFeedToFileApp.class, args);


Testing the Application

Running the above main class will give you the following output:

The file names are random with content.

When you open one of the files in an editor, such as, Notepad or Notepad++, then you will see similar to below content in it:

Spring Vault 2.2.1.RELEASE and 2.1.5.RELEASE available Mark Paluch https://spring.io/blog/2020/01/17/spring-vault-2-2-1-release-and-2-1-5-release-available

That’s all.

Source Code


Thanks for reading.

Leave a Reply

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