Spring Book – Chapter 20 – Spring Integration

Channel Adapter

Channel adapters are used to connect an application to the messaging system so that it can send and receive messages. Again, the definition written in the book “Enterprise Integration Pattern”, by Gregor Hohpe and Bobby Woolf is as given below:

The adapter acts as a messaging client to the messaging system and invokes applications functions via an application-supplied interface. This way, any application can connect to the messaging system and be integrated with other applications as long as it has a proper Channel Adapter.

Pictorially channel adapter can be represented as shown in Figure 22-31 below.

Figure 22-31. Function of Channel Adapter

Figure 22-31. Function of Channel Adapter

Spring Integration Support

Spring Integration provides a number of adapters which shields application components from integration details. External events produce various kinds of messages which feds into the Spring Integration. The adapters according to the message type kicks into action and deals with the messages without caring neither about the message origin nor about destination. Once the message is processed it can trigger another external event to which the processed messages are sent.

Figure 22-32. Spring Integration adapters

Figure 22-32. Spring Integration adapters

The Spring Integration includes support for the following adapters:

  • Filesystem
  • FTP, FTPS and Secured File Transfer Protocol (SFTP)
  • User Datagram Protocol (UDP)
  • TCP
  • HTTP (Representational State Transfer [REST])
  • Web services (SOAP)
  • Mail (POP3 or IMAP for receiving, SMTP for sending)
  • Java Message Service (JMS)
  • JDBC
  • Java Management Extensions (JMX)
  • Remote Method Invocation (RMI)
  • Really Simple Syndication (RSS) feeds
  • Twitter
  • Extensible Messaging and Presence Protocol (XMPP)

The following sections are aimed at explaining some of the important adapters in some detail. Since these are very extensive topic, I would like to give you information and details which allow you a stepping-stone in actually considering using these adapters in your application. Some adapters, I will only be giving information and you can find more details on these from other books available in market.

Each of the following sub-sections in which Spring’s Integration capability will be covered in detail follows a standard sub-sections as shown below:

  • Brief Introduction
  • Maven Dependency
  • Spring Integration Namespace
  • Adapter Configuration

File System

It is one of the simplest approaches to enterprise integration. Spring Integration provides both inbound and outbound channel adapters to support this integration style.

Listing 22-31 below shows maven dependency required for integrating file system using Spring Integration.

Listing 22-31. Maven dependency required

Listing 22-32 below shows configuration of main Spring Integration namespace and file related namespace in the Spring configuration file (file-integration-context.xml).

Listing 22-32. Spring Integration Namespace declaration

Listing 22-33 below shows configuration of a basic file adapter in the Spring configuration file (file-integration-context.xml). In this sample, the file inbound channel adapter polls the configured directory every 5 seconds and passes it onto the “inputFileChannel” and then the file output channel adapter reads the files in the channel to the output directory configured.

Listing 22-33. Basic file adpater configuration

There are various atributes in “inbound-channel-adapter” as shown in Table 22-3 using which can be used to change the behavior of this adapter according to your application requirement. I would not be able to explain these attributes in detail (excessively much and out of scope of this book) but think it would be of great help to know that these attributes can be used if need arises in your application.

Table 22-3. The attributes in “inbound-channel-adapter” element

Attribute Name Description
comparator Specify a Comparator to be used when ordering Files. If none is provided, the order will be determined by the java.io.File implementation of Comparable.
filter Specify a FileListFilter to be used. By default, an AcceptOnceFileListFilter is used, which ensures files are picked up only once from the directory. You can also apply multiple filters by referencing a CompositeFileListFilter.
filter-pattern Only files matching this ant style path will be picked up by this adapter.
filename-regex Only files matching this regular expression will be picked up by this adapter.
scanner Reference to a custom DirectoryScanner implementation.
prevent-duplicates A boolean flag indicating whether duplicates should be prevented. If a ‘filter’ reference is provided, duplicate prevention will not be enabled by default (the assumption is that the provided filter is sufficient), but setting this to true will enable it. If a ‘filename-pattern’ is provided, duplicate prevention will be enabled by default (preceding the pattern matching), but setting this to false will disable it. If neither ‘filter’ nor ‘filename-pattern’ is provided, duplicate prevention is enabled by default, but setting this to false will disable it. For more detail on the actual duplicate prevention, see the Javadoc for AcceptOnceFileListFilter.


Spring Integration also provides an outbound gateway file adapter, which will send the file as a payload to the reply channel as soon as written.

Note: In the above Table 22-1, only some attributes have been explained which the adapter to customize it further can use.

Page Visitors: 13388

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 20 – Spring Integration

  1. Hi,
    Thanks for this blog and information sharing!
    I have one question from Spring Integration. Just thought of checking with you.
    I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
    This is my current gateway configuration:

    Please let me know, if you can throw some light in this area.
    Thanks in Advance!

  2. Hi,
    Thank you for your information sharing.
    I have one doubt,could you please suggest me the correct frameworks to address that issue.

    My requirement is I would like to get and process files using spring and camel.


Leave a Reply

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