Indeed, you can use Spring Integration to power the e-mail polling functionality in a Swing/JavaFX
application! It's as lightweight as you want it to be.
In subsequent examples, the configuration shown should be put in an XML file and that XML file
referenced as the first parameter when running this class. When the main method runs to completion,
your context will start up the Spring Integration bus and start responding to requests on the components
configured in the application context's XML.
8-3. Integrating Two Systems Using JMS
You want to build an integration to connect one application to another using JMS, which provides
location and temporal decoupling on modern middleware for Java applications. You're interested in
applying more sophisticated routing and want to isolate your code from the specifics of the origin of the
message (in this case, the JMS queue or topic).
While you can do this by using regular JMS code or EJB's support for message-driven beans (MDBs),
or using core Spring's message-driven POJO (MDP) support, all are necessarily coded for handling
messages coming specifically from JMS. Your code is tied to JMS. Using an ESB lets you hide the origin
of the message from the code that's handling it. You'll use this solution as an easy way to see how a
Spring Integration solution can be built. Spring Integration provides an easy way to work with JMS, just
as you might using MDPs in the core Spring container. Here, however, you could conceivably replace the
JMS middleware with an e-mail, and the code that reacts to the message could stay the same.
How it Works
Building an MDP Using Spring Integration
As you recall from Chapter 7, Spring can replace EJB's message driven bean (MDB) functionality by
using message-driven POJOs (MDPs). This is a powerful solution for anyone wanting to build something
that handles messages on a message queue. You'll build an MDP, but you will configure it using Spring
Integration's more concise configuration and provide an example of a very rudimentary integration. All
this integration will do is take an inbound JMS message (whose payload is of type Map<String,Object> ).
As with a standard MDP, configuration for the JMSConnectionFactory exists. There's also a lot of
other schema required for using the configuration elements available in Spring Integration. Shown
following is a configuration file. You can store in on the classpath, and pass it in as a parameter to the
Spring ApplicationContext on creation (as you did in the previous recipe, in the Main class.)
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans=" http://www.springframework.org/schema/beans"