14
Integration Pattern Splitter and Aggregators

Integration Pattern Splitter and Aggregators

Embed Size (px)

Citation preview

Page 1: Integration Pattern Splitter and Aggregators

Integration Pattern Splitter and

Aggregators

Page 2: Integration Pattern Splitter and Aggregators

Introduction

• Messages passing through an integration solution consist of multiple elements. • E.g. an order placed by a customer typically consists of more than just a single items like Address,

Product details , Mode Of Payment etc.

• We should process a complete order but treat each order item contained in the order individually

• How can we process a message having multiple elements, each of which may have to be processed in a different way?

• Publish Subscriber Model ????

Page 2

Page 3: Integration Pattern Splitter and Aggregators

Publish Subscriber an alternative to Splitter ?

• Publish a message having Multiple Orders to All Subscribers

• Each Subscriber would process the required/supported Order and discard other orders

• Inefficient• Each subscriber needs to implement logic to divide whole message and process supported one

• Increase Network Traffic

• Implement extra logic for lost / duplicate message handling

Page 3

Page 4: Integration Pattern Splitter and Aggregators

Splitter

• Use a Splitter to break out the composite message into a series of individual messages, each containing data related to one item.

• To avoid sending the complete message multiple times• Split them into multiple

• Each message would then contain only one items

• The Splitter publishes one message for each single element

Page 4

Page 5: Integration Pattern Splitter and Aggregators

Splitter -Handling Common Elements• In many cases, we repeat some common elements in each resulting message

• These extra elements might be required to make the resulting child message self-contained and enable stateless processing of each child message

• It also allows reconciliation of associated child messages later on

• Common Element can be Some ID or Timestamp

Page 5

Page 6: Integration Pattern Splitter and Aggregators

Iterative Splitter

• When Data in Message is stored in a Data Structure like Lists , Tree Or Map

• Then Splitter iterates over each records/Node and constructs the output

• Generic Splitter can be worked with any number of child elements

• Also Called Sequencer Splitter

Page 6

Page 7: Integration Pattern Splitter and Aggregators

Static Splitter

• Customized Splitter

• Used to split a large message into smaller messages based on some criteria e.g. subtype

• Usually it splits into Fixed number of messages

• The strategy of splitting is fixed hence its called static Splitter

Page 7

Page 8: Integration Pattern Splitter and Aggregators

Splitter -Input Message

• <order>    <date>7/18/2002</date>    <ordernumber>3825968</ordernumber>    <customer>        <id>12345</id>        <name>Joe Doe</name>    </customer>    <orderitems>        <item>            <quantity>3.0</quantity>            <itemno>W1234</itemno>            <description>A Widget</description>        </item>        <item>            <quantity>2.0</quantity>            <itemno>G2345</itemno>            <description>A Gadget</description>        </item>    </orderitems></order>

Page 8

Page 9: Integration Pattern Splitter and Aggregators

Splitter – Output Messages• <orderitem>

    <date>7/18/2002</date>    <ordernumber>3825968</ordernumber>    <customerid>12345</customerid>    <quantity>3.0</quantity>

    <itemno>W1234</itemno>    <description>A Widget</description></orderitem>

<orderitem>    <date>7/18/2002</date>    <ordernumber>3825968</ordernumber>    <customerid>12345</customerid>    <quantity>2.0</quantity>    <itemno>G2345</itemno>    <description>A Gadget</description></orderitem>

Page 9

Page 10: Integration Pattern Splitter and Aggregators

Aggregator

• Splitter splits single message into sequence of individual messages

• How can we combine results of individual but related messages ?• Asynchronous behavior

• Unknown number of recipients

• Response of individual message may be out of sequence

• How long should we wait ?• Wait for too long ?

• Set timeout • What should we do when response of few message is pending

• Should we send incomplete information ?

Page 10

Page 11: Integration Pattern Splitter and Aggregators

Aggregator

• A separate component which sends a single message Once all individual message response is ready

• Its called Aggregator because it collects individual messages until it receives a complete set and then it combines and sends a single message

• Special filter • which receives stream of messages It identifies the related messages . Once a complete set is arrived it sends to

output channel

Page 11

Page 12: Integration Pattern Splitter and Aggregators

• Stateful component• It needs to store all incoming messages(some information)

• Design1. Correlation: Which incoming messages belong together

ID, Timestamp etc

2. Completeness Condition: When are we ready to publish the result message?

3. Aggregation Algorithm: How do we combine the received messages into a single result message ?

Page 12

Aggregator

Page 13: Integration Pattern Splitter and Aggregators

Aggregator Implementation

Page 13

Message

First Message ?

Yes

Aggregator

Yes

Message

Correlation

exists

No

Aggregator

No

Create Aggregator

and add message

Add Message to

Existing Aggregator

Create Aggregator

and add message

Complete Set

Received

YesAggregate

and Construct

Single Message

NoWait till all messages received

SystemSend

message

Page 14: Integration Pattern Splitter and Aggregators

References

• Enterprise Integration Patterns a Book by Gregor Hohpe