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:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("helloworld.xml")
public class HelloWorldTest {
 
 @Autowired
 @Qualifier("messageChannel")
 MessageChannel messageChannel;

 @Test
 public void testHelloWorld() {
  Message<String> helloWorld = new GenericMessage<String>("Hello World");
  messageChannel.send(helloWorld);
 }
}

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"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:int="http://www.springframework.org/schema/integration"
 xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
 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"/>
 

</beans>

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.

References:
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.

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 two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


1 + nine =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close