Popular EIP Frameworks comparison

Enterprise Integration Patterns solves problems of enterprise application integration and message-oriented middleware. The aim of this article is to show the two EIP frameworks: Apache Camel and Spring Integration from the perspective of a developer who knows EIP patterns quite well but do not have very long experience with using these frameworks.

Paweł Weselak

|

11 Jan
2018

Introduction

Enterprise Integration Patterns solves problems of enterprise application integration and message-oriented middleware. I recommend the book by Gregor Hohpe and Bobby Woolf where authors catalogued the patterns.

The aim of this article is to show the two EIP frameworks: Apache Camel and Spring Integration from the perspective of a developer who knows EIP patterns quite well but do not have very long experience with using these frameworks. For the purpose of this article I’m going to take the most recent versions of both frameworks (I will use new Java DSL from Spring Integration and Apache Camel fluent API) to write simple application for sending order notifications via email. I want to see which framework will meet my needs better, how long will it take to write a complete app, what is the learning curve, what problems I can have and what help is available in the Internet to solve them out.

Flow of sample application

The application does the one simple task – confirms to a client the order he placed in some online store. It can be considered as a part of bigger application built upon microservices architecture.

1. HTTP inbound adapter receives XML order sent with POST method

2. Received order is validated against XSD schema

a. If validation fails message is rejected and stored in filesystem directory

Spring Integration

Starting from version 4.0 Spring Integration provides Java DSL. It is basically a façade over Spring Integration components and it enables us to configure the flow using java code without any single line of XML configuration. Furthermore, If you love Java 8 lambda expressions you will be delighted.

How it looks in the practice? Let’s see the flow defined for the sample app:

I think Java DSL is consistent and thanks to that it is easy to use. The DSL has methods like filter, transform or handle corresponding to the SI components. Additional configuration for the parameter can be passed as a second parameter to the method, often it is a lambda expression. The defined flow is quite contracted but not sure if the code is easy to read for everyone. Sometimes number of lambdas can be overwhelming.

Was it difficult to learn and use new Java DSL? Spring has very good documentation in general which helps a lot, it is well structured and each Spring Integration component is described in detail. Java DSL documentation is available on github. It is also easy to read but little bit outdated, for example Http is not listed among supported protocols (namespace factories) although it is present in the current version of the API.

Sometimes we need to dive into the Spring code for searching the class name of the component we want to use because it is not always mentioned in the documentation. XmlValidatingMessageSelector is a good example. Moreover, when I finally found the class I wasn’t sure how to use it with Java DSL but luckily enough it turn out pretty simple.

What annoys me in Spring Integration is the lack of support for XML namespaces in several XML components. XPath SpEL expression is not namespace aware, you cannot pass a namespace to XPathHeaderEnricher also. Thankfully XPathExpressionFactory has factory method where one can pass namespaces map and I usedg that in my CustomXPathHeaderValueMessageProcessor.

To sum up, using Spring Integration Java DSL was interesting and enjoyable experience. Quite complicated app can be built up quickly without writing a lot of boiler plate code. Let’s check how another popular EIP framework will work out in the same task.

Apache Camel

For defining flows Java DSL is also available in another popular integration framework, Apache Camel. Java DSL is not the only option, Camel gives us plenty other DSLs we can choose from. Additionally, using Camel we can benefit from Spring, Guice and CDI (Camel Dependency Injection) frameworks.

As you can see the code is self-explanatory and incredibly compact and very easy to read when well formatted. The conception of components URIs is surprisingly nifty. The worth to mention is fact that Camel has good XML namespace support.

Camel has comprehensive documentation, the components are very well documented and each component has a few examples of usage. When you want to perform certain task, you just open the components page, find the component you need, open the component description and you have ready to use example or at least detailed description. Nevertheless, documentation pages for me are not very intuitive to navigate, I use google from time to time to find documentation page I am interested.

The framework is really flexible, it allows to do one thing in many different ways. Although I think that sometimes it is not good idea to give too much freedom to developers, it can lead to bugs, confusions and a mishmash code. Often it is hard to decide which option will meet our needs the best.

Summarize

I share the opinion of Björn Beskow presented on his blog. In addition to that I’ve noticed that Camel DSL is less verbose than Spring DSL. Also writing application in Spring Integration I spent twice as many time as doing it in Camel. Spring surprised me with more exceptions which elongated the process, writing the flow in Camel was far way more intuitive.

To conclude, both frameworks are lightweight, mature, well supported and have good documentation. Each of us has different preferences so I recommend you to try out different available libraries. Maybe Mule I haven’t discussed in the article will be your favorite?

Paweł Weselak

Senior Java Developer. In IT industry since 2010. Sharing his knowledge and experiences Pawel finds the most rewarding in everyday work. He doesn't underestimate importance of developing soft skills in the job of software engineer. He is keen on Machine Learning and data analysis. His free time Pawel spends on traveling, dancing, snowboarding and striking up new acquaintances.