Files
spring-integration/src/reference/docbook/resequencer.xml
2014-10-16 12:53:11 +03:00

217 lines
11 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="resequencer"
xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Resequencer</title>
<section>
<title>Introduction</title>
<para>Related to the Aggregator, albeit different from a functional
standpoint, is the Resequencer.</para>
</section>
<section id="resequencer-functionality">
<title>Functionality</title>
<para>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.</para>
<para>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.</para>
</section>
<section>
<title>Configuring a Resequencer</title>
<para>Configuring a resequencer requires only including the appropriate
element in XML.</para>
<para>A sample resequencer configuration is shown below.</para>
<programlisting language="xml"><![CDATA[<int:channel id="inputChannel"/>
<int:channel id="outputChannel"/>
<int:resequencer id="completelyDefinedResequencer" ]]><co id="resxml1-co"
linkends="resxml1" /><![CDATA[
input-channel="inputChannel" ]]><co id="resxml2-co" linkends="resxml2" /><![CDATA[
output-channel="outputChannel" ]]><co id="resxml3-co" linkends="resxml3" /><![CDATA[
discard-channel="discardChannel" ]]><co id="resxml4-co" linkends="resxml4" /><![CDATA[
release-partial-sequences="true" ]]><co id="resxml5-co" linkends="resxml5" /><![CDATA[
message-store="messageStore" ]]><co id="resxml6-co" linkends="resxml6" /><![CDATA[
send-partial-result-on-expiry="true" ]]><co id="resxml7-co"
linkends="resxml7" /><![CDATA[
send-timeout="86420000" ]]><co id="resxml10-co" linkends="resxml10" /><![CDATA[
correlation-strategy="correlationStrategyBean" ]]><co id="resxml11-co" linkends="resxml11" /><![CDATA[
correlation-strategy-method="correlate" ]]><co id="resxml12-co" linkends="resxml12" /><![CDATA[
correlation-strategy-expression="headers['foo']" ]]><co id="resxml13-co" linkends="resxml13" /><![CDATA[
release-strategy="releaseStrategyBean" ]]><co id="resxml14-co" linkends="resxml14" /><![CDATA[
release-strategy-method="release" ]]><co id="resxml15-co" linkends="resxml15" /><![CDATA[
release-strategy-expression="size() == 10" ]]><co id="resxml16-co" linkends="resxml16" /><![CDATA[
empty-group-min-timeout="60000" ]]><co id="resxml17-co" linkends="resxml17" /><![CDATA[
lock-registry="lockRegistry" ]]><co id="resxml18" /><![CDATA[
group-timeout="60000" ]]><co id="resxml19" /><![CDATA[
group-timeout-expression="size() ge 2 ? 100 : -1" ]]><co id="resxml20" /><![CDATA[
scheduler="taskScheduler" /> ]]><co id="resxml21" /><![CDATA[
expire-group-upon-timeout="false" /> ]]><co id="resxml22" /></programlisting>
<para><calloutlist>
<callout arearefs="resxml1-co" id="resxml1">
<para>The id of the resequencer is
<emphasis>optional</emphasis>.</para>
</callout>
<callout arearefs="resxml2-co" id="resxml2">
<para>The input channel of the resequencer.
<emphasis>Required</emphasis>.</para>
</callout>
<callout arearefs="resxml3-co" id="resxml3">
<para>The channel to which the resequencer will send the reordered
messages. <emphasis>Optional</emphasis>.</para>
</callout>
<callout arearefs="resxml4-co" id="resxml4">
<para>The channel to which the resequencer will send the messages that
timed out (if <code>send-partial-result-on-timeout</code> is
<emphasis>false)</emphasis>. <emphasis>Optional</emphasis>.</para>
</callout>
<callout arearefs="resxml5-co" id="resxml5">
<para>Whether to send out ordered sequences as soon as they are
available, or only after the whole message group arrives.
<emphasis>Optional (false by default)</emphasis>.</para>
</callout>
<callout arearefs="resxml6-co" id="resxml6">
<para>A reference to a <code>MessageGroupStore</code> that can be
used to store groups of messages under their correlation key until
they are complete. <emphasis>Optional</emphasis> with default a
volatile in-memory store.</para>
</callout>
<callout arearefs="resxml7-co" id="resxml7">
<para>Whether, upon the expiration of the group, the ordered group
should be sent out (even if some of the messages are missing).
<emphasis>Optional (false by default)</emphasis>. See <xref
linkend="reaper" />.</para>
</callout>
<callout arearefs="resxml10-co" id="resxml10">
<para>The timeout interval to wait when sending a reply
<interfacename>Message</interfacename> to the <code>output-channel</code> or <code>discard-channel</code>.
By default the send will block for one second.
It is applied only if the output channel has some 'sending' limitations, e.g. <classname>QueueChannel</classname>
with a fixed 'capacity'. In this case a <classname>MessageDeliveryException</classname> is thrown.
The <code>send-timeout</code> is ignored in case of <classname>AbstractSubscribableChannel</classname> implementations.
In case of <code>group-timeout(-expression)</code> the <classname>MessageDeliveryException</classname>
from the scheduled expire task leads this task to be rescheduled.
<emphasis>Optional</emphasis>.</para>
</callout>
<callout arearefs="resxml11-co" id="resxml11">
<para>A reference to a bean that implements the message correlation (grouping)
algorithm. The bean can be an implementation of the <interfacename>CorrelationStrategy</interfacename>
interface or a POJO. In the latter case the correlation-strategy-method attribute must be defined
as well. <emphasis>Optional (by default, the aggregator will use
the <code>IntegrationMessageHeaderAccessor.CORRELATION_ID</code> header) </emphasis>.</para>
</callout>
<callout arearefs="resxml12-co" id="resxml12">
<para>A method defined on the bean referenced by
<code>correlation-strategy</code>, that implements the
correlation decision algorithm. <emphasis>Optional, with
restrictions (requires <code>correlation-strategy</code> to be
present).</emphasis></para>
</callout>
<callout arearefs="resxml13-co" id="resxml13">
<para>A SpEL expression representing the correlation strategy.
Example: <code>"headers['foo']"</code>. Only one of <code>correlation-strategy</code>
or <code>correlation-strategy-expression</code> is allowed.</para>
</callout>
<callout arearefs="resxml14-co" id="resxml14">
<para>A reference to a bean that implements the release strategy.
The bean can be an implementation of the <interfacename>ReleaseStrategy</interfacename> interface
or a POJO. In the latter case the release-strategy-method
attribute must be defined as well. <emphasis>Optional (by default, the
aggregator will use the <code>IntegrationMessageHeaderAccessor.SEQUENCE_SIZE</code> header attribute)</emphasis>.</para>
</callout>
<callout arearefs="resxml15-co" id="resxml15">
<para>A method defined on the bean referenced by
<code>release-strategy</code>, that implements the
completion decision algorithm. <emphasis>Optional, with
restrictions (requires <code>release-strategy</code> to be
present).</emphasis></para>
</callout>
<callout arearefs="resxml16-co" id="resxml16">
<para>A SpEL expression representing the release strategy; the root object for the
expression is a <code>Collection</code> of <code>Message</code>s.
Example: <code>"size() == 5"</code>. Only one of
<code>release-strategy</code>
or <code>release-strategy-expression</code> is allowed.</para>
</callout>
<callout arearefs="resxml17-co" id="resxml17">
<para>Only applies if a <classname>MessageGroupStoreReaper</classname> is configured
for the <code>&lt;resequcencer&gt;</code>'s <classname>MessageStore</classname>.
By default, when a <classname>MessageGroupStoreReaper</classname> is configured to expire partial
groups, empty groups are also removed. Empty groups exist after a group
is released normally. This is to enable the detection and discarding of
late-arriving messages. If you wish to expire empty groups on a longer
schedule than expiring partial groups, set this property. Empty groups will
then not be removed from the <classname>MessageStore</classname> until they have not been modified
for at least this number of milliseconds. Note that the actual time to expire an
empty group will also be affected by the reaper's <emphasis>timeout</emphasis>
property and it could be as much as this value plus the timeout.</para>
</callout>
<callout arearefs="resxml18">
<para>
See <xref linkend="aggregator-xml"/>.
</para>
</callout>
<callout arearefs="resxml19">
<para>
See <xref linkend="aggregator-xml"/>.
</para>
</callout>
<callout arearefs="resxml20">
<para>
See <xref linkend="aggregator-xml"/>.
</para>
</callout>
<callout arearefs="resxml21">
<para>
See <xref linkend="aggregator-xml"/>.
</para>
</callout>
<callout arearefs="resxml22" id="resxml22-txt">
<para>
When a group is completed due to a timeout (or by a <classname>MessageGroupStoreReaper</classname>), the
empty group's metadata
is retained by default. Late arriving messages will be immediately discarded. Set this
to <code>true</code> to remove the group completely; then, late arriving messages will start a new group
and won't be discarded until the group again times out. The new group will never be released normally
because of the "hole" in the sequence range that caused the timeout.
Empty groups can be expired (completely removed) later using a
<classname>MessageGroupStoreReaper</classname> together with the <code>empty-group-min-timeout</code>
attribute. Default: 'false'.
</para>
</callout>
</calloutlist></para>
<note>
Since there is no custom behavior to be implemented in Java classes for resequencers, there is no annotation support for it.
</note>
</section>
</section>