Spring Integration with Java Config: An Example from Spring Integration in Action

The year is 2016. As a developer, the majority of the third-party service endpoints I work with on a daily basis follow (or sort of follow) the RESTful API guidelines. However, RESTful APIs were not always the web transfer methodology of choice. There are numerous ways to transmit information over HTTP. Outside of HTTP, systems might also employ FTP or another use of the TCP/IP protocol to transmit information between computers. For managing multiple myriad types of integrations, we have Spring Integration.

To get an overview of Spring Integration and understand what the tool can do, I recommend sections 3.3.1—3.4.7 of the documentation. These sections explain the concept of a message and a channel, and they provide many examples of how and why different configurations of messages and channels might be used.

After that, I would recommend taking a look at this documentation for the Spring Integration Java DSL. If you are already ramping a development team on Java or on Spring, the Java Config for Spring Integration will look and feel more similar to the other code they’re writing than an XML configuration would. It should be noted that not all of Spring Integration’s capabilities have been ported to the Java Config DSL at this time. If you find yourself needing something special that the Java DSL does not cover, the book Spring Integration in Action provides excellent examples of the XML config, as do sections 4 and above in the documentation for Spring Integration.

I found the book Spring Integration in Action extremely helpful for understanding how Spring works, but all of the examples in the book are configured in XML. So I decided to rework an example from one of the book’s introductory chapters using Java Config instead of XML.

Here is an explanation of the business problem:

An airline has a web app through which customers can book their flights. This app also exposes an API that airline comparison sites can use to let customers book flights.
For each booking, the app should charge the credit card and, if that succeeds, proceed to seat selection. Those two steps should happen immediately so we can make sure the airline gets paid and we can make sure that we don’t overbook or book two people in the same seat.
Additionally the customer should get a confirmation email, but that does not have to happen right away if the system is under a lot of load.
Finally, people booking flights from the airline’s website should have priority over the customers of the comparison sites.
Here is my attempt at a Java Config version of a business solution:

This is a first attempt and may need to be tweaked and clarified. I welcome feedback!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s