12. Resequencer

12.1 Introduction

Related to the Aggregator, albeit different from a functional standpoint, is the Resequencer.

12.2 Functionality

The Resequencer works in a similar way to the Aggregator, in the sense that it uses the CORRELATION_ID to store messages in groups, the difference being that the Resequencer does not process the messages in any way. It simply releases them in the order of their SEQUENCE_NUMBER header values.

With respect to that, the user might opt to release all messages at once (after the whole sequence, according to the SEQUENCE_SIZE, has been released), or as soon as a valid sequence is available.

12.3 Configuring a Resequencer with XML

Configuring a resequencer requires only including the appropriate element in XML.

A sample resequencer configuration is shown below.

<channel id="inputChannel"/>

<channel id="outputChannel"/>

<resequencer id="completelyDefinedResequencer" 1
  input-channel="inputChannel" 2
  output-channel="outputChannel" 3
  discard-channel="discardChannel" 4
  release-partial-sequences="true" 5
  message-store="messageStore" 6
  send-partial-result-on-expiry="true" 7
  send-timeout="86420000" 8 /> 

1

The id of the resequencer is optional.

2

The input channel of the resequencer. Required.

3

The channel where the resequencer will send the reordered messages. Optional.

4

The channel where the resequencer will send the messages that timed out (if send-partial-result-on-timeout is false). Optional.

5

Whether to send out ordered sequences as soon as they are available, or only after the whole message group arrives. Optional (false by default).

If this flag is not specified (so a complete sequence is defined by the sequence headers) then it can make sense to provide a custom Comparator to be used to order the messages when sending (use the XML attribute comparator to point to a bean definition). If release-partial-sequences is true then there is no way with a custom comparator to define a partial sequence. To do that you would have to provide a release-strategy (also a reference to another bean definition, either a POJO or a ReleaseStrategy ).

6

A reference to a MessageGroupStore that can be used to store groups of messages under their correlation key until they are complete. Optional with default a volatile in-memory store.

7

Whether, upon the expiration of the group, the ordered group should be sent out (even if some of the messages are missing). Optional (false by default). See Section 11.5, “Managing State in an Aggregator: MessageGroupStore”.

8

The timeout for sending out messages. Optional.

[Note]Note
Since there is no custom behavior to be implemented in Java classes for resequencers, there is no annotation support for it.