Home » Java » Enterprise Java » Spring Integration – Session 1 – Hello World

About Biju Kunjummen

Biju Kunjummen

Spring Integration – Session 1 – Hello World

The ” Hello World” of Spring Integration – consider a simple program to print “Hello World” to the console using Spring Integration and in the process visit a few Enterprise Integration Patterns Concepts

Before jumping into the program itself, a quick review of messaging concepts will be helpful – Messaging is an Integration style where two independent applications communicate with each other through an intermediary – the intermediary is referred to as the “Messaging System”.

Enterprise Integration Patterns describes the common Integration related issues with Messaging based application Integration and their recommended solutions.

For eg. Consider one of the Enterprise Integration Patterns – The Messaging Channel, to quote from the Entprise Integration Patterns Book:

The problem “Messaging Channel” is trying to solve is:

An enterprise has two separate applications that need to communicate, preferably by using Messaging.
How does one application communicate with another using messaging?

The solution is:

Connect the applications using a Message Channel, where one application writes information to the channel and the other one reads that information from the channel.
All the other Enterprise Integration Patterns are described along the same lines.

The reason to quickly visit Enterprise Integration Patterns is to set the context – Spring Integration aligns very closely with the Enterprise Integration Patterns and is the “Messaging system” that was mentioned earlier.

So now to see the Hello World using Spring Integration:

First a small junit:

public class HelloWorldTest {
 MessageChannel messageChannel;

 public void testHelloWorld() {
  Message<String> helloWorld = new GenericMessage<String>("Hello World");

Here a MessageChannel is being wired into the test, the first application (here the Junit), sends a Message(in this case a string “Hello World”) to the Message Channel, something reads the message from the “Message Channel” and writes the message to the system out.

Now, let us see the remaining part of how “something” picks up a message from the Message Channel and writes to the system out:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd
  http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.1.xsd
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

 <int:channel id="messageChannel"></int:channel>
 <int-stream:stdout-channel-adapter channel="messageChannel" append-newline="true"/>


The above is a Spring Integration flow being described using Spring Custom namespaces, here the Integration Namespace. A “Message Channel”, imaginatively called the “messageChannel” is created, a “Hello World” “Message” is placed into the “Messsage Channel”, from which a “Channel Adapter” gets the message and prints it to the standard out.

This is a small program, but it uses three Enterprise Integration Patterns – the Message (“Hello World”, which is the packet of information being sent to the messaging system, the ” Message Channel” which was introduced earlier and the new one, the Channel Adapter, here an Outbound Channel Adapter which connects the messaging system to the application(in this case the system out). It further shows how Spring Integration aligns very closely with the Enterprise Integration Patterns terminology with its Spring custom namespace.

This simple program introduces Spring Integration, I will be introducing Spring Integration in more detail using a few more samples in the next few sessions.

1. Spring Integration Reference: http://static.springsource.org/spring-integration/reference/htmlsingle/
2. Enterprise Integration Patterns: http://www.eaipatterns.com/index.html
3. Visio templates for EIP : http://www.eaipatterns.com/downloads.html

Reference: Spring, Spring Integration, Enterprise Development from our JCG partner Biju Kunjummen at the all and sundry blog.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

Be the First to Comment!

Notify of