Spring Integration key notes with real life scenarios

Hi,

This post will summarize Spring Integration (SI) important key notes together with messaging Integration patterns.

For each key note I will add a real life example based on my experience.

Splitter:

a. What it does?

The Splitter is actually a pattern which receives one message in one point and split 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 suppose to be executed following a couple of steps: (execute it against a provider, logging it in the DB, send notification to the client)

With Splitter you can do all 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 when a message being received in one point and by a content based criteria it will dispatch to a specific destination.

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

So you have a notification feature in your infrastructure. Each client chose to be noticed differently (Email, Sms, Fax, Webservice,  etc..). Notification request being sent to the client and based on the request content the router will choose to which component the request will be handed: EmailService, SmscService, FaxService and so on..

d. SI example:

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

Aggregator:

a. What it does?

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

b. Why is it good for me?

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

c. Real life example

In trading systems you get different prices from different providers. It’s very often to choose 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: “Do you want to get this message?”

b. Why is it good for me?

Your component might get different messages. 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 which wish for it. That component via filter will receive only the prices which 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 could have convert your message format from one to another based on your destination.

b. Why is it good for me?

Many times we receiving input in one format and we need to parse or convert them to other format after adding/modifying/deleting the payload content ( For example from XML into String and vice versa).

c. Real life example

So you have an order request. That request need to be placed in DB in a specific format, After that it needs to be sent over to the client within an xml format. You could transform the payload to fit your destination needs.

d. SI example:

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

There are  additional components in SI. Those are the most popular ones. That’s all for now, Idan.

Related Articles:

(1583)

Be Sociable, Share!

Leave a Reply