Skip to Content
Technical Articles

EIPinCPI – Resequencer

Previous – Aggregator | Index | Next – Composed Message Processor

This week, we’ll study a variation of Aggregator Pattern known as Resequencer.

When do I use this pattern?

An aggregator is used when multiple related messages need to be combined into a single message. When these multiple messages need to be combined in a sequence a Resequencer is used. For example, order items may be split to be processed individually, however, the receiver wants them together and in sequence. In this case, a sequencer can be used to combine order items in a sequence.

Resequencer in CPI

In CPI, Aggregator component is used to implement a sequencer. For the demonstration, I’ll reuse the example from Aggregator Pattern blog. For resequencing, the element ‘Sequence’ has been added to each message.

These are the three order items:

<OrderItem>
    <Id>1</Id>
    <OrderId>001</OrderId>
    <NextOrderItemId>2</NextOrderItemId>
    <Sequence>1</Sequence>
</OrderItem>
<OrderItem>
    <Id>2</Id>
    <OrderId>001</OrderId>
    <NextOrderItemId>3</NextOrderItemId>
    <Sequence>2</Sequence>
</OrderItem>
<OrderItem>
    <Id>3</Id>
    <OrderId>001</OrderId>
    <Sequence>3</Sequence>
</OrderItem>

Integration Flow

This integration flow exposes Reseqencer as an HTTPS service using HTTPS Adapter. Step ‘Resequencer’ is an Aggregator component that is responsible for sequencing the order items. The Log step uses a Groovy Script to log the output.

The Resequencer’s configuration is as follows:

Tab Parameter Value
Correlation Correlation Expression /OrderItem/OrderId
Aggregation Strategy Incoming Format XML (Same Format)
Aggregation Strategy Aggregation Algorithm Combine in Sequence
Aggregation Strategy Message Sequence Expression /OrderItem/Sequence
Aggregation Strategy Last Message Condition not(boolean(/OrderItem/NextOrderItemId))
Aggregation Strategy Completion Timeout (in min) 60
Aggregation Strategy Data Store Name Orders

Here, the Aggregation Algorithm ‘Combine in Sequence’ tells Aggregator to behave like a Resequencer. Whereas, Message Sequence Expression tells the element to be used to order the messages.

Output

Here, the message with Sequence 2 was sent first, the message with Sequence 1 was sent second, and finally, the message with Sequence 3 was sent. However, in the output, the messages are ordered as per the Sequence element.

<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
    <multimap:Message1>
        <OrderItem>
            <Id>1</Id>
            <OrderId>001</OrderId>
            <NextOrderItemId>2</NextOrderItemId>
            <Sequence>1</Sequence>
        </OrderItem>
        <OrderItem>
            <Id>2</Id>
            <OrderId>001</OrderId>
            <NextOrderItemId>3</NextOrderItemId>
            <Sequence>2</Sequence>
        </OrderItem>
        <OrderItem>
            <Id>3</Id>
            <OrderId>001</OrderId>
            <Sequence>3</Sequence>
        </OrderItem>
    </multimap:Message1>
</multimap:Messages>

Conclusion

The Resequencer is a special form of Aggregator. It is used with multiple related messages need to be combined in a single message in sequence.

References/Further Readings

Hope this helps,
Bala

Previous – Aggregator | Index | Next – Composed Message Processor

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