Enterprise Integration Zone is brought to you in partnership with:

Idan is a software engineer with experience in Server side technologies. Idan is responsible for various infrastructure models in the software industry (Telecommunications, Finance). Idan is a DZone MVB and is not an employee of DZone and has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

No Fluff Spring Integration Messaging Patterns

09.20.2013
| 3596 views |
  • submit to reddit

This post will summarize only the key points about Spring Integration (SI) messaging patterns.

Each point will have a real world example based on my experience.

Splitter:

a. What it Does

The Splitter is actually a pattern that receives one message in one point and splits it into several.

b. Why is it good for me?

The Splitter can be used when you want to split your content into multiple parts. Each part will process the content asynchronously.

c. Real Life Example

In trading systems, you can have a trading-request. The request is suppose to be executed following a couple of steps: Execute it against a provider, log it in the DB and a send notification to the client.

With Splitter you can do all these things at once.

d. SI example:

<int:splitter id="tradeSplitter" input-channel="tradeSplitterInputChannel" output-channel="outPutChannel">

Router:

a. What it Does

The Router is a mechanism that dispatches a message to a specific destination based on whether the content received meets certain criteria.

b. Why is it good for me?

The router is very handy when you actually have different message inputs that need to be handled differently based on their content.

c. Real Life Example

Imagine you have a notification feature in your infrastructure. Each client chose to be notified differently (Email, Sms, Fax, Webservice,  etc.). With the Router, notification requests can be sent to the client based on their contact preferences.

d. SI Example:

router id="notificationsRouter" input-channel="notificationInputChannel"

Aggregator:

a. What it Does

The Aggregator role waits for a group of related messages. After all expected messages are retrieved, it will be able to merge them and send out a single result. The Aggregator is able to handle different group messages simultaneously by a group correlation Id.

b. Why is it good for me?

Usually, the Aggregators works together with a Splitter. After you split your request to multiple destinations in parallel, you might need to aggregate all destination results and send the final result as an output.

c. Real Life Example

In trading systems, you get different prices from different providers.  It's common to make a program that  chooses the best price among all providers. The Aggregator will be able to aggregate all prices and send back the best one.

d. SI Example:

<int:aggregator input-channel="bestPriceAgg" output-channel="bestPriceChannel"
send-partial-result-on-expiry="true">
</int:aggregator>

Filter:

a. What it Does

In short, it asks: “Do you want to get this message?”

b. Why is it good for me?

Instead of processing unnecessary messages, you could filter the messages based on the message payload (In the EJB world, it’s very similar to Message-driven Bean Selectors).

c. Real Life Example

In the trading system world you, could choose whether the commission in the final price should be included or not. Your component role is to add commissions only to the clients that wish for it. That component, via the filter, will receive only the prices that  are commission based.

d. SI Example:

<filter input-channel="commisionsChannel" ref="selector" output-channel="output"/>

Transformer:

a. What it Does

The transformer can receive a message and convert it’s payload from one type to another.

b. Why is it good for me?

You might need to convert your message from one format to another based on your destination.

I've often had to parse or convert messages to other formats after adding/modifying/deleting the payload content (e.g. from XML into a string and vice versa).

c. Real Life Example

So you have an order request. That request needs to be placed into the database in a specific format.  After that, it needs to be sent over to the client in XML format. With a transformer, you could transform the payload to fit your destinations requirements.

d. SI Example:

<object-to-string-transformer input-channel="in" output-channel="out"/>

There are  additional components in SI, but I think these are the most popular ones.


Published at DZone with permission of Idan Fridman, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)