Skip to Content
Technical Articles

EIPinCPI – Scatter-Gather

Previous – Composed Message Processor | Index | Next – Routing Slip

This week, we’ll study a routing pattern known as Scatter-Gather.

When do I use this pattern?

When the message needs to be sent to multiple recipients but only one response needs to be considered for further processing, then the Scatter-Gather pattern can be applied. For example, when booking a flight, the itinerary can be sent to multiple airlines for the quote, finally, only the best quote will be sent as a response.

Scatter-Gather in CPI

In CPI, Scatter part can be implemented by a Multicast, whereas, Gather part can be implemented by a combination of an Aggregator and a Groovy Script.

Integration Flow

In this integration flow, a user can place an order through the Online Ordering System (OS). The order is sent to ‘Airline1’ and ‘Airline2’ for a quote using Command Message Pattern. Finally, all the quotes are combined together using an Aggregator and the best Quote is determined using a Groovy Script.

Example Run

Let’s consider that the order arrives from the ordering system as follows:

<Order>
	<Id>1234</Id>
	<Flight>
		<From>United Kingdom</From>
		<To>India</To>
	</Flight>
</Order>

Airline 1 returns £500 total price, whereas, Airline 2 return £450 total price

<Price>
	<Id>1234</Id>
	<Airline>1</Airline>
	<Amount>500</Amount>
</Price>
<Price>
	<Id>1234</Id>
	<Airline>2</Airline>
	<Amount>450</Amount>
</Price>

The aggregator combines these two responses in one message like so:

<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <multimap:Message1>
        <Price>
            <Id>1234</Id>
            <Airline>1</Airline>
            <Amount>500</Amount>
        </Price>
        <Price>
            <Id>1234</Id>
            <Airline>2</Airline>
            <Amount>450</Amount>
        </Price>
    </multimap:Message1>
</multimap:Messages>

Finally, the script keeps the cheapest price in the message:

<Price>
    <Id>1234</Id>
    <Airline>2</Airline>
    <Amount>450</Amount>
</Price>

Scatter-Gather vs Composed Message Processor

In Scatter-Gather, the entire input message is sent to various systems and the best response is selected. On the other hand, Composed Message Processor splits the message into sub-messages and combines the responses back into a single message.

Conclusion

The Scatter-Gather pattern is used when the message needs to be sent to multiple systems, however, only one response needs to be considered as output.

References/Further Readings

Hope this helps,
Bala

P.S.: To check how to implement Scatter-Gather pattern in SAP PO and learn another way of implementing Scatter-Gather pattern in SAP CPI, head over to Alex‘s blog on Scatter-Gather pattern.

Previous – Composed Message Processor | Index | Next – Routing Slip

/
Be the first to leave a comment
You must be Logged on to comment or reply to a post.