Spring Integration Essentials

By Chandan Pandey
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting Started

About this book

This book begins with an introduction to the enterprise integration landscape, the challenges, the approaches that have been tried, and how Spring Integration can help address these issues. You will learn how to deal with enterprise integration challenges such as the heterogeneous communication format, data transfer, transformation, external system invocation, security or transaction propagation, and more. You will also see how each of these layers can be addressed by a specific set of Spring Integration components.

You will explore each Spring Integration component in the context of the enterprise integration problem that it tries to address by covering the theory, writing code snippets, and doing real integration.

By the end, you will not only be able to identify and design enterprise communication, but you will also be able to code it using Spring Integration.

Publication date:
February 2015
Publisher
Packt
Pages
198
ISBN
9781783989164

 

Chapter 1. Getting Started

In this chapter, we will set up our development environment and discuss how we can leverage SpringSource Tool Suite (STS) to its maximum. Although any popular Java development IDE such as Eclipse, intelliJ, NetBeans, and others can be used for developing Spring Integration solutions, pivotal, the company spearheading Spring Integration, recommends that you use STS which is an Eclipse-based IDE.

 

Setting up STS


STS comes with many off-the-shelf plugins, visual editors, and other features, which ease the development of Spring-powered enterprise applications. The look and feel of the IDE is very similar to Eclipse. Install STS by following these steps:

  1. JDK 1.6 and above is a prerequisite, download and install it from http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html.

  2. Set JAVA_HOME properties as explained in the documentation at https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/index.html.

  3. Download STS from http://spring.io/tools/sts.

  4. The downloaded file is in ZIP format. Extract it to the preferred folder and it's all set.

  5. Go to <installation-directory>\sts-bundle\sts-3.6.1.RELEASE. The STS.exe file is the executable for launching the IDE.

  6. This step is optional but can help in efficient functioning of the OS editor—change the memory allocation parameter. Locate STS.ini (in the same folder as STS.exe) and change the value of Xmx. For 2 GB, I've put it as Xmx2048m.

 

Creating your first project


The following steps will help you in creating your first project:

  1. Create a Spring Integration project by navigating to File | Spring Project, as shown in the following screenshot:

  2. Under the templates section, select Spring Integration Project - Simple. Provide a project name, for example, sisimple, as shown in the following screenshot:

  3. Fill in the information required to create a Maven-based project, as shown in this screenshot:

  4. Click on Finish; this will create a project with the name that was provided by us (sisimple), as shown in this screenshot:

This project is as simple as it can be. Let's take a quick look at the generated Java classes in the following points:

  • Main.java: This file is located at the path: /sisimple/src/main/java/com/chandan/example/si/. It has the main method and will be used to run this sample. Right-click on this file from the package explorer and click on Run As | Java Application—this will start the program. This class has the code to bootstrap Spring Integration configuration files and load components defined in it. Additionally, it converts user input to upper case.

  • StringConversionService.java: This file is located at the path: /sisimple/src/main/java/com/chandan/example/si/service/. This is the service interface that is used to convert user input to upper case.

  • spring-integration-context.xml: This file is located at the path: /sisimple/src/main/resources/META-INF/spring/integration/. It is the Spring Integration configuration file. It contains the XML-based declaration of Spring Integration components.

  • log4j.xml: This file is located at the path: /sisimple/src/main/resources/. It is the Log4j configuration file. It can be edited to control the log level, appenders, and other logging-related aspects.

  • StringConversionServiceTest.java: This file is located at the path: /sisimple/src/test/java/com/chandan/example/si/. This is the test file for StringConversionService. This will be used to run tests against the service classes.

  • pom.xml: This is the file used for rmaven dependency management, located in /sisimple/. It has entries for all the dependencies used by the project.

It will be a bit heavy and premature to explain each of the components in these classes and configuration files without having built up some theoretical concepts—we will discuss each of the elements in detail, as we move ahead in the chapters.

 

STS visual editor


STS provides visual ways to add different namespaces. Locate spring-integration-context.xml under /sisimple/src/main/resources/META-INF/spring/integration/ and open it. This is the default Spring configuration file. Click on the Namespaces tab to manage different namespaces of Spring Integration. The following screenshot shows imported namespaces for this sample project:

In the same editor, clicking on the Integration-graph tab will open a visual editor, which can be used to add/modify or delete endpoints, channels, and other components of Spring Integration. The following screenshot contains the integration graph for our sample project:

Let's have a quick look at the generated Maven POM—overall, there are three dependencies; only one for Spring Integration, and the other ones for Junit and log4j, as shown in the following screenshot:

 

Spring Integration Scala DSL


This is still in the very early stages and is an incubation project. Scala DSL should not be confused with other EIP implementations being offered in Scala—rather, it is built on top of Spring Integration and provides DSL-based configuration and flow management.

 

Summary


In this chapter, you learned how to set up your IDE and created a basic project. We also tried our hands at the visual editor of STS and covered a quick introduction of the upcoming Scala DSL for Spring Integration. We will leverage this knowledge to build a compelling Spring Integration application using STS throughout the rest of the chapters.

In the next chapter, we will cover how to ingest messages in the application and then how to process them.

About the Author

  • Chandan Pandey

    Chandan Pandey is an Oracle Certified Enterprise architect with more than 10 years of experience in designing, coding, and delivering enterprise applications using various tools and technologies. He has always been amused by the power of software that reduces the boredom of repetitive tasks and introduces agility and efficiency. He firmly believes that tools, technology, and methodology are a medium to provide a solution and would like to be positioned as a solutions expert rather than limiting his identity to a framework or tool. This is reflected in the breadth and depth of his work; he is proficient not only in traditional languages and frameworks such as Java/JEE and Spring, but also in Groovy and Grails, Vaadin, and Play Framework, to name a few. His domain experience varies from blogging applications, web frameworks, content management systems, and finance, to networking & telecom. For him, the end result should be extendable, scalable, secure, and easy-to-use systems!

    He believes in community ecosystems and tries to share his learning with larger audiences. He writes regularly at www.chandanpandey.com, and this book is a step forward to connect with the community.

    When he is not working or writing, he likes to go on road trips with his family to explore new avenues—be it spiritual, historical, or just a leisure tour! India being his home country, he is never short of surprises and variety!

    Browse publications by this author
Book Title
Unlock this full book with a FREE 10-day trial
Start Free Trial