Major progress on Gradle port
Complete: -------- - src/* documentation resources moved to 'docs' subproject - docbook sources upgraded to Docbook 5 - formatted all docbook sources to strip tab characters and eliminate trailing whitespace - all projects compile and test successfully - all artifacts upload successfully to s3, static.sf.org, etc. Remaining: --------- - documentation L&F needs work. CSS, images, and highlighting aren't hooked up properly - spring-integration-jdbc codegen bits in Maven POM need to be transcribed into gradle - dependencies that were optional or provided scope in maven are currently 'compile' scope in Gradle. Need to figure out support in Gradle to fix this. - run through Eclipse classpath and project generation scenarios - delete all Maven artifacts
@@ -1,626 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="aggregator">
|
||||
<title>Aggregator</title>
|
||||
|
||||
<section id="aggregator-introduction">
|
||||
<title>Introduction</title>
|
||||
|
||||
<para>Basically a mirror-image of the Splitter, the Aggregator is a type
|
||||
of Message Handler that receives multiple Messages and combines them into
|
||||
a single Message. In fact, Aggregators are often downstream consumers in a
|
||||
pipeline that includes a Splitter.</para>
|
||||
|
||||
<para>Technically, the Aggregator is more complex than a Splitter, because
|
||||
it is required to maintain state (the Messages to be aggregated), to
|
||||
decide when the complete group of Messages is available. In order to do
|
||||
this it requires a MessageStore</para>
|
||||
</section>
|
||||
|
||||
<section id="aggregator-functionality">
|
||||
<title>Functionality</title>
|
||||
|
||||
<para>The Aggregator combines a group of related messages, by correlating
|
||||
and storing them, until the group is deemed complete. At that point, the
|
||||
Aggregator will create a single message by processing the whole group, and
|
||||
will send that aggregated message as output.</para>
|
||||
|
||||
<para>An main aspect of implementing an Aggregator is providing the logic
|
||||
that has to be executed when the aggregation (creation of a single message
|
||||
out of many) takes place. The other two aspects are correlation and
|
||||
release</para>
|
||||
|
||||
<para>In Spring Integration, the grouping of the messages for aggregation
|
||||
(correlation) is done by default based on their CORRELATION_ID message
|
||||
header (i.e. the messages with the same CORRELATION_ID will be grouped
|
||||
together). However, this can be customized, and the users can opt for
|
||||
other ways of specifying how the messages should be grouped together, by
|
||||
using a CorrelationStrategy (see below).</para>
|
||||
|
||||
<para>To determine whether or not a group of messages may be processed, a
|
||||
ReleaseStrategy is consulted. The default release strategy for aggregator
|
||||
will release groups that have all messages from the sequence, but this can
|
||||
be entirely customized</para>
|
||||
</section>
|
||||
|
||||
<section id="aggregator-api">
|
||||
<title>Programming model</title>
|
||||
|
||||
<para>The Aggregation API consists of a number of classes:</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>The interface <code>MessageGroupProcessor</code> and related
|
||||
base class <code>AbstractAggregatingMessageGroupProcessor</code> and
|
||||
its subclass
|
||||
<code>MethodInvokingAggregatingMessageGroupProcessor</code></para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>The <code>ReleaseStrategy</code> interface and its default
|
||||
implementation <code>SequenceSizeReleaseStrategy</code></para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>The <code>CorrelationStrategy</code> interface and its default
|
||||
implementation <code>HeaderAttributeCorrelationStrategy</code></para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<section>
|
||||
|
||||
|
||||
<title>CorrelatingMessageHandler</title>
|
||||
|
||||
|
||||
|
||||
<para>The <code>CorrelatingMessageHandler</code> is a
|
||||
<code>MessageHandler</code> implementation, encapsulating the common
|
||||
functionalities of an Aggregator (and other correlating use cases),
|
||||
which are: <itemizedlist>
|
||||
<listitem>
|
||||
<para>correlating messages into a group to be aggregated</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>maintaining those messages in a MessageStore until the group
|
||||
may be released</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>deciding when the group is in fact may be released</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>processing the released group into a single aggregated
|
||||
message</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>recognizing and responding to an expired group</para>
|
||||
</listitem>
|
||||
</itemizedlist> The responsibility of deciding how the messages should
|
||||
be grouped together is delegated to a <code>CorrelationStrategy</code>
|
||||
instance. The responsibility of deciding whether the message group can
|
||||
be released is delegated to a <code>ReleaseStrategy</code>
|
||||
instance.</para>
|
||||
|
||||
|
||||
|
||||
<para>Here is a brief highlight of the base
|
||||
<code>AbstractAggregatingMessageGroupProcessor</code> (the
|
||||
responsibility of implementing the aggregateMessages method is left to
|
||||
the developer):</para>
|
||||
|
||||
|
||||
|
||||
<programlisting language="java"><![CDATA[public abstract class AbstractAggregatingMessageGroupProcessor
|
||||
implements MessageGroupProcessor {
|
||||
|
||||
protected Map<String, Object> aggregateHeaders(MessageGroup group) {
|
||||
....
|
||||
}
|
||||
|
||||
protected abstract Object aggregatePayloads(MessageGroup group);
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
The CorrelationStrategy is owned by the
|
||||
|
||||
<code>CorrelatingMessageHandler</code>
|
||||
|
||||
and it has a default value based on the correlation ID message header:
|
||||
|
||||
<programlisting language="java"><![CDATA[private volatile CorrelationStrategy correlationStrategy =
|
||||
new HeaderAttributeCorrelationStrategy(MessageHeaders.CORRELATION_ID);]]></programlisting>
|
||||
|
||||
|
||||
|
||||
<para>When appropriate, the simplest option is the
|
||||
<code>DefaultAggregatingMessageGroupProcessor</code>. It creates a
|
||||
single Message whose payload is a List of the payloads received for a
|
||||
given group. It uses the default <code>CorrelationStrategy</code> and
|
||||
<code>CompletionStrategy</code> as shown above. This works well for
|
||||
simple Scatter Gather implementations with either a Splitter, Publish
|
||||
Subscribe Channel, or Recipient List Router upstream.</para>
|
||||
|
||||
|
||||
|
||||
<note>
|
||||
<para>When using a Publish Subscribe Channel or Recipient List Router
|
||||
in this type of scenario, be sure to enable the flag to
|
||||
<emphasis>apply-sequence</emphasis>. That will add the necessary
|
||||
headers (correlation id, sequence number and sequence size). That
|
||||
behavior is enabled by default for Splitters in Spring Integration,
|
||||
but it is not enabled for the Publish Subscribe Channel or Recipient
|
||||
List Router because those components may be used in a variety of
|
||||
contexts where those headers are not necessary.</para>
|
||||
</note>
|
||||
|
||||
|
||||
|
||||
<para>When implementing a specific aggregator object for an application,
|
||||
a developer can extend
|
||||
<code>AbstractAggregatingMessageGroupProcessor</code> and implement the
|
||||
<code>aggregatePayloads</code> method. However, there are better suited
|
||||
(which reads, less coupled to the API) solutions for implementing the
|
||||
aggregation logic, which can be configured easily either through XML or
|
||||
through annotations.</para>
|
||||
|
||||
|
||||
|
||||
<para>In general, any ordinary Java class (i.e. POJO) can implement the
|
||||
aggregation algorithm. For doing so, it must provide a method that
|
||||
accepts as an argument a single java.util.List (parametrized lists are
|
||||
supported as well). This method will be invoked for aggregating
|
||||
messages, as follows:</para>
|
||||
|
||||
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>if the argument is a parametrized java.util.List, and the
|
||||
parameter type is assignable to Message, then the whole list of
|
||||
messages accumulated for aggregation will be sent to the
|
||||
aggregator</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>if the argument is a non-parametrized java.util.List or the
|
||||
parameter type is not assignable to Message, then the method will
|
||||
receive the payloads of the accumulated messages</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>if the return type is not assignable to Message, then it will
|
||||
be treated as the payload for a Message that will be created
|
||||
automatically by the framework.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
|
||||
|
||||
<note>
|
||||
<para>In the interest of code simplicity, and promoting best practices
|
||||
such as low coupling, testability, etc., the preferred way of
|
||||
implementing the aggregation logic is through a POJO, and using the
|
||||
XML or annotation support for setting it up in the application.</para>
|
||||
</note>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>ReleaseStrategy</title>
|
||||
|
||||
<para>The <code>ReleaseStrategy</code> interface is defined as
|
||||
follows:</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[public interface ReleaseStrategy {
|
||||
|
||||
boolean canRelease(MessageGroup messages);
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
<para>In general, any ordinary Java class (i.e. POJO) can implement the
|
||||
completion decision mechanism. For doing so, it must provide a method
|
||||
that accepts as an argument a single java.util.List (parametrized lists
|
||||
are supported as well), and returns a boolean value. This method will be
|
||||
invoked after the arrival of a new message, to decide whether the group
|
||||
is complete or not, as follows:</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>if the argument is a parametrized java.util.List, and the
|
||||
parameter type is assignable to Message, then the whole list of
|
||||
messages accumulated in the group will be sent to the method</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>if the argument is a non-parametrized java.util.List or the
|
||||
parameter type is not assignable to Message, then the method will
|
||||
receive the payloads of the accumulated messages</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>the method must return true if the message group is ready for
|
||||
aggregation, and false otherwise.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para>When the group is released for aggregation, all its unmarked
|
||||
messages are processed and then marked so they will not be processed
|
||||
again. If the group is also complete (i.e. if all messages from a
|
||||
sequence have arrived or if there is no sequence defined) then the group
|
||||
is removed from the message store. Partial sequences can be released, in
|
||||
which case the next time the <code>ReleaseStrategy</code> is called it
|
||||
will be presented with a group containing marked messages (already
|
||||
processed) and unmarked messages (a potential new partial
|
||||
sequence)</para>
|
||||
|
||||
<para>Spring Integration provides an out-of-the box implementation for
|
||||
<code>ReleaseStrategy</code>, the
|
||||
<code>SequenceSizerReleaseStrategy</code>. This implementation uses the
|
||||
SEQUENCE_NUMBER and SEQUENCE_SIZE of the arriving messages for deciding
|
||||
when a message group is complete and ready to be aggregated. As shown
|
||||
above, it is also the default strategy.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>CorrelationStrategy</title>
|
||||
|
||||
<para>The <code>CorrelationStrategy</code> interface is defined as
|
||||
follows:</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[public interface CorrelationStrategy {
|
||||
|
||||
Object getCorrelationKey(Message<?> message);
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
<para>The method shall return an Object which represents the correlation
|
||||
key used for grouping messages together. The key must satisfy the
|
||||
criteria used for a key in a Map with respect to the implementation of
|
||||
equals() and hashCode().</para>
|
||||
|
||||
<para>In general, any ordinary Java class (i.e. POJO) can implement the
|
||||
correlation decision mechanism, and the rules for mapping a message to a
|
||||
method's argument (or arguments) are the same as for a
|
||||
<code>ServiceActivator</code> (including support for @Header
|
||||
annotations). The method must return a value, and the value must not be
|
||||
<code>null</code>.</para>
|
||||
|
||||
<para>Spring Integration provides an out-of-the box implementation for
|
||||
<code>CorrelationStrategy</code>, the
|
||||
<code>HeaderAttributeCorrelationStrategy</code>. This implementation
|
||||
returns the value of one of the message headers (whose name is specified
|
||||
by a constructor argument) as the correlation key. By default, the
|
||||
correlation strategy is a HeaderAttributeCorrelationStrategy returning
|
||||
the value of the CORRELATION_ID header attribute.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="aggregator-xml">
|
||||
<title>Configuring an Aggregator with XML</title>
|
||||
|
||||
<para>Spring Integration supports the configuration of an aggregator via
|
||||
XML through the <aggregator/> element. Below you can see an example
|
||||
of an aggregator with all optional parameters defined.</para>
|
||||
|
||||
<programlisting lang="xml"><![CDATA[<channel id="inputChannel"/>
|
||||
|
||||
<aggregator id="completelyDefinedAggregator" ]]><co id="aggxml1" /><![CDATA[
|
||||
input-channel="inputChannel" ]]><co id="aggxml2" /><![CDATA[
|
||||
output-channel="outputChannel" ]]><co id="aggxml3" /><![CDATA[
|
||||
discard-channel="discardChannel" ]]><co id="aggxml4" /><![CDATA[
|
||||
ref="aggregatorBean" ]]><co id="aggxml5" /><![CDATA[
|
||||
method="add" ]]><co id="aggxml6" /><![CDATA[
|
||||
release-strategy="releaseStrategyBean" ]]><co id="aggxml7" /><![CDATA[
|
||||
release-strategy-method="canRelease" ]]><co id="aggxml8" /><![CDATA[
|
||||
correlation-strategy="correlationStrategyBean" ]]><co
|
||||
id="aggxmlCorrelationStrategy" /><![CDATA[
|
||||
correlation-strategy-method="groupNumbersByLastDigit" ]]><co
|
||||
id="aggxmlCorrelationStrategyMethod" /><![CDATA[
|
||||
message-store="messageStore" ]]><co id="aggxml11-co" linkends="aggxml11" /><![CDATA[
|
||||
send-partial-result-on-expiry="true" ]]><co id="aggxml9" /><![CDATA[
|
||||
send-timeout="86420000" ]]><co id="aggxml10" /><![CDATA[ />
|
||||
|
||||
<channel id="outputChannel"/>
|
||||
|
||||
<bean id="aggregatorBean" class="sample.PojoAggregator"/>
|
||||
|
||||
<bean id="releaseStrategyBean" class="sample.PojoReleaseStrategy"/>
|
||||
|
||||
<bean id="correlationStrategyBean" class="sample.PojoCorrelationStrategy"/>]]></programlisting>
|
||||
|
||||
<calloutlist>
|
||||
<callout arearefs="aggxml1">
|
||||
<para>The id of the aggregator is
|
||||
<emphasis>optional</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml2">
|
||||
<para>The input channel of the aggregator.
|
||||
<emphasis>Required</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml3">
|
||||
<para>The channel where the aggregator will send the aggregation
|
||||
results. <emphasis>Optional (because incoming messages can specify a
|
||||
reply channel themselves)</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml4">
|
||||
<para>The channel where the aggregator will send the messages that
|
||||
timed out (if <code>send-partial-results-on-timeout</code> is
|
||||
<emphasis>false</emphasis>). <emphasis>Optional</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml5">
|
||||
<para>A reference to a bean defined in the application context. The
|
||||
bean must implement the aggregation logic as described above.
|
||||
<emphasis>Required</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml6">
|
||||
<para>A method defined on the bean referenced by <code>ref</code>,
|
||||
<emphasis>that implements the message aggregation
|
||||
algorithm.</emphasis> <emphasis>Optional, with restrictions (see
|
||||
above).</emphasis></para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml7">
|
||||
<para>A reference to a bean that implements the decision algorithm as
|
||||
to whether a given message group is complete. The bean can be an
|
||||
implementation of the CompletionStrategy interface or a POJO. In the
|
||||
latter case the completion-strategy-method attribute must be defined
|
||||
as well. <emphasis>Optional (by default, the aggregator will use
|
||||
sequence size) </emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml8">
|
||||
<para>A method defined on the bean referenced by
|
||||
<code>release-strategy</code>, <emphasis>that implements the
|
||||
completion decision algorithm.</emphasis> <emphasis>Optional, with
|
||||
restrictions (requires <code>completion-strategy</code> to be
|
||||
present).</emphasis></para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxmlCorrelationStrategy">
|
||||
<para>A reference to a bean that implements the correlation strategy.
|
||||
The bean can be an implementation of the CorrelationStrategy 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 correlation id header attribute)
|
||||
</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxmlCorrelationStrategyMethod">
|
||||
<para>A method defined on the bean referenced by
|
||||
<code>correlation-strategy</code>, <emphasis>that implements the
|
||||
correlation key algorithm.</emphasis> <emphasis>Optional, with
|
||||
restrictions (requires <code>correlation-strategy</code> to be
|
||||
present).</emphasis></para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml11-co" id="aggxml11">
|
||||
<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 arch="" arearefs="aggxml9">
|
||||
<para>Whether upon the expiration of the message group, the aggregator
|
||||
will try to aggregate the messages that have already arrived.
|
||||
<emphasis>Optional (false by default)</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="aggxml10">
|
||||
<para>The timeout for sending the aggregated messages to the output or
|
||||
reply channel. <emphasis>Optional</emphasis>.</para>
|
||||
</callout>
|
||||
</calloutlist>
|
||||
|
||||
<para>Using a "ref" attribute is generally recommended if a custom
|
||||
aggregator handler implementation can be reused in other
|
||||
<code><aggregator></code> definitions. However if a custom
|
||||
aggregator handler implementation should be scoped to a concrete
|
||||
definition of the <code><aggregator></code>, you can use an inner
|
||||
bean definition (starting with version 1.0.3) for custom aggregator
|
||||
handlers within the <code><aggregator></code> element:
|
||||
<programlisting language="xml"><![CDATA[<aggregator input-channel="input" method="sum" output-channel="output">
|
||||
<beans:bean class="org.foo.ExampleAggregator"/>
|
||||
</aggregator>]]></programlisting></para>
|
||||
|
||||
<note>
|
||||
<para>Using both a "ref" attribute and an inner bean definition in the
|
||||
same <code><aggregator></code> configuration is not allowed, as it
|
||||
creates an ambiguous condition. In such cases, an Exception will be
|
||||
thrown.</para>
|
||||
</note>
|
||||
|
||||
<para>An example implementation of the aggregator bean looks as
|
||||
follows:</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[public class PojoAggregator {
|
||||
|
||||
public Long add(List<Long> results) {
|
||||
long total = 0l;
|
||||
for (long partialResult: results) {
|
||||
total += partialResult;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
<para>An implementation of the completion strategy bean for the example
|
||||
above may be as follows:</para>
|
||||
|
||||
<para><programlisting language="java"><![CDATA[public class PojoReleaseStrategy {
|
||||
...
|
||||
public boolean canRelease(List<Long> numbers) {
|
||||
int sum = 0;
|
||||
for (long number: numbers) {
|
||||
sum += number;
|
||||
}
|
||||
return sum >= maxValue;
|
||||
}
|
||||
}]]></programlisting> <note>
|
||||
<para>Wherever it makes sense, the release strategy method and the
|
||||
aggregator method can be combined in a single bean.</para>
|
||||
</note></para>
|
||||
|
||||
<para>An implementation of the correlation strategy bean for the example
|
||||
above may be as follows:</para>
|
||||
|
||||
<para><programlisting language="java"><![CDATA[public class PojoCorrelationStrategy {
|
||||
...
|
||||
public Long groupNumbersByLastDigit(Long number) {
|
||||
return number % 10;
|
||||
}
|
||||
}]]></programlisting></para>
|
||||
|
||||
<para>For example, this aggregator would group numbers by some criterion
|
||||
(in our case the remainder after dividing by 10) and will hold the group
|
||||
until the sum of the numbers which represents the payload exceeds a
|
||||
certain value.</para>
|
||||
|
||||
<note>
|
||||
<para>Wherever it makes sense, the release strategy method, correlation
|
||||
strategy method and the aggregator method can be combined in a single
|
||||
bean (all of them or any two).</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title id="reaper">Managing State in an Aggregator:
|
||||
MessageGroupStore</title>
|
||||
|
||||
<para>Aggregator (and some other patterns in Spring Integration) is a
|
||||
stateful pattern that requires decisions to be made based on a group of
|
||||
messages that have arrived over a period of time, all with the same
|
||||
correlation key. The design of the interfaces in the stateful patterns
|
||||
(e.g. <classname>ReleaseStrategy</classname>) is driven by the principle
|
||||
that the components (framework and user) should be to remain stateless.
|
||||
All state is carried by the <classname>MessageGroup</classname> and its
|
||||
management is delegated to the
|
||||
<classname>MessageGroupStore</classname>.</para>
|
||||
|
||||
<para>The <classname>MessageGroupStore</classname> accumulates state
|
||||
information in <classname>MessageGroups</classname>, potentially forever.
|
||||
So to prevent stale state from hanging around, and for volatile stores to
|
||||
provide a hook for cleaning up when the application shots down, the
|
||||
<classname>MessageGroupStore</classname> allows the user to register
|
||||
callbacks to apply to <classname>MessageGroups</classname> when they
|
||||
expire. The interface is very straighforward:</para>
|
||||
|
||||
<programlisting><![CDATA[public interface MessageGroupCallback {
|
||||
|
||||
void execute(MessageGroupStore messageGroupStore, MessageGroup group);
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
<para>The callback has access directly to the store and the message group
|
||||
so it can manage the persistent state (e.g. by removing the group from the
|
||||
store entirely).</para>
|
||||
|
||||
<para>The MessageGroupStore maintains a list of these callbacks which it
|
||||
applies when asked to all messages whose timestamp is earlier than a time
|
||||
supplied as a parameter:</para>
|
||||
|
||||
<programlisting><![CDATA[public interface MessageGroupStore {
|
||||
void registerMessageGroupExpiryCallback(MessageGroupCallback callback);
|
||||
int expireMessageGroups(long timeout);
|
||||
}]]></programlisting>
|
||||
|
||||
<para>The expireMessageGroups method can be called with a timeout value:
|
||||
any message older than the current time minus this value wiull be expired,
|
||||
and have the callbacks applied. Thus it is the user of the store that
|
||||
defines what is meant by message group "expiry".</para>
|
||||
|
||||
<para>As a convenience for users, Spring Integration provides a wrapper
|
||||
for the message expiry in the form of a
|
||||
<classname>MessageGroupStoreReaper</classname>:</para>
|
||||
|
||||
<programlisting><![CDATA[<bean id="reaper" class="org...MessageGroupStoreReaper">
|
||||
<property name="messageGroupStore" ref="messageStore"/>
|
||||
<property name="timeout" value="10"/>
|
||||
</bean>
|
||||
|
||||
<task:scheduled-tasks scheduler="scheduler">
|
||||
<task:scheduled ref="reaper" method="run" fixed-rate="10000"/>
|
||||
</task:scheduled-tasks>]]></programlisting>
|
||||
|
||||
<para>The reaper is a Runnable, and all that is happening is that the
|
||||
message group store's expire method is being called in the sample above
|
||||
once every 10 seconds. In addition to the reaper, the expiry callbacks are
|
||||
invoked when the application shuts down via a lifecycle callback in the
|
||||
<classname>CorrelatingMessageHandler</classname>.</para>
|
||||
|
||||
<para>The <classname>CorrelatingMessageHandler</classname> registers its
|
||||
own expiry callback, and this is the link with the boolean flag
|
||||
<code>send-partial-result-on-expiry</code> in the XML configuration of the
|
||||
aggregator. If the flag is set to true, then when the expiry callback is
|
||||
invoked then any unmarked messages in groups that are not yet released can
|
||||
be sent on to the downstream channel.</para>
|
||||
</section>
|
||||
|
||||
<section id="aggregator-annotations">
|
||||
<title>Configuring an Aggregator with Annotations</title>
|
||||
|
||||
<para>An aggregator configured using annotations can look like
|
||||
this.</para>
|
||||
|
||||
<programlisting language="java"><![CDATA[public class Waiter {
|
||||
...
|
||||
|
||||
@Aggregator ]]><co id="aggann" /><![CDATA[
|
||||
public Delivery aggregatingMethod(List<OrderItem> items) {
|
||||
...
|
||||
}
|
||||
|
||||
@ReleaseStrategy ]]><co id="agganncs" /><![CDATA[
|
||||
public boolean releaseChecker(List<Message<?>> messages) {
|
||||
...
|
||||
}
|
||||
|
||||
@CorrelationStrategy ]]><co id="agganncorrs" /><![CDATA[
|
||||
public String correlateBy(OrderItem item) {
|
||||
...
|
||||
}
|
||||
|
||||
}]]></programlisting>
|
||||
|
||||
<calloutlist>
|
||||
<callout arearefs="aggann">
|
||||
<para>An annotation indicating that this method shall be used as an
|
||||
aggregator. Must be specified if this class will be used as an
|
||||
aggregator.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="agganncs">
|
||||
<para id="aggann2">An annotation indicating that this method shall be
|
||||
used as the release strategy of an aggregator. If not present on any
|
||||
method, the aggregator will use the
|
||||
SequenceSizeCompletionStrategy.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="agganncorrs">
|
||||
<para id="agann3">An annotation indicating that this method shall be
|
||||
used as the correlation strategy of an aggregator. If no correlation
|
||||
strategy is indicated, the aggregator will use the
|
||||
HeaderAttributeCorrelationStrategy based on CORRELATION_ID.</para>
|
||||
</callout>
|
||||
</calloutlist>
|
||||
|
||||
<para>All of the configuration options provided by the xml element are
|
||||
also available for the @Aggregator annotation.</para>
|
||||
|
||||
<para>The aggregator can be either referenced explicitly from XML or, if
|
||||
the @MessageEndpoint is defined on the class, detected automatically
|
||||
through classpath scanning.</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="bridge">
|
||||
<title>Messaging Bridge</title>
|
||||
|
||||
<section id="bridge-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
A Messaging Bridge is a relatively trivial endpoint that simply connects two Message Channels or Channel
|
||||
Adapters. For example, you may want to connect a <interfacename>PollableChannel</interfacename> to a
|
||||
<interfacename>SubscribableChannel</interfacename> so that the subscribing endpoints do not have to worry
|
||||
about any polling configuration. Instead, the Messaging Bridge provides the polling configuration.
|
||||
</para>
|
||||
<para>
|
||||
By providing an intermediary poller between two channels, a Messaging Bridge can be used to throttle inbound
|
||||
Messages. The poller's trigger will determine the rate at which messages arrive on the second channel, and the
|
||||
poller's "maxMessagesPerPoll" property will enforce a limit on the throughput.
|
||||
</para>
|
||||
<para>
|
||||
Another valid use for a Messaging Bridge is to connect two different systems. In such a scenario, Spring
|
||||
Integration's role would be limited to making the connection between these systems and managing a poller
|
||||
if necessary. It is probably more common to have at least a <emphasis>Transformer</emphasis> between the
|
||||
two systems to translate between their formats, and in that case, the channels would be provided as the
|
||||
'input-channel' and 'output-channel' of a Transformer endpoint. If data format translation is not required,
|
||||
the Messaging Bridge may indeed be sufficient.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="bridge-namespace">
|
||||
<title>The <bridge> Element</title>
|
||||
<para>
|
||||
The <bridge> element is used to create a Messaging Bridge between two Message Channels or Channel Adapters.
|
||||
Simply provide the "input-channel" and "output-channel" attributes:
|
||||
<programlisting language="xml"><![CDATA[ <bridge input-channel="input" output-channel="output"/>]]></programlisting>
|
||||
As mentioned above, a common use case for the Messaging Bridge is to connect a
|
||||
<interfacename>PollableChannel</interfacename> to a <interfacename>SubscribableChannel</interfacename>, and when
|
||||
performing this role, the Messaging Bridge may also serve as a throttler:
|
||||
<programlisting language="xml"><![CDATA[ <bridge input-channel="pollable" output-channel="subscribable">
|
||||
<poller max-messages-per-poll="10" fixed-rate="5000"/>
|
||||
</bridge>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Connecting Channel Adapters is just as easy. Here is a simple echo example between the "stdin" and "stdout"
|
||||
adapters from Spring Integration's "stream" namespace.
|
||||
<programlisting language="xml"><![CDATA[ <stream:stdin-channel-adapter id="stdin"/>
|
||||
|
||||
<stream:stdout-channel-adapter id="stdout"/>
|
||||
|
||||
<bridge id="echo" input-channel="stdin" output-channel="stdout"/>]]></programlisting>
|
||||
Of course, the configuration would be similar for other (potentially more useful) Channel Adapter bridges, such
|
||||
as File to JMS, or Mail to File. The various Channel Adapters will be discussed in upcoming chapters.
|
||||
</para>
|
||||
<note>
|
||||
<para>If no 'output-channel' is defined on a bridge, the reply channel provided by the inbound Message will
|
||||
be used, if available. If neither output or reply channel is available, an Exception will be thrown.</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,115 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="chain">
|
||||
<title>Message Handler Chain</title>
|
||||
|
||||
<section id="chain-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
The <classname>MessageHandlerChain</classname> is an implementation of
|
||||
<interfacename>MessageHandler</interfacename> that can be configured as a single Message Endpoint while
|
||||
actually delegating to a chain of other handlers, such as Filters, Transformers, Splitters, and so on.
|
||||
This can lead to a much simpler configuration when several handlers need to be connected in a fixed, linear
|
||||
progression. For example, it is fairly common to provide a Transformer before other components. Similarly, when
|
||||
providing a <emphasis>Filter</emphasis> before some other component in a chain, you are essentially creating a
|
||||
<ulink url="http://www.eaipatterns.com/MessageSelector.html">Selective Consumer</ulink>. In either case, the
|
||||
chain only requires a single input-channel and a single output-channel as opposed to the configuration of
|
||||
channels for each individual component.
|
||||
<tip>
|
||||
Spring Integration's <emphasis>Filter</emphasis> provides a boolean property 'throwExceptionOnRejection'. When
|
||||
providing multiple Selective Consumers on the same point-to-point channel with different acceptance criteria,
|
||||
this value should be set to 'true' (the default is false) so that the dispatcher will know that the Message was
|
||||
rejected and as a result will attempt to pass the Message on to other subscribers. If the Exception were not
|
||||
thrown, then it would appear to the dispatcher as if the Message had been passed on successfully even though
|
||||
the Filter had <emphasis>dropped</emphasis> the Message to prevent further processing.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
The handler chain simplifies configuration while internally maintaining the same degree of loose coupling between
|
||||
components, and it is trivial to modify the configuration if at some point a non-linear arrangement is required.
|
||||
</para>
|
||||
<para>
|
||||
Internally, the chain will be expanded into a linear setup of the listed endpoints, separated by direct channels.
|
||||
The reply channel header will not be taken into account within the chain: only after the last handler is invoked
|
||||
will the resulting message be forwarded on to the reply channel or the chain's output channel. Because of this
|
||||
setup all handlers except the last require a <methodname>setOutputChannel</methodname> implementation. The last
|
||||
handler only needs an output channel if the outputChannel on the MessageHandlerChain is set.
|
||||
<note>
|
||||
<para>
|
||||
As with other endpoints, the output-channel is optional. If there is a reply Message at the end of the
|
||||
chain, the output-channel takes precedence, but if not available, the chain handler will check for a
|
||||
reply channel header on the inbound Message.
|
||||
</para>
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
In most cases there is no need to implement MessageHandlers yourself. The next section will focus on namespace
|
||||
support for the chain element. Most Spring Integration endpoints, like Service Activators and Transformers, are
|
||||
suitable for use within a <classname>MessageHandlerChain</classname>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="chain-namespace">
|
||||
<title>The <chain> Element</title>
|
||||
<para>
|
||||
The <chain> element provides an 'input-channel' attribute, and if the last element in the chain is capable
|
||||
of producing reply messages (optional), it also supports an 'output-channel' attribute. The sub-elements are then
|
||||
filters, transformers, splitters, and service-activators. The last element may also be a router.
|
||||
<programlisting language="xml"><![CDATA[ <chain input-channel="input" output-channel="output">
|
||||
<filter ref="someSelector" throw-exception-on-rejection="true"/>
|
||||
<header-enricher error-channel="customErrorChannel">
|
||||
<header name="foo" value="bar"/>
|
||||
</header-enricher>
|
||||
<service-activator ref="someService" method="someMethod"/>
|
||||
</chain>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The <header-enricher> element used in the above example will set a message header with name "foo" and
|
||||
value "bar" on the message. A header enricher is a specialization of Transformer that touches only header
|
||||
values. You could obtain the same result by implementing a MessageHandler that did the header modifications
|
||||
and wiring that as a bean.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Some time you need to make a nested call to another chain from within the chain and then come
|
||||
back and continue execution within the original chain.
|
||||
To accomplish this you can utilize Messaging Gateway by including light-configuration via <gateway> element.
|
||||
For example:
|
||||
<programlisting language="xml"><![CDATA[ <si:chain id="main-chain" input-channel="inputA" output-channel="inputB">
|
||||
<si:header-enricher>
|
||||
<si:header name="name" value="Many" />
|
||||
</si:header-enricher>
|
||||
<si:service-activator>
|
||||
<bean class="org.foo.SampleService" />
|
||||
</si:service-activator>
|
||||
<si:gateway request-channel="inputC"/>
|
||||
</si:chain>
|
||||
<si:chain id="nested-chain-a" input-channel="inputC">
|
||||
<si:header-enricher>
|
||||
<si:header name="name" value="Moe" />
|
||||
</si:header-enricher>
|
||||
<si:gateway request-channel="inputD"/>
|
||||
<si:service-activator>
|
||||
<bean class="org.foo.SampleService" />
|
||||
</si:service-activator>
|
||||
</si:chain>
|
||||
<si:chain id="nested-chain-b" input-channel="inputD">
|
||||
<si:header-enricher>
|
||||
<si:header name="name" value="Jack" />
|
||||
</si:header-enricher>
|
||||
<si:service-activator>
|
||||
<bean class="org.foo.SampleService" />
|
||||
</si:service-activator>
|
||||
</si:chain>]]></programlisting>
|
||||
|
||||
In the above example the <emphasis>nested-chain-a</emphasis> will be called at the end of <emphasis>main-chain</emphasis> processing by the 'gateway' element
|
||||
configured there. While in <emphasis>nested-chain-a</emphasis> a call to a <emphasis>nested-chain-b</emphasis> will be made after header enrichment and then it will
|
||||
come back to finish execution in <emphasis>nested-chain-b</emphasis> finally getting back to the <emphasis>main-chain</emphasis>.
|
||||
When light version of <gateway> element is defined in the chain SI will construct an instance <classname>SimpleMessagingGateway</classname>
|
||||
(no need to provide 'service-interface' configuration) which will take the message in its current state and will place it on the channel defined via 'request-channel' attribute.
|
||||
Upon processing <classname>Message</classname> will be returned to the gateway and continue its journey within the current chain.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,78 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="channel-adapter">
|
||||
<title>Channel Adapter</title>
|
||||
<para>
|
||||
A Channel Adapter is a Message Endpoint that enables connecting a single sender or receiver to a Message Channel.
|
||||
Spring Integration provides a number of adapters out of the box to support various transports, such as JMS, File,
|
||||
HTTP, Web Services, and Mail. Those will be discussed in upcoming chapters of this reference guide. However, this
|
||||
chapter focuses on the simple but flexible Method-invoking Channel Adapter support. There are both inbound and
|
||||
outbound adapters, and each may be configured with XML elements provided in the core namespace.
|
||||
</para>
|
||||
|
||||
<section id="channel-adapter-namespace-inbound">
|
||||
<title>The <inbound-channel-adapter> element</title>
|
||||
<para>
|
||||
An "inbound-channel-adapter" element can invoke any method on a Spring-managed Object and send a non-null return
|
||||
value to a <interfacename>MessageChannel</interfacename> after converting it to a <classname>Message</classname>.
|
||||
When the adapter's subscription is activated, a poller will attempt to receive messages from the source. The
|
||||
poller will be scheduled with the <interfacename>TaskScheduler</interfacename> according to the provided
|
||||
configuration. To configure the polling interval or cron expression for an individual channel-adapter,
|
||||
provide a 'poller' element with either an 'interval-trigger' (in milliseconds) or 'cron-trigger'
|
||||
sub-element.
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter ref="source1" method="method1" channel="channel1">
|
||||
<poller fixed-rate="5000"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<inbound-channel-adapter ref="source2" method="method2" channel="channel2">
|
||||
<poller cron="30 * 9-17 * * MON-FRI"/>
|
||||
</channel-adapter>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
If no poller is provided, then a single default poller must be registered within the context.
|
||||
See <xref linkend="endpoint-namespace"/> for more detail.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="channel-adapter-namespace-outbound">
|
||||
<title>The <outbound-channel-adapter/> element</title>
|
||||
<para>
|
||||
An "outbound-channel-adapter" element can also connect a <interfacename>MessageChannel</interfacename> to any POJO consumer
|
||||
method that should be invoked with the payload of Messages sent to that channel.
|
||||
<programlisting language="xml"><![CDATA[<outbound-channel-adapter channel="channel1" ref="target1" method="method1"/>]]></programlisting>
|
||||
If the channel being adapted is a <interfacename>PollableChannel</interfacename>, provide a poller sub-element:
|
||||
<programlisting language="xml"><![CDATA[<outbound-channel-adapter channel="channel2" ref="target2" method="method2">
|
||||
]]><emphasis><![CDATA[<poller fixed-rate="3000"/>
|
||||
]]></emphasis><![CDATA[
|
||||
</outbound-channel-adapter>
|
||||
<beans:bean id="target1" class="org.bar.Foo"/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the POJO consumer implementation can be reused
|
||||
in other <code><outbound-channel-adapter></code> definitions. However if the consumer implementation
|
||||
should be scoped to a single definition of the <code><outbound-channel-adapter></code>, you can define it as inner bean:
|
||||
<programlisting language="xml"><![CDATA[<outbound-channel-adapter channel="channel2" method="method2">
|
||||
<beans:bean class="org.bar.Foo"/>
|
||||
]]><![CDATA[
|
||||
</outbound-channel-adapter>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both the "ref" attribute and an inner handler definition in the same <code><outbound-channel-adapter></code>
|
||||
configuration is not allowed, as it creates an ambiguous condition and will result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
Any Channel Adapter can be created without a "channel" reference in which case it will implicitly create an
|
||||
instance of <classname>DirectChannel</classname>. The created channel's name will match the "id" attribute
|
||||
of the <inbound-channel-adapter/> or <outbound-channel-adapter>l; element. Therefore, if the "channel"
|
||||
is not provided, the "id" is required.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,602 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="channel">
|
||||
<title>Message Channels</title>
|
||||
<para>
|
||||
While the <interfacename>Message</interfacename> plays the crucial role of encapsulating data, it is the
|
||||
<interfacename>MessageChannel</interfacename> that decouples message producers from message consumers.
|
||||
</para>
|
||||
|
||||
<section id="channel-interfaces">
|
||||
<title>The MessageChannel Interface</title>
|
||||
<para>
|
||||
Spring Integration's top-level <interfacename>MessageChannel</interfacename> interface is defined as follows.
|
||||
<programlisting language="java"><![CDATA[public interface MessageChannel {
|
||||
|
||||
String getName();
|
||||
|
||||
boolean send(Message message);
|
||||
|
||||
boolean send(Message message, long timeout);
|
||||
}]]></programlisting>
|
||||
When sending a message, the return value will be <emphasis>true</emphasis> if the message is sent successfully.
|
||||
If the send call times out or is interrupted, then it will return <emphasis>false</emphasis>.
|
||||
</para>
|
||||
|
||||
<section id="channel-interfaces-pollablechannel">
|
||||
<title>PollableChannel</title>
|
||||
<para>
|
||||
Since Message Channels may or may not buffer Messages (as discussed in the overview), there are two
|
||||
sub-interfaces defining the buffering (pollable) and non-buffering (subscribable) channel behavior. Here is the
|
||||
definition of <interfacename>PollableChannel</interfacename>.
|
||||
<programlisting language="java">public interface PollableChannel extends MessageChannel {
|
||||
|
||||
Message<?> receive();
|
||||
|
||||
Message<?> receive(long timeout);
|
||||
|
||||
List<Message<?>> clear();
|
||||
|
||||
List<Message<?>> purge(MessageSelector selector);
|
||||
|
||||
}</programlisting>
|
||||
Similar to the send methods, when receiving a message, the return value will be <emphasis>null</emphasis> in the
|
||||
case of a timeout or interrupt.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="channel-interfaces-subscribablechannel">
|
||||
<title>SubscribableChannel</title>
|
||||
<para>
|
||||
The <interfacename>SubscribableChannel</interfacename> base interface is implemented by channels that send
|
||||
Messages directly to their subscribed <interfacename>MessageHandler</interfacename>s. Therefore, they do not
|
||||
provide receive methods for polling, but instead define methods for managing those subscribers:
|
||||
<programlisting language="java">public interface SubscribableChannel extends MessageChannel {
|
||||
|
||||
boolean subscribe(MessageHandler handler);
|
||||
|
||||
boolean unsubscribe(MessageHandler handler);
|
||||
|
||||
}</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="channel-implementations">
|
||||
<title>Message Channel Implementations</title>
|
||||
<para>
|
||||
Spring Integration provides several different Message Channel implementations. Each is briefly described in the
|
||||
sections below.
|
||||
</para>
|
||||
<section id="channel-implementations-publishsubscribechannel">
|
||||
<title>PublishSubscribeChannel</title>
|
||||
<para>
|
||||
The <classname>PublishSubscribeChannel</classname> implementation broadcasts any Message
|
||||
sent to it to all of its subscribed handlers. This is most often used for sending
|
||||
<emphasis>Event Messages</emphasis> whose primary role is notification as opposed to
|
||||
<emphasis>Document Messages</emphasis> which are generally intended to be processed by
|
||||
a single handler. Note that the <classname>PublishSubscribeChannel</classname> is
|
||||
intended for sending only. Since it broadcasts to its subscribers directly when its
|
||||
<methodname>send(Message)</methodname> method is invoked, consumers cannot poll for
|
||||
Messages (it does not implement <interfacename>PollableChannel</interfacename> and
|
||||
therefore has no <methodname>receive()</methodname> method). Instead, any subscriber
|
||||
must be a <interfacename>MessageHandler</interfacename> itself, and the subscriber's
|
||||
<methodname>handleMessage(Message)</methodname> method will be invoked in turn.
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-implementations-queuechannel">
|
||||
<title>QueueChannel</title>
|
||||
<para>
|
||||
The <classname>QueueChannel</classname> implementation wraps a queue. Unlike the
|
||||
<classname>PublishSubscribeChannel</classname>, the <classname>QueueChannel</classname> has point-to-point
|
||||
semantics. In other words, even if the channel has multiple consumers, only one of them should receive any
|
||||
Message sent to that channel. It provides a default no-argument constructor (providing an essentially unbounded
|
||||
capacity of <code>Integer.MAX_VALUE</code>) as well as a constructor that accepts the queue capacity:
|
||||
<programlisting language="java">public QueueChannel(int capacity)</programlisting>
|
||||
A channel that has not reached its capacity limit will store messages in its internal queue, and the
|
||||
<methodname>send()</methodname> method will return immediately even if no receiver is ready to handle the
|
||||
message. If the queue has reached capacity, then the sender will block until room is available. Or, if using
|
||||
the send call that accepts a timeout, it will block until either room is available or the timeout period
|
||||
elapses, whichever occurs first. Likewise, a receive call will return immediately if a message is available
|
||||
on the queue, but if the queue is empty, then a receive call may block until either a message is available
|
||||
or the timeout elapses. In either case, it is possible to force an immediate return regardless of the
|
||||
queue's state by passing a timeout value of 0. Note however, that calls to the no-arg versions of
|
||||
<methodname>send()</methodname> and <methodname>receive()</methodname> will block indefinitely.
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-implementations-prioritychannel">
|
||||
<title>PriorityChannel</title>
|
||||
<para>
|
||||
Whereas the <classname>QueueChannel</classname> enforces first-in/first-out (FIFO) ordering, the
|
||||
<classname>PriorityChannel</classname> is an alternative implementation that allows for messages
|
||||
to be ordered within the channel based upon a priority. By default the priority is determined by the
|
||||
'<literal>priority</literal>' header within each message. However, for custom priority determination
|
||||
logic, a comparator of type <classname>Comparator<Message<?>></classname> can be provided
|
||||
to the <classname>PriorityChannel</classname>'s constructor.
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-implementations-rendezvouschannel">
|
||||
<title>RendezvousChannel</title>
|
||||
<para>
|
||||
The <classname>RendezvousChannel</classname> enables a "direct-handoff" scenario where a sender will block
|
||||
until another party invokes the channel's <methodname>receive()</methodname> method or vice-versa. Internally,
|
||||
this implementation is quite similar to the <classname>QueueChannel</classname> except that it uses a
|
||||
<classname>SynchronousQueue</classname> (a zero-capacity implementation of
|
||||
<interfacename>BlockingQueue</interfacename>). This works well in situations where the sender and receiver are
|
||||
operating in different threads but simply dropping the message in a queue asynchronously is not appropriate.
|
||||
In other words, with a <classname>RendezvousChannel</classname> at least the sender knows that some receiver
|
||||
has accepted the message, whereas with a <classname>QueueChannel</classname>, the message would have been
|
||||
stored to the internal queue and potentially never received.
|
||||
</para>
|
||||
<tip>
|
||||
<para>
|
||||
Keep in mind that all of these queue-based channels are storing messages in-memory only. When persistence
|
||||
is required, you can either invoke a database operation within a handler or use Spring Integration's
|
||||
support for JMS-based Channel Adapters. The latter option allows you to take advantage of any JMS provider's
|
||||
implementation for message persistence, and it will be discussed in <xref linkend="jms"/>. However, when
|
||||
buffering in a queue is not necessary, the simplest approach is to rely upon the
|
||||
<classname>DirectChannel</classname> discussed next.
|
||||
</para>
|
||||
</tip>
|
||||
<para>
|
||||
The <classname>RendezvousChannel</classname> is also useful for implementing request-reply
|
||||
operations. The sender can create a temporary, anonymous instance of <classname>RendezvousChannel</classname>
|
||||
which it then sets as the 'replyChannel' header when building a Message. After sending that Message, the sender
|
||||
can immediately call receive (optionally providing a timeout value) in order to block while waiting for a reply
|
||||
Message. This is very similar to the implementation used internally by many of Spring Integration's
|
||||
request-reply components.
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-implementations-directchannel">
|
||||
<title>DirectChannel</title>
|
||||
<para>
|
||||
The <classname>DirectChannel</classname> has point-to-point semantics but otherwise is more similar to the
|
||||
<classname>PublishSubscribeChannel</classname> than any of the queue-based channel implementations described
|
||||
above. It implements the <interfacename>SubscribableChannel</interfacename> interface instead of the
|
||||
<interfacename>PollableChannel</interfacename> interface, so it dispatches Messages directly to a subscriber.
|
||||
As a point-to-point channel, however, it differs from the <classname>PublishSubscribeChannel</classname> in
|
||||
that it will only send each Message to a <emphasis>single</emphasis> subscribed
|
||||
<classname>MessageHandler</classname>.
|
||||
</para>
|
||||
<para>
|
||||
In addition to being the simplest point-to-point channel option, one of its most important features is that
|
||||
it enables a single thread to perform the operations on "both sides" of the channel. For example, if a handler
|
||||
is subscribed to a <classname>DirectChannel</classname>, then sending a Message to that channel will trigger
|
||||
invocation of that handler's <methodname>handleMessage(Message)</methodname> method <emphasis>directly in the
|
||||
sender's thread</emphasis>, before the send() method invocation can return.
|
||||
</para>
|
||||
<para>
|
||||
The key motivation for providing a channel implementation with this behavior is to support transactions that
|
||||
must span across the channel while still benefiting from the abstraction and loose coupling that the channel
|
||||
provides. If the send call is invoked within the scope of a transaction, then the outcome of the handler's
|
||||
invocation (e.g. updating a database record) will play a role in determining the ultimate result of that
|
||||
transaction (commit or rollback).
|
||||
<note>
|
||||
Since the <classname>DirectChannel</classname> is the simplest option and does not add any additional
|
||||
overhead that would be required for scheduling and managing the threads of a poller, it is the default
|
||||
channel type within Spring Integration. The general idea is to define the channels for an application and
|
||||
then to consider which of those need to provide buffering or to throttle input, and then modify those to
|
||||
be queue-based <interfacename>PollableChannels</interfacename>. Likewise, if a channel needs to broadcast
|
||||
messages, it should not be a <classname>DirectChannel</classname> but rather a
|
||||
<classname>PublishSubscribeChannel</classname>. Below you will see how each of these can be configured.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
The <classname>DirectChannel</classname> internally delegates to a Message Dispatcher to invoke its
|
||||
subscribed Message Handlers, and that dispatcher can have a load-balancing strategy. The load-balancer
|
||||
determines how invocations will be ordered in the case that there are multiple handlers subscribed to the
|
||||
same channel. When using the namespace support described below, the default strategy is
|
||||
"round-robin" which essentially load-balances across the handlers in rotation.
|
||||
<note>
|
||||
The "round-robin" strategy is currently the only implementation available out-of-the-box in Spring
|
||||
Integration. Other strategy implementations may be added in future versions.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
The load-balancer also works in combination with a boolean <emphasis>failover</emphasis> property.
|
||||
If the "failover" value is true (the default), then the dispatcher will fall back to any subsequent
|
||||
handlers as necessary when preceding handlers throw Exceptions. The order is determined by an optional
|
||||
order value defined on the handlers themselves or, if no such value exists, the order in which the
|
||||
handlers are subscribed.
|
||||
</para>
|
||||
<para>
|
||||
If a certain situation requires that the dispatcher always try to invoke the first handler, then
|
||||
fallback in the same fixed order sequence every time an error occurs, no load-balancing strategy should
|
||||
be provided. In other words, the dispatcher still supports the failover boolean property even when no
|
||||
load-balancing is enabled. Without load-balancing, however, the invocation of handlers will always begin
|
||||
with the first according to their order. For example, this approach works well when there is a clear
|
||||
definition of primary, secondary, tertiary, and so on. When using the namespace support, the "order"
|
||||
attribute on any endpoint will determine that order.
|
||||
</para>
|
||||
<note>
|
||||
Keep in mind that load-balancing and failover only apply when a channel has more than one
|
||||
subscribed Message Handler. When using the namespace support, this means that more than one
|
||||
endpoint shares the same channel reference in the "input-channel" attribute.
|
||||
</note>
|
||||
</section>
|
||||
<section id="executor-channel">
|
||||
<title>ExecutorChannel</title>
|
||||
<para>
|
||||
The <classname>ExecutorChannel</classname> is a point-to-point channel that supports
|
||||
the same dispatcher configuration as <classname>DirectChannel</classname> (load-balancing strategy
|
||||
and the failover boolean property). The key difference between these two dispatching channel types
|
||||
is that the <classname>ExecutorChannel</classname> delegates to an instance of
|
||||
<interfacename>TaskExecutor</interfacename> to perform the dispatch. This means that the send method
|
||||
typically will not block, but it also means that the handler invocation may not occur in the sender's
|
||||
thread. It therefore <emphasis>does not support transactions spanning the sender and receiving
|
||||
handler</emphasis>.
|
||||
<tip>
|
||||
Note that there are occasions where the sender may block. For example, when using a
|
||||
TaskExecutor with a rejection-policy that throttles back on the client (such as the
|
||||
<code>ThreadPoolExecutor.CallerRunsPolicy</code>), the sender's thread will execute
|
||||
the method directly anytime the thread pool is at its maximum capacity and the
|
||||
executor's work queue is full. Since that situation would only occur in a non-predictable
|
||||
way, that obviously cannot be relied upon for transactions.
|
||||
</tip>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-implementations-threadlocalchannel">
|
||||
<title>ThreadLocalChannel</title>
|
||||
<para>
|
||||
The final channel implementation type is <classname>ThreadLocalChannel</classname>. This channel also delegates
|
||||
to a queue internally, but the queue is bound to the current thread. That way the thread that sends to the
|
||||
channel will later be able to receive those same Messages, but no other thread would be able to access them.
|
||||
While probably the least common type of channel, this is useful for situations where
|
||||
<classname>DirectChannels</classname> are being used to enforce a single thread of operation but any reply
|
||||
Messages should be sent to a "terminal" channel. If that terminal channel is a
|
||||
<classname>ThreadLocalChannel</classname>, the original sending thread can collect its replies from it.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="channel-interceptors">
|
||||
<title>Channel Interceptors</title>
|
||||
<para>
|
||||
One of the advantages of a messaging architecture is the ability to provide common behavior and capture
|
||||
meaningful information about the messages passing through the system in a non-invasive way. Since the
|
||||
<interfacename>Messages</interfacename> are being sent to and received from
|
||||
<interfacename>MessageChannels</interfacename>, those channels provide an opportunity for intercepting
|
||||
the send and receive operations. The <interfacename>ChannelInterceptor</interfacename> strategy interface
|
||||
provides methods for each of those operations:
|
||||
<programlisting language="java"><![CDATA[public interface ChannelInterceptor {
|
||||
|
||||
Message<?> preSend(Message<?> message, MessageChannel channel);
|
||||
|
||||
void postSend(Message<?> message, MessageChannel channel, boolean sent);
|
||||
|
||||
boolean preReceive(MessageChannel channel);
|
||||
|
||||
Message<?> postReceive(Message<?> message, MessageChannel channel);
|
||||
}]]></programlisting>
|
||||
After implementing the interface, registering the interceptor with a channel is just a matter of calling:
|
||||
<programlisting language="java">channel.addInterceptor(someChannelInterceptor);</programlisting>
|
||||
The methods that return a Message instance can be used for transforming the Message or can return 'null'
|
||||
to prevent further processing (of course, any of the methods can throw a RuntimeException). Also, the
|
||||
<methodname>preReceive</methodname> method can return '<literal>false</literal>' to prevent the receive
|
||||
operation from proceeding.
|
||||
<note>
|
||||
Keep in mind that <methodname>receive()</methodname> calls are only relevant for
|
||||
<interfacename>PollableChannels</interfacename>. In fact the
|
||||
<interfacename>SubscribableChannel</interfacename> interface does not even define a
|
||||
<methodname>receive()</methodname> method. The reason for this is that when a Message is sent to a
|
||||
<interfacename>SubscribableChannel</interfacename> it will be sent directly to one or more subscribers
|
||||
depending on the type of channel (e.g. a PublishSubscribeChannel sends to all of its subscribers). Therefore,
|
||||
the <methodname>preReceive(..)</methodname> and <methodname>postReceive(..)</methodname> interceptor methods
|
||||
are only invoked when the interceptor is applied to a <interfacename>PollableChannel</interfacename>.
|
||||
</note>
|
||||
Spring Integration also provides an implementation of the
|
||||
<ulink url="http://eaipatterns.com/WireTap.html">Wire Tap</ulink> pattern.
|
||||
It is a simple interceptor that sends the Message to another channel without otherwise altering the
|
||||
existing flow. It can be very useful for debugging and monitoring. An example is shown in
|
||||
<xref linkend="channel-wiretap"/>.
|
||||
</para>
|
||||
<para>
|
||||
Because it is rarely necessary to implement all of the interceptor methods, a
|
||||
<classname>ChannelInterceptorAdapter</classname> class is also available for sub-classing. It provides no-op
|
||||
methods (the <literal>void</literal> method is empty, the <classname>Message</classname> returning methods
|
||||
return the Message as-is, and the <literal>boolean</literal> method returns <literal>true</literal>).
|
||||
Therefore, it is often easiest to extend that class and just implement the method(s) that you need as in the
|
||||
following example.
|
||||
<programlisting language="java"><![CDATA[public class CountingChannelInterceptor extends ChannelInterceptorAdapter {
|
||||
|
||||
private final AtomicInteger sendCount = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
sendCount.incrementAndGet();
|
||||
return message;
|
||||
}
|
||||
}]]></programlisting>
|
||||
<tip>
|
||||
The order of invocation for the interceptor methods depends on the type of channel. As described above,
|
||||
the queue-based channels are the only ones where the receive method is intercepted in the first place.
|
||||
Additionally, the relationship between send and receive interception depends on the timing of separate
|
||||
sender and receiver threads. For example, if a receiver is already blocked while waiting for a message
|
||||
the order could be: preSend, preReceive, postReceive, postSend. However, if a receiver polls after the
|
||||
sender has placed a message on the channel and already returned, the order would be: preSend, postSend,
|
||||
(some-time-elapses) preReceive, postReceive. The time that elapses in such a case depends on a number
|
||||
of factors and is therefore generally unpredictable (in fact, the receive may never happen!).
|
||||
Obviously, the type of queue also plays a role (e.g. rendezvous vs. priority). The bottom line is that
|
||||
you cannot rely on the order beyond the fact that preSend will precede postSend and preReceive will
|
||||
precede postReceive.
|
||||
</tip>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="channel-template">
|
||||
<title>MessagingTemplate</title>
|
||||
<para>
|
||||
As you will see when the endpoints and their various configuration options are introduced, Spring Integration
|
||||
provides a foundation for messaging components that enables non-invasive invocation of your application code
|
||||
<emphasis>from the messaging system</emphasis>. However, sometimes it is necessary to invoke the messaging system
|
||||
<emphasis>from your application code</emphasis>. For convenience when implementing such use-cases, Spring
|
||||
Integration provides a <classname>MessagingTemplate</classname> that supports a variety of operations across
|
||||
the Message Channels, including request/reply scenarios. For example, it is possible to send a request
|
||||
and wait for a reply.
|
||||
<programlisting language="java">MessagingTemplate template = new MessagingTemplate();
|
||||
|
||||
Message reply = template.sendAndReceive(new StringMessage("test"), someChannel);</programlisting>
|
||||
In that example, a temporary anonymous channel would be created internally by the template. The
|
||||
'sendTimeout' and 'receiveTimeout' properties may also be set on the template, and other exchange
|
||||
types are also supported.
|
||||
<programlisting language="java"><![CDATA[public boolean send(final Message<?> message, final MessageChannel channel) { ... }
|
||||
|
||||
public Message<?> sendAndReceive(final Message<?> request, final MessageChannel channel) { .. }
|
||||
|
||||
public Message<?> receive(final PollableChannel<?> channel) { ... }]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
A less invasive approach that allows you to invoke simple interfaces with payload and/or header
|
||||
values instead of Message instances is described in <xref linkend="gateway-proxy"/>.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="channel-configuration">
|
||||
<title>Configuring Message Channels</title>
|
||||
<para>
|
||||
To create a Message Channel instance, you can use the 'channel' element:
|
||||
<programlisting language="xml"><channel id="exampleChannel"/></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The default channel type is <emphasis>Point to Point</emphasis>. To create a
|
||||
<emphasis>Publish Subscribe</emphasis> channel, use the "publish-subscribe-channel" element:
|
||||
<programlisting language="xml"><publish-subscribe-channel id="exampleChannel"/></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To create a <ulink url="http://www.eaipatterns.com/DatatypeChannel.html">Datatype Channel</ulink> that only
|
||||
accepts messages containing a certain payload type, provide the fully-qualified class name in the
|
||||
channel element's <literal>datatype</literal> attribute:
|
||||
<programlisting language="xml"><![CDATA[<channel id="numberChannel" datatype="java.lang.Number"/>]]></programlisting>
|
||||
Note that the type check passes for any type that is <emphasis>assignable</emphasis> to the channel's
|
||||
datatype. In other words, the "numberChannel" above would accept messages whose payload is
|
||||
<classname>java.lang.Integer</classname> or <classname>java.lang.Double</classname>. Multiple types can be
|
||||
provided as a comma-delimited list:
|
||||
<programlisting language="xml"><![CDATA[<channel id="stringOrNumberChannel" datatype="java.lang.String,java.lang.Number"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
When using the "channel" element without any sub-elements, it will create a <classname>DirectChannel</classname>
|
||||
instance (a <interfacename>SubscribableChannel</interfacename>).
|
||||
</para>
|
||||
<para>
|
||||
However, you can alternatively provide a variety of "queue" sub-elements to create any of
|
||||
the pollable channel types (as described in
|
||||
<xref linkend="channel-implementations"/>). Examples of each are shown below.
|
||||
</para>
|
||||
<section id="channel-configuration-directchannel">
|
||||
<title>DirectChannel Configuration</title>
|
||||
<para>
|
||||
As mentioned above, <classname>DirectChannel</classname> is the default type.
|
||||
<programlisting language="xml"><![CDATA[<channel id="directChannel"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
A default channel will have a <emphasis>round-robin</emphasis> load-balancer and will also have
|
||||
failover enabled (See the discussion in <xref linkend="channel-implementations-directchannel"/>
|
||||
for more detail). To disable one or both of these, add a <dispatcher/> sub-element and
|
||||
configure the attributes:
|
||||
<programlisting language="xml"><![CDATA[<channel id="failFastChannel">
|
||||
<dispatcher failover="false"/>
|
||||
</channel>
|
||||
|
||||
<channel id="channelWithFixedOrderSequenceFailover">
|
||||
<dispatcher load-balancer="none"/>
|
||||
</channel>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-configuration-queuechannel">
|
||||
<title>QueueChannel Configuration</title>
|
||||
<para>
|
||||
To create a <classname>QueueChannel</classname>, use the "queue" sub-element.
|
||||
You may specify the channel's capacity:
|
||||
<programlisting language="xml"><channel id="queueChannel">
|
||||
<queue capacity="25"/>
|
||||
</channel></programlisting>
|
||||
<note>
|
||||
If you do not provide a value for the 'capacity' attribute on this <queue/> sub-element,
|
||||
the resulting queue will be unbounded. To avoid issues such as OutOfMemoryErrors, it is highly
|
||||
recommended to set an explicit value for a bounded queue.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-configuration-pubsubchannel">
|
||||
<title>PublishSubscribeChannel Configuration</title>
|
||||
<para>
|
||||
To create a <classname>PublishSubscribeChannel</classname>, use the "publish-subscribe-channel" element.
|
||||
When using this element, you can also specify the "task-executor" used for publishing
|
||||
Messages (if none is specified it simply publishes in the sender's thread):
|
||||
<programlisting language="xml"><publish-subscribe-channel id="pubsubChannel" task-executor="someExecutor"/></programlisting>
|
||||
If you are providing a <emphasis>Resequencer</emphasis> or <emphasis>Aggregator</emphasis> downstream
|
||||
from a <classname>PublishSubscribeChannel</classname>, then you can set the 'apply-sequence' property
|
||||
on the channel to <code>true</code>. That will indicate that the channel should set the sequence-size
|
||||
and sequence-number Message headers as well as the correlation id prior to passing the Messages along.
|
||||
For example, if there are 5 subscribers, the sequence-size would be set to 5, and the Messages would
|
||||
have sequence-number header values ranging from 1 to 5.
|
||||
<programlisting language="xml"><publish-subscribe-channel id="pubsubChannel" apply-sequence="true"/></programlisting>
|
||||
<note>
|
||||
The 'apply-sequence' value is <code>false</code> by default so that a Publish Subscribe Channel
|
||||
can send the exact same Message instances to multiple outbound channels. Since Spring Integration
|
||||
enforces immutability of the payload and header references, the channel creates new Message
|
||||
instances with the same payload reference but different header values when the flag is set to
|
||||
<code>true</code>.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-configuration-executorchannel">
|
||||
<title>ExecutorChannel</title>
|
||||
<para>
|
||||
To create an <classname>ExecutorChannel</classname>, add the <dispatcher> sub-element along
|
||||
with a 'task-executor' attribute. Its value can reference any <interfacename>TaskExecutor</interfacename>
|
||||
within the context. For example, this enables configuration of a thread-pool for dispatching messages
|
||||
to subscribed handlers. As mentioned above, this does break the "single-threaded" execution context
|
||||
between sender and receiver so that any active transaction context will not be shared by the invocation
|
||||
of the handler (i.e. the handler may throw an Exception, but the send invocation has already returned
|
||||
successfully).
|
||||
<programlisting language="xml"><![CDATA[<channel id="executorChannel">
|
||||
<dispatcher task-executor="someExecutor"/>
|
||||
</channel>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
The "load-balancer" and "failover" options are also both available on the dispatcher sub-element
|
||||
as described above in <xref linkend="channel-configuration-directchannel"/>. The same defaults
|
||||
apply as well. So, the channel will have a round-robin load-balancing strategy with failover
|
||||
enabled unless explicit configuration is provided for one or both of those attributes.
|
||||
<programlisting language="xml"><![CDATA[<channel id="executorChannelWithoutFailover">
|
||||
<dispatcher task-executor="someExecutor" failover="false"/>
|
||||
</channel>]]></programlisting>
|
||||
</note>
|
||||
</section>
|
||||
<section id="channel-configuration-prioritychannel">
|
||||
<title>PriorityChannel Configuration</title>
|
||||
<para>
|
||||
To create a <classname>PriorityChannel</classname>, use the "priority-queue" sub-element:
|
||||
<programlisting language="xml"><![CDATA[<channel id="priorityChannel">
|
||||
<priority-queue capacity="20"/>
|
||||
</channel>]]></programlisting>
|
||||
By default, the channel will consult the <classname>MessagePriority</classname> header of the
|
||||
message. However, a custom <interfacename>Comparator</interfacename> reference may be
|
||||
provided instead. Also, note that the <classname>PriorityChannel</classname> (like the other types)
|
||||
does support the "datatype" attribute. As with the QueueChannel, it also supports a "capacity" attribute.
|
||||
The following example demonstrates all of these:
|
||||
<programlisting language="xml"><![CDATA[<channel id="priorityChannel" datatype="example.Widget">
|
||||
<priority-queue comparator="widgetComparator"
|
||||
capacity="10"/>
|
||||
</channel>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-configuration-rendezvouschannel">
|
||||
<title>RendezvousChannel Configuration</title>
|
||||
<para>
|
||||
A <classname>RendezvousChannel</classname> is created when the queue sub-element is
|
||||
a <rendezvous-queue>. It does not provide any additional configuration options to
|
||||
those described above, and its queue does not accept any capacity value since it is a
|
||||
0-capacity direct handoff queue.
|
||||
<programlisting language="xml"><![CDATA[<channel id="rendezvousChannel"/>
|
||||
<rendezvous-queue/>
|
||||
</channel>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="channel-configuration-threadlocalchannel">
|
||||
<title>ThreadLocalChannel Configuration</title>
|
||||
<para>
|
||||
The <classname>ThreadLocalChannel</classname> does not provide any additional configuration options.
|
||||
<programlisting language="xml"><![CDATA[<thread-local-channel id="threadLocalChannel"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="channel-configuration-interceptors">
|
||||
<title>Channel Interceptor Configuration</title>
|
||||
<para>
|
||||
Message channels may also have interceptors as described in <xref linkend="channel-interceptors"/>. The
|
||||
<interceptors> sub-element can be added within <channel> (or the more specific element
|
||||
types). Provide the "ref" attribute to reference any Spring-managed object that implements the
|
||||
<interfacename>ChannelInterceptor</interfacename> interface:
|
||||
<programlisting language="xml"><![CDATA[<channel id="exampleChannel">
|
||||
]]><emphasis><![CDATA[<interceptors>
|
||||
<ref bean="trafficMonitoringInterceptor"/>
|
||||
</interceptors>]]></emphasis><![CDATA[
|
||||
</channel>]]></programlisting>
|
||||
In general, it is a good idea to define the interceptor implementations in a separate location since they
|
||||
usually provide common behavior that can be reused across multiple channels.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="global-channel-configuration-interceptors">
|
||||
<title>Global Channel Interceptor Configuration</title>
|
||||
<para>
|
||||
Channel Interceptors allow you for a clean and concise way of applying cross-cutting behavior per individual channel.
|
||||
But what if the same behavior should be applied on multiple channels, configuring the same set of interceptors for
|
||||
each channel <emphasis>would not be</emphasis> the most efficient way. The better way would be to configure interceptors globally and apply
|
||||
them on multiple channels in one shot. Spring Integration provides capabilities to configure <emphasis>Global Interceptors</emphasis>
|
||||
and apply them on multiple channels.
|
||||
Look at the example below:
|
||||
<programlisting language="xml"><![CDATA[<int:channel-interceptor pattern="input*, bar*, foo" order="3">
|
||||
<bean class="foo.barSampleInterceptor"/>
|
||||
</int:channel-interceptor>]]></programlisting>
|
||||
or
|
||||
<programlisting language="xml"><![CDATA[<int:channel-interceptor ref="myInterceptor" pattern="input*, bar*, foo" order="3"/>
|
||||
|
||||
<bean id="myInterceptor" class="foo.barSampleInterceptor"/>]]></programlisting>
|
||||
<channel-interceptor> element allows you to define a global interceptor which will be applied on all
|
||||
channels that match patterns defined via <emphasis>pattern</emphasis> attribute. In the above case the global interceptor will be applied on
|
||||
'foo' channel and all other channels that begin with 'bar' and 'input'.
|
||||
The <emphasis>order</emphasis> attribute allows you to manage the place where this interceptor will be injected.
|
||||
For example, channel 'inputChannel' could have individual interceptors configured locally (see below):
|
||||
<programlisting language="xml"><![CDATA[<int:channel id="inputChannel">
|
||||
<int:interceptors>
|
||||
<int:wire-tap channel="logger"/>
|
||||
</int:interceptors>
|
||||
</int:channel>]]></programlisting>
|
||||
The reasonable question would be how global interceptor will be injected in relation to other interceptors
|
||||
configured locally or through other global interceptor definitions? Current implementation provides
|
||||
a very simple and clever mechanism of handling this. Positive number in the <emphasis>order</emphasis> attribute will ensure interceptor injection
|
||||
after existing interceptors and negative number will ensure that such interceptors injected before.
|
||||
This means that in the above example global interceptor will be injected <emphasis>AFTER</emphasis> (since its order is greater then 0)
|
||||
'wire-tap' interceptor configured locally. If there was another global interceptor with matching <emphasis>pattern</emphasis> their
|
||||
order would be determined based on who's got the higher or lower value in <emphasis>order</emphasis> attribute.
|
||||
To inject global interceptor <emphasis>BEFORE</emphasis> the existing interceptors use negative value for the <emphasis>order</emphasis> attribute.
|
||||
</para>
|
||||
<note>
|
||||
Note that <emphasis>order</emphasis> and <emphasis>pattern</emphasis> attributes are optional. The default value for <emphasis>order</emphasis>
|
||||
will be 0 and for <emphasis>pattern</emphasis> is '*'
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="channel-wiretap">
|
||||
<title>Wire Tap</title>
|
||||
<para>
|
||||
As mentioned above, Spring Integration provides a simple <emphasis>Wire Tap</emphasis> interceptor out of
|
||||
the box. You can configure a <emphasis>Wire Tap</emphasis> on any channel within an 'interceptors' element.
|
||||
This is especially useful for debugging, and can be used in conjunction with Spring Integration's logging
|
||||
Channel Adapter as follows: <programlisting language="xml"><![CDATA[ <channel id="in">
|
||||
<interceptors>
|
||||
<wire-tap channel="logger"/>
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
<logging-channel-adapter id="logger" level="DEBUG"/>]]></programlisting>
|
||||
<tip>
|
||||
The 'logging-channel-adapter' also accepts a boolean attribute: <emphasis>'log-full-message'</emphasis>.
|
||||
That is <emphasis>false</emphasis> by default so that only the payload is logged. Setting that to
|
||||
<emphasis>true</emphasis> enables logging of all headers in addition to the payload.
|
||||
</tip>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
If namespace support is enabled, there are also two special channels defined within the context by default:
|
||||
<code>errorChannel</code> and <code>nullChannel</code>. The 'nullChannel' acts like <code>/dev/null</code>,
|
||||
simply logging any Message sent to it at DEBUG level and returning immediately. Any time you face channel
|
||||
resolution errors for a reply that you don't care about, you can set the affected component's 'output-channel'
|
||||
to reference 'nullChannel' (the name 'nullChannel' is reserved within the context). The 'errorChannel' is
|
||||
used internally for sending error messages, and it can be overridden with a custom configuration. It is
|
||||
discussed in greater detail in <xref linkend="namespace-errorhandler"/>.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,463 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<appendix id="configuration">
|
||||
<title>Configuration</title>
|
||||
<section id="configuration-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Spring Integration offers a number of configuration options. Which option you choose depends upon your particular
|
||||
needs and at what level you prefer to work. As with the Spring framework in general, it is also possible to mix
|
||||
and match the various techniques according to the particular problem at hand. For example, you may choose the
|
||||
XSD-based namespace for the majority of configuration combined with a handful of objects that are configured with
|
||||
annotations. As much as possible, the two provide consistent naming. XML elements defined by the XSD schema will
|
||||
match the names of annotations, and the attributes of those XML elements will match the names of annotation
|
||||
properties. Direct usage of the API is of course always an option, but we expect that most users will choose one
|
||||
of the higher-level options, or a combination of the namespace-based and annotation-driven configuration.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="configuration-namespace">
|
||||
<title>Namespace Support</title>
|
||||
<para>
|
||||
Spring Integration components can be configured with XML elements that map directly to the terminology and
|
||||
concepts of enterprise integration. In many cases, the element names match those of the
|
||||
<ulink url="http://www.eaipatterns.com">Enterprise Integration Patterns</ulink>.
|
||||
</para>
|
||||
<para>
|
||||
To enable Spring Integration's core namespace support within your Spring configuration files, add the following
|
||||
namespace reference and schema mapping in your top-level 'beans' element:
|
||||
<programlisting language="xml"><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
]]><emphasis>xmlns:integration="http://www.springframework.org/schema/integration"</emphasis><![CDATA[
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
]]><emphasis>http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"</emphasis>></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
You can choose any name after "xmlns:"; <emphasis>integration</emphasis> is used here for clarity, but you might
|
||||
prefer a shorter abbreviation. Of course if you are using an XML-editor or IDE support, then the availability of
|
||||
auto-completion may convince you to keep the longer name for clarity. Alternatively, you can create configuration
|
||||
files that use the Spring Integration schema as the primary namespace:
|
||||
<programlisting language="xml"><emphasis><beans:beans xmlns="http://www.springframework.org/schema/integration"</emphasis><![CDATA[
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
]]><emphasis>xmlns:beans="http://www.springframework.org/schema/beans"</emphasis><![CDATA[
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
When using this alternative, no prefix is necessary for the Spring Integration elements. On the other hand, if
|
||||
you want to define a generic Spring "bean" within the same configuration file, then a prefix would be required
|
||||
for the bean element (<beans:bean ... />). Since it is generally a good idea to modularize the
|
||||
configuration files themselves based on responsibility and/or architectural layer, you may find it appropriate to
|
||||
use the latter approach in the integration-focused configuration files, since generic beans are seldom necessary
|
||||
within those same files. For purposes of this documentation, we will assume the "integration" namespace is
|
||||
primary.
|
||||
</para>
|
||||
<para>
|
||||
Many other namespaces are provided within the Spring Integration distribution. In fact, each adapter type (JMS,
|
||||
File, etc.) that provides namespace support defines its elements within a separate schema. In order to use these
|
||||
elements, simply add the necessary namespaces with an "xmlns" entry and the corresponding "schemaLocation" mapping.
|
||||
For example, the following root element shows several of these namespace declarations:
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:jms="http://www.springframework.org/schema/integration/jms"
|
||||
xmlns:mail="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:rmi="http://www.springframework.org/schema/integration/rmi"
|
||||
xmlns:ws="http://www.springframework.org/schema/integration/ws"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/file
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jms
|
||||
http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/rmi
|
||||
http://www.springframework.org/schema/integration/rmi/spring-integration-rmi-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/ws
|
||||
http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.0.xsd">
|
||||
...
|
||||
</beans>]]></programlisting>
|
||||
The reference manual provides specific examples of the various elements in their corresponding chapters. Here, the
|
||||
main thing to recognize is the consistency of the naming for each namespace URI and schema location.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="namespace-taskscheduler">
|
||||
<title>Configuring the Task Scheduler</title>
|
||||
<para>
|
||||
In Spring Integration, the ApplicationContext plays the central role of a Message Bus, and there are only a
|
||||
couple configuration options to be aware of. First, you may want to control the central TaskScheduler instance.
|
||||
You can do so by providing a single bean with the name "taskScheduler". This is also defined as a constant:
|
||||
<programlisting><![CDATA[ IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME ]]></programlisting>
|
||||
By default Spring Integration uses the <classname>SimpleTaskScheduler</classname> implementation. That in turn
|
||||
just delegates to any instance of Spring's <interfacename>TaskExecutor</interfacename> abstraction. Therefore,
|
||||
it's rather trivial to supply your own configuration. The "taskScheduler" bean is then responsible for managing
|
||||
all pollers. The TaskScheduler will startup automatically by default. If you provide your own instance of
|
||||
SimpleTaskScheduler however, you can set the 'autoStartup' property to <emphasis>false</emphasis> instead.
|
||||
</para>
|
||||
<para>
|
||||
When Polling Consumers provide an explicit task-executor reference in their configuration, the invocation of
|
||||
the handler methods will happen within that executor's thread pool and not the main scheduler pool. However,
|
||||
when no task-executor is provided for an endpoint's poller, it will be invoked by one of the main scheduler's
|
||||
threads.
|
||||
<note>
|
||||
An endpoint is a <emphasis>Polling Consumer</emphasis> if its input channel is one of the queue-based
|
||||
(i.e. pollable) channels. On the other hand, <emphasis>Event Driven Consumers</emphasis> are those whose
|
||||
input channels have dispatchers instead of queues (i.e. they are subscribable). Such endpoints have no
|
||||
poller configuration since their handlers will be invoked directly.
|
||||
</note>
|
||||
<para>
|
||||
The next section will describe what happens if Exceptions occur within the asynchronous invocations.
|
||||
</para>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="namespace-errorhandler">
|
||||
<title>Error Handling</title>
|
||||
<para>
|
||||
As described in the overview at the very beginning of this manual, one of the main motivations behind a
|
||||
Message-oriented framework like Spring Integration is to promote loose-coupling between components. The
|
||||
Message Channel plays an important role in that producers and consumers do not have to know about each
|
||||
other. However, the advantages also have some drawbacks. Some things become more complicated in a very
|
||||
loosely coupled environment, and one example is error handling.
|
||||
</para>
|
||||
<para>
|
||||
When sending a Message to a channel, the component that ultimately handles that Message may or may not
|
||||
be operating within the same thread as the sender. If using a simple default DirectChannel (with the
|
||||
<channel> element that has no <queue> sub-element and no 'task-executor' attribute), the
|
||||
Message-handling will occur in the same thread as the Message-sending. In that case, if an Exception
|
||||
is thrown, it can be caught by the sender (or it may propagate past the sender if it is an uncaught
|
||||
RuntimeException). So far, everything is fine. This is the same behavior as an Exception-throwing
|
||||
operation in a normal call stack. However, when adding the asynchronous aspect, things become much
|
||||
more complicated. For instance, if the 'channel' element <emphasis>does</emphasis> provide a 'queue'
|
||||
sub-element, then the component that handles the Message <emphasis>will</emphasis> be operating in a
|
||||
different thread than the sender. The sender may have dropped the Message into the channel and moved
|
||||
on to other things. There is no way for the Exception to be thrown directly back to that sender using
|
||||
standard Exception throwing techniques. Instead, to handle errors for asynchronous processes requires
|
||||
an asynchronous error-handling mechanism as well.
|
||||
</para>
|
||||
<para>
|
||||
Spring Integration supports error handling for its components by publishing errors to a Message Channel.
|
||||
Specifically, the Exception will become the payload of a Spring Integration Message. That Message will
|
||||
then be sent to a Message Channel that is resolved in a way that is similar to the 'replyChannel'
|
||||
resolution. First, if the request Message being handled at the time the Exception occurred contains
|
||||
an 'errorChannel' header (the header name is defined in the constant: MessageHeaders.ERROR_CHANNEL),
|
||||
the ErrorMessage will be sent to that channel. Otherwise, the error handler will send to a "global"
|
||||
channel whose bean name is "errorChannel" (this is also defined as a constant:
|
||||
IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME).
|
||||
</para>
|
||||
<para>
|
||||
Whenever relying on Spring Integration's XML namespace support, a default "errorChannel" bean will be
|
||||
created behind the scenes. However, you can just as easily define your own if you want to control the
|
||||
settings.
|
||||
<programlisting language="xml"><![CDATA[ <channel id="errorChannel">
|
||||
<queue capacity="500"/>
|
||||
</channel>]]></programlisting>
|
||||
<note>
|
||||
The default "errorChannel" is a PublishSubscribeChannel.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
The most important thing to understand here is that the messaging-based error handling will only apply
|
||||
to Exceptions that are thrown by a Spring Integration task that is executing within a TaskExecutor.
|
||||
This does <emphasis>not</emphasis> apply to Exceptions thrown by a handler that is operating within
|
||||
the same thread as the sender (e.g. through a DirectChannel as described above).
|
||||
</para>
|
||||
<note>
|
||||
When Exceptions occur in a scheduled poller task's execution, those exceptions will be wrapped in
|
||||
<classname>ErrorMessages</classname> and sent to the 'errorChannel' as well.
|
||||
</note>
|
||||
<para>
|
||||
To enable global error handling, simply register a handler on that channel. For example, you can configure
|
||||
Spring Integration's <classname>ErrorMessageExceptionTypeRouter</classname> as the handler of an endpoint
|
||||
that is subscribed to the 'errorChannel'. That router can then spread the error messages across multiple
|
||||
channels based on <classname>Exception</classname> type.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="annotations">
|
||||
<title>Annotation Support</title>
|
||||
<para>
|
||||
In addition to the XML namespace support for configuring Message Endpoints, it is also possible to use
|
||||
annotations. First, Spring Integration provides the class-level <interfacename>@MessageEndpoint</interfacename>
|
||||
as a <emphasis>stereotype</emphasis> annotation meaning that is itself annotated with Spring's @Component
|
||||
annotation and therefore is recognized automatically as a bean definition when using Spring component-scanning.
|
||||
</para>
|
||||
<para>
|
||||
Even more importantly are the various Method-level annotations that indicate the annotated method is capable of
|
||||
handling a message. The following example demonstrates both:
|
||||
<programlisting language="java">@MessageEndpoint
|
||||
public class FooService {
|
||||
|
||||
@ServiceActivator
|
||||
public void processMessage(Message message) {
|
||||
...
|
||||
}
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Exactly what it means for the method to "handle" the Message depends on the particular annotation. The following
|
||||
are available with Spring Integration, and the behavior of each is described in its own chapter or section within
|
||||
this reference: @Transformer, @Router, @Splitter, @Aggregator, @ServiceActivator, and @ChannelAdapter.
|
||||
</para>
|
||||
<note>
|
||||
The @MessageEndpoint is not required if using XML configuration in combination with annotations. If you want to
|
||||
configure a POJO reference from the "ref" attribute of a <service-activator/> element, it is sufficient to
|
||||
provide the method-level annotations. In that case, the annotation prevents ambiguity even when no "method"
|
||||
attribute exists on the <service-activator/> element.
|
||||
</note>
|
||||
<para>
|
||||
In most cases, the annotated handler method should not require the <classname>Message</classname> type as its
|
||||
parameter. Instead, the method parameter type can match the message's payload type.
|
||||
<programlisting language="java">public class FooService {
|
||||
|
||||
@ServiceActivator
|
||||
public void bar(<emphasis>Foo foo</emphasis>) {
|
||||
...
|
||||
}
|
||||
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
When the method parameter should be mapped from a value in the <classname>MessageHeaders</classname>, another
|
||||
option is to use the parameter-level <interfacename>@Header</interfacename> annotation. In general, methods
|
||||
annotated with the Spring Integration annotations can either accept the <classname>Message</classname> itself, the
|
||||
message payload, or a header value (with @Header) as the parameter. In fact, the method can accept a combination,
|
||||
such as:
|
||||
<programlisting language="java">public class FooService {
|
||||
|
||||
@ServiceActivator
|
||||
public void bar(String payload, @Header("x") int valueX, @Header("y") int valueY) {
|
||||
...
|
||||
}
|
||||
|
||||
}</programlisting>
|
||||
There is also a @Headers annotation that provides all of the Message headers as a Map:
|
||||
<programlisting language="java">public class FooService {
|
||||
|
||||
@ServiceActivator
|
||||
public void bar(String payload, @Headers Map<String, Object> headerMap) {
|
||||
...
|
||||
}
|
||||
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
For several of these annotations, when a Message-handling method returns a non-null value, the endpoint will
|
||||
attempt to send a reply. This is consistent across both configuration options (namespace and annotations) in
|
||||
that such an endpoint's output channel will be used if available, and the REPLY_CHANNEL message header value
|
||||
will be used as a fallback.
|
||||
</para>
|
||||
<tip>
|
||||
The combination of output channels on endpoints and the reply channel message header enables a pipeline approach
|
||||
where multiple components have an output channel, and the final component simply allows the reply message to be
|
||||
forwarded to the reply channel as specified in the original request message. In other words, the final component
|
||||
depends on the information provided by the original sender and can dynamically support any number of clients as a
|
||||
result. This is an example of <ulink url="http://eaipatterns.com/ReturnAddress.html">Return Address</ulink>.
|
||||
</tip>
|
||||
<para>
|
||||
In addition to the examples shown here, these annotations also support inputChannel and outputChannel properties.
|
||||
<programlisting language="java">public class FooService {
|
||||
|
||||
@ServiceActivator(inputChannel="input", outputChannel="output")
|
||||
public void bar(String payload, @Headers Map<String, Object> headerMap) {
|
||||
...
|
||||
}
|
||||
|
||||
}</programlisting>
|
||||
That provides a pure annotation-driven alternative to the XML configuration. However, it is generally recommended
|
||||
to use XML for the endpoints, since it is easier to keep track of the overall configuration in a single, external
|
||||
location (and besides the namespace-based XML configuration is not very verbose). If you do prefer to provide
|
||||
channels with the annotations however, you just need to enable a SI Annotations BeanPostProcessor. The following element should
|
||||
be added: <programlisting language="xml"><![CDATA[ <int:annotation-config/> ]]></programlisting>
|
||||
<note>
|
||||
When configuring the "inputChannel" and "outputChannel" with annotations, the "inputChannel"
|
||||
<emphasis>must</emphasis> be a reference to a <interfacename>SubscribableChannel</interfacename> instance.
|
||||
Otherwise, it would be necessary to also provide the full poller configuration via annotations, and those
|
||||
settings (e.g. the trigger for scheduling the poller) should be externalized rather than hard-coded within
|
||||
an annotation. If the input channel that you want to receive Messages from is indeed a
|
||||
<interfacename>PollableChannel</interfacename> instance, one option to consider is the Messaging Bridge.
|
||||
Spring Integration's "bridge" element can be used to connect a PollableChannel directly to a
|
||||
SubscribableChannel. Then, the polling metadata is externally configured, but the annotation option is
|
||||
still available. For more detail see <xref linkend="bridge"/>.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="message-mapping-rules">
|
||||
<title>Message Mapping rules and conventions</title>
|
||||
<para>Spring Integration implements a flexible facility to map Messages to Methods and their arguments without
|
||||
providing extra configuration by relying on some default rules as well as defining certain conventions.
|
||||
</para>
|
||||
<section id="sample-scenarios">
|
||||
<title>Simple Scenarios</title>
|
||||
|
||||
<para>
|
||||
<emphasis>Single un-annotated parameter (object or primitive) which is not a Map/Properties with non-void return type;</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public String foo(Object o);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>Input parameter is Message Payload. If parameter type is not compatible with Message Payload an
|
||||
attempt will be made to convert it using Conversion Service provided by Spring 3.0. The return value
|
||||
will be incorporated as a Payload of the returned Message</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Single un-annotated parameter (object or primitive) which is not a Map/Properties with Message return type;</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public Message foo(Object o);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>Input parameter is Message Payload. If parameter type is not compatible with Message Payload an attempt
|
||||
will be made to convert it using Conversion Service provided by Spring 3.0. The return value is a newly constructed
|
||||
Message that will be sent to the next destination.</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Single parameter which is a Message or its subclass with arbitrary object/primitive return type; </emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public int foo(Message msg);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>Input parameter is Message itself. The return value will become a payload of the
|
||||
Message that will be sent to the next destination.</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Single parameter which is a Message or its subclass with Message or its subclass as a return type;</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public Message foo(Message msg);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>Input parameter is Message itself. The return value is a newly constructed Message that will be sent to the next destination.</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Single parameter which is of type Map or Properties with Message as a return type;</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public Message foo(Map m);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>This one is a bit interesting. Although at first it might seem like an easy mapping straight to Message Headers,
|
||||
the preference is always given to a Message Payload. This means that if Message Payload is of type Map, this input argument will
|
||||
represent Message Payload. However if Message Payload is not of type Map, then no conversion via Conversion Service will be
|
||||
attempted and the input argument will be mapped to Message Headers.</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Two parameters where one of them is arbitrary non-Map/Properties type object/primitive and another is Map/Properties type object (regardless of the return)</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public Message foo(Map h, <T> t);</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>This combination contains two input parameters where one of them is of type Map. Naturally the non-Map parameters (regardless of the order) will
|
||||
be mapped to a Message Payload and the Map/Properties (regardless of the order) will be mapped to Message Headers giving you a nice POJO way
|
||||
of interacting with Message structure.</para>
|
||||
|
||||
<para>
|
||||
<emphasis>No parameters (regardless of the return)</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public String foo();</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>This Message Handler method will be invoked based on the Message sent to the input channel this handler is hooked up to,
|
||||
however no Message data will be mapped, thus making Message act as event/trigger to invoke such handlerThe output will be
|
||||
mapped according to the rules above</para>
|
||||
|
||||
<para>
|
||||
<emphasis>No parameters, void return</emphasis>
|
||||
</para>
|
||||
<programlisting language="java">public void foo();</programlisting>
|
||||
<para>Details:</para>
|
||||
<para>Same as above, but no output </para>
|
||||
|
||||
<para>
|
||||
<emphasis>Annotation based mappings</emphasis>
|
||||
</para>
|
||||
<para>Annotation based mapping is the safest and least ambiguous approach to map Messages to Methods. There wil be many pointers to annotation
|
||||
based mapping throughout this manual, however here are couple of examples:
|
||||
</para>
|
||||
|
||||
<programlisting language="java">public String foo(@Payload String s, @Header("foo") String b) </programlisting>
|
||||
<para>Very simple and explicite way of mapping Messages to method. As you'll see later on without annotation this signature
|
||||
would result in the ambiguous condition, however by explicitly mapping first argument to a Message Payload and second argument to
|
||||
a value of the 'foo' Message Header we have avoided ambiguity.</para>
|
||||
|
||||
<programlisting language="java">public String foo(@Payload String s, @RequestParam("foo") String b) </programlisting>
|
||||
<para>Looks almost identical to the previous example, however @RequestMapping or any other non-SI mapping annotation
|
||||
is irrelevant and therefore will be ignored leaving the second parameter unmapped. And although the second parameters could
|
||||
easily be mapped to a Payload, there can only be one Payload, therefore this method becomes ambiguous. </para>
|
||||
|
||||
<programlisting language="java">public String foo(String s, @Header("foo") String b) </programlisting>
|
||||
<para>The same as above. The only difference is that the first argument will be mapped to Message Payload implicitly.</para>
|
||||
|
||||
<programlisting language="java">public String foo(@Headers Map m, @Header("foo")Map f, @Header("bar") String bar)</programlisting>
|
||||
<para>Yet another signature that would definitely be treated as ambiguous because it has more then 2 arguments,
|
||||
plus two of them are Maps, however with annotation-based mapping ambiguity is easily avoided. In this example
|
||||
the first argument is mapped to all the Message Headers, while second and third argument map to the values of Message Headers 'foo' and 'bar'.</para>
|
||||
</section>
|
||||
|
||||
<section id="complex-scenarios">
|
||||
<title>Complex Scenarios</title>
|
||||
|
||||
<para><emphasis>Multiple parameters:</emphasis> </para>
|
||||
<para>Multiple parameters could create a lot of ambiguity with regards to determining the appropriate mappings. The general advice is to annotate your method parameters with @Payload and/or @Header/@Headers
|
||||
Below are some of the examples of ambiguous conditions which result in exception being raised.
|
||||
</para>
|
||||
<programlisting language="java">public String foo(String s, int i)</programlisting>
|
||||
<para> - the two parameters are equal in weight, therefore no way to determine which one is a payload and what to do with another.</para>
|
||||
|
||||
<programlisting language="java">public String foo(String s, Map m, String b) </programlisting>
|
||||
<para> - almost the same as above. Although Map could be easily mapped to Message Headers, there is no way to determine what to do with two Strings.</para>
|
||||
|
||||
<programlisting language="java">public String foo(Map m, Map f)</programlisting>
|
||||
<para> - although one might argue that one Map could be mapped to Message Payload and another one to Message Headers, it would be unreasonable to rely on the order (e.g., first is Payload, second Headers)</para>
|
||||
|
||||
<para>
|
||||
<tip>Basically any method signature with more then one method argument which is not (Map, <T>) and those parameters are not annotated will result in the ambiguous condition thus triggering an exception.</tip>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Multiple methods:</emphasis>
|
||||
</para>
|
||||
<para>Message Handlers with multiple methods are mapped based on the same rules that are described above, however some scenarios might still look confusing.</para>
|
||||
|
||||
<para><emphasis>Multiple methods (same or different name) with legal (mappable) signatures:</emphasis> </para>
|
||||
|
||||
<programlisting language="java">public class Foo{
|
||||
public String foo(String str, Map m);
|
||||
|
||||
public String foo(Map m)
|
||||
}</programlisting>
|
||||
<para>As you can see, the Message could be mapped to either method. The first method would be invoked where Message Payload
|
||||
could be mapped to 'str' and Message Headers could be mapped to 'm'. The second method could easily also be a candidate where
|
||||
only Message Headers are mapped to 'm'. To make meters worse both methods have the same name which at first might look very
|
||||
ambiguous considering the following configuration:</para>
|
||||
<programlisting language="xml"><![CDATA[<si:service-activator input-channel="input" output-channel="output" method="foo">
|
||||
<bean class="org.bar.Foo"/>
|
||||
</si:service-activator>]]></programlisting>
|
||||
<para>At this point it would be important to understand Spring Integration mapping Conventions where at the very core,
|
||||
mappings are based on Payload first and everything else next. In other words the method whose argument could be mapped
|
||||
to a Payload will take precedence over all other methods.</para>
|
||||
|
||||
<para>On the other hand let's look at slightly different example:</para>
|
||||
<programlisting language="java">public class Foo{
|
||||
public String foo(String str, Map m);
|
||||
|
||||
public String foo(String str)
|
||||
}</programlisting>
|
||||
|
||||
<para>If you look at it you can probably see a truly an ambiguous condition. In this example since both methods have signatures that
|
||||
could be mapped to a Message Payload. They also have the same name. Such handler will trigger an exception.
|
||||
However if method names were different you could influence the mapping with 'method' attribute (see below):</para>
|
||||
<programlisting language="java">public class Foo{
|
||||
public String foo(String str, Map m);
|
||||
|
||||
public String bar(String str)
|
||||
}</programlisting>
|
||||
<programlisting language="xml"><![CDATA[<si:service-activator input-channel="input" output-channel="output" method="bar">
|
||||
<bean class="org.bar.Foo"/>
|
||||
</si:service-activator>]]></programlisting>
|
||||
|
||||
<para>Now there is no ambiguity since the configuration explicitly maps to 'bar' method which has no name conflicts.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
</appendix>
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="delayer">
|
||||
<title>Delayer</title>
|
||||
|
||||
<section id="delayer-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
A Delayer is a simple endpoint that allows a Message flow to be delayed by a certain interval. When
|
||||
a Message is delayed, the original sender will not block. Instead, the delayed Messages will be
|
||||
scheduled with an instance of <interfacename>java.util.concurrent.ScheduledExecutorService</interfacename>
|
||||
to be sent to the output channel after the delay has passed. This approach is scalable even for
|
||||
rather long delays, since it does not result in a large number of blocked sender Threads. On the
|
||||
contrary, in the typical case a thread pool will be used for the actual execution of releasing the
|
||||
Messages. Below you will find several examples of configuring a Delayer.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="delayer-namespace">
|
||||
<title>The <delayer> Element</title>
|
||||
<para>
|
||||
The <delayer> element is used to delay the Message flow between two Message Channels.
|
||||
As with the other endpoints, you can provide the "input-channel" and "output-channel" attributes,
|
||||
but the delayer also requires at least the 'default-delay' attribute with the number of milliseconds
|
||||
that each Message should be delayed.
|
||||
<programlisting language="xml"><![CDATA[ <delayer input-channel="input" default-delay="3000" output-channel="output"/>]]></programlisting>
|
||||
If you need per-Message determination of the delay, then you can also provide the name of a header
|
||||
within the 'delay-header-name' attribute:
|
||||
<programlisting language="xml"><![CDATA[ <delayer input-channel="input" output-channel="output"
|
||||
default-delay="3000" delay-header-name="delay"/>]]></programlisting>
|
||||
In the example above the 3 second delay would only apply in the case that the header value is
|
||||
not present for a given inbound Message. If you only want to apply a delay to Messages that have
|
||||
an explicit header value, then you can set the 'default-delay' to 0. For any Message that has a
|
||||
delay of 0 (or less), the Message will be sent directly. In fact, if there is not a positive delay
|
||||
value for a Message, it will be sent to the output channel on the calling Thread.
|
||||
<tip>
|
||||
The delay handler actually supports header values that represent an interval in milliseconds (any
|
||||
Object whose <methodname>toString()</methodname> method produces a value that can be parsed into a
|
||||
Long) as well as <classname>java.util.Date</classname> instances representing an absolute time.
|
||||
In the former case, the milliseconds will be counted from the current time (e.g. a value of 5000
|
||||
would delay the Message for at least 5 seconds from the time it is received by the Delayer). In
|
||||
the latter case, with an actual Date instance, the Message will not be released until that Date
|
||||
occurs. In either case, a value that equates to a non-positive delay, or a Date in the past, will
|
||||
not result in any delay. Instead, it will be sent directly to the output channel in the original
|
||||
sender's Thread.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
The delayer delegates to an instance of Spring's <interfacename>TaskScheduler</interfacename> abstraction.
|
||||
The default scheduler is a <classname>ThreadPoolTaskScheduler</classname> instance with a pool size of 1.
|
||||
If you want to delegate to a different scheduler, you can provide a reference through the delayer element's
|
||||
'scheduler' attribute:
|
||||
<programlisting language="xml"><![CDATA[ <delayer input-channel="input" output-channel="output"
|
||||
default-delay="0" delay-header-name="delay"
|
||||
scheduler="exampleTaskScheduler"/>
|
||||
|
||||
<task:scheduler id="exampleTaskScheduler" pool-size="3"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,350 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="endpoint">
|
||||
<title>Message Endpoints</title>
|
||||
<para>
|
||||
The first part of this chapter covers some background theory and reveals quite a bit about the underlying API
|
||||
that drives Spring Integration's various messaging components. This information can be helpful if you want to
|
||||
really understand what's going on behind the scenes. However, if you want to get up and running with the
|
||||
simplified namespace-based configuration of the various elements, feel free to skip ahead to
|
||||
<xref linkend="endpoint-namespace"/> for now.
|
||||
</para>
|
||||
<para>
|
||||
As mentioned in the overview, Message Endpoints are responsible for connecting the various messaging components to
|
||||
channels. Over the next several chapters, you will see a number of different components that consume Messages. Some
|
||||
of these are also capable of sending reply Messages. Sending Messages is quite straightforward. As shown above in
|
||||
<xref linkend="channel"/>, it's easy to <emphasis>send</emphasis> a Message to a Message Channel. However,
|
||||
receiving is a bit more complicated. The main reason is that there are two types of consumers:
|
||||
<ulink url="http://www.eaipatterns.com/PollingConsumer.html">Polling Consumers</ulink> and
|
||||
<ulink url="http://www.eaipatterns.com/EventDrivenConsumer.html">Event Driven Consumers</ulink>.
|
||||
</para>
|
||||
<para>
|
||||
Of the two, Event Driven Consumers are much simpler. Without any need to manage and schedule a separate poller
|
||||
thread, they are essentially just listeners with a callback method. When connecting to one of Spring Integration's
|
||||
subscribable Message Channels, this simple option works great. However, when connecting to a buffering, pollable
|
||||
Message Channel, some component has to schedule and manage the polling thread(s). Spring Integration provides
|
||||
two different endpoint implementations to accommodate these two types of consumers. Therefore, the consumers
|
||||
themselves can simply implement the callback interface. When polling is required, the endpoint acts as a
|
||||
"container" for the consumer instance. The benefit is similar to that of using a container for hosting
|
||||
Message Driven Beans, but since these consumers are simply Spring-managed Objects running within an
|
||||
ApplicationContext, it more closely resembles Spring's own MessageListener containers.
|
||||
</para>
|
||||
|
||||
<section id="endpoint-handler">
|
||||
<title>Message Handler</title>
|
||||
<para>
|
||||
Spring Integration's <interfacename>MessageHandler</interfacename> interface is implemented by many of the
|
||||
components within the framework. In other words, this is not part of the public API, and a developer would not
|
||||
typically implement <interfacename>MessageHandler</interfacename> directly. Nevertheless, it is used by a Message
|
||||
Consumer for actually handling the consumed Messages, and so being aware of this strategy interface does help in
|
||||
terms of understanding the overall role of a consumer. The interface is defined as follows:
|
||||
<programlisting language="java">public interface MessageHandler {
|
||||
|
||||
void handleMessage(Message<?> message);
|
||||
|
||||
}</programlisting>
|
||||
Despite its simplicity, this provides the foundation for most of the components that will be covered in the
|
||||
following chapters (Routers, Transformers, Splitters, Aggregators, Service Activators, etc). Those components
|
||||
each perform very different functionality with the Messages they handle, but the requirements for actually
|
||||
receiving a Message are the same, and the choice between polling and event-driven behavior is also the same.
|
||||
Spring Integration provides two endpoint implementations that "host" these callback-based handlers and allow
|
||||
them to be connected to Message Channels.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="endpoint-eventdrivenconsumer">
|
||||
<title>Event Driven Consumer</title>
|
||||
<para>
|
||||
Because it is the simpler of the two, we will cover the Event Driven Consumer endpoint first. You may recall that
|
||||
the <interfacename>SubscribableChannel</interfacename> interface provides a <methodname>subscribe()</methodname>
|
||||
method and that the method accepts a <interfacename>MessageHandler</interfacename> parameter (as shown in
|
||||
<xref linkend="channel-interfaces-subscribablechannel"/>):
|
||||
<programlisting language="java">
|
||||
subscribableChannel.subscribe(messageHandler);
|
||||
</programlisting>
|
||||
Since a handler that is subscribed to a channel does not have to actively poll that channel, this is an
|
||||
Event Driven Consumer, and the implementation provided by Spring Integration accepts a
|
||||
a <interfacename>SubscribableChannel</interfacename> and a <interfacename>MessageHandler</interfacename>:
|
||||
<programlisting language="java">SubscribableChannel channel = (SubscribableChannel) context.getBean("subscribableChannel");
|
||||
|
||||
EventDrivenConsumer consumer = new EventDrivenConsumer(channel, exampleHandler);</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="endpoint-pollingconsumer">
|
||||
<title>Polling Consumer</title>
|
||||
<para>
|
||||
Spring Integration also provides a <classname>PollingConsumer</classname>, and it can be instantiated in
|
||||
the same way except that the channel must implement <interfacename>PollableChannel</interfacename>:
|
||||
<programlisting language="java">PollableChannel channel = (PollableChannel) context.getBean("pollableChannel");
|
||||
|
||||
PollingConsumer consumer = new PollingConsumer(channel, exampleHandler);</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
There are many other configuration options for the Polling Consumer. For example, the trigger is a required property:
|
||||
<programlisting language="java">
|
||||
PollingConsumer consumer = new PollingConsumer(channel, handler);
|
||||
|
||||
consumer.setTrigger(new IntervalTrigger(30, TimeUnit.SECONDS));</programlisting>
|
||||
Spring Integration currently provides two implementations of the <interfacename>Trigger</interfacename>
|
||||
interface: <classname>IntervalTrigger</classname> and <classname>CronTrigger</classname>. The
|
||||
<classname>IntervalTrigger</classname> is typically defined with a simple interval (in milliseconds), but
|
||||
also supports an 'initialDelay' property and a boolean 'fixedRate' property (the default is false, i.e.
|
||||
fixed delay):
|
||||
<programlisting language="java">IntervalTrigger trigger = new IntervalTrigger(1000);
|
||||
trigger.setInitialDelay(5000);
|
||||
trigger.setFixedRate(true);</programlisting>
|
||||
The <classname>CronTrigger</classname> simply requires a valid cron expression (see the Javadoc for details):
|
||||
<programlisting language="java">CronTrigger trigger = new CronTrigger("*/10 * * * * MON-FRI");</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In addition to the trigger, several other polling-related configuration properties may be specified:
|
||||
<programlisting language="java">
|
||||
PollingConsumer consumer = new PollingConsumer(channel, handler);
|
||||
|
||||
consumer.setMaxMessagesPerPoll(10);
|
||||
|
||||
consumer.setReceiveTimeout(5000);</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The 'maxMessagesPerPoll' property specifies the maximum number of messages to receive within a given poll
|
||||
operation. This means that the poller will continue calling receive() <emphasis>without waiting</emphasis>
|
||||
until either <code>null</code> is returned or that max is reached. For example, if a poller has a 10 second
|
||||
interval trigger and a 'maxMessagesPerPoll' setting of 25, and it is polling a channel that has 100 messages
|
||||
in its queue, all 100 messages can be retrieved within 40 seconds. It grabs 25, waits 10 seconds, grabs the
|
||||
next 25, and so on.
|
||||
</para>
|
||||
<para>
|
||||
The 'receiveTimeout' property specifies the amount of time the poller should wait if no messages are
|
||||
available when it invokes the receive operation. For example, consider two options that seem similar on
|
||||
the surface but are actually quite different: the first has an interval trigger of 5 seconds and a receive
|
||||
timeout of 50 milliseconds while the second has an interval trigger of 50 milliseconds and a receive timeout
|
||||
of 5 seconds. The first one may receive a message up to 4950 milliseconds later than it arrived on the channel
|
||||
(if that message arrived immediately after one of its poll calls returned). On the other hand, the second
|
||||
configuration will never miss a message by more than 50 milliseconds. The difference is that the second
|
||||
option requires a thread to wait, but as a result it is able to respond much more quickly to arriving messages.
|
||||
This technique, known as "long polling", can be used to emulate event-driven behavior on a polled source.
|
||||
</para>
|
||||
<para>
|
||||
A Polling Consumer may also delegate to a Spring <interfacename>TaskExecutor</interfacename>, and it can
|
||||
be configured to participate in Spring-managed transactions. The following example shows the configuration of both:
|
||||
<programlisting language="java">
|
||||
PollingConsumer consumer = new PollingConsumer(channel, handler);
|
||||
|
||||
TaskExecutor taskExecutor = (TaskExecutor) context.getBean("exampleExecutor");
|
||||
consumer.setTaskExecutor(taskExecutor);
|
||||
|
||||
PlatformTransactionManager txManager = (PlatformTransationManager) context.getBean("exampleTxManager");
|
||||
consumer.setTransactionManager(txManager);</programlisting>
|
||||
The examples above show dependency lookups, but keep in mind that these consumers will most often be configured
|
||||
as Spring <emphasis>bean definitions</emphasis>. In fact, Spring Integration also provides a
|
||||
<interfacename>FactoryBean</interfacename> that creates the appropriate consumer type based on the type of
|
||||
channel, and there is full XML namespace support to even further hide those details. The namespace-based
|
||||
configuration will be featured as each component type is introduced.
|
||||
<note>
|
||||
Many of the <interfacename>MessageHandler</interfacename> implementations are also capable of generating reply
|
||||
Messages. As mentioned above, sending Messages is trivial when compared to the Message reception. Nevertheless,
|
||||
<emphasis>when</emphasis> and <emphasis>how many</emphasis> reply Messages are sent depends on the handler
|
||||
type. For example, an <emphasis>Aggregator</emphasis> waits for a number of Messages to arrive and is often
|
||||
configured as a downstream consumer for a <emphasis>Splitter</emphasis> which may generate multiple
|
||||
replies for each Message it handles. When using the namespace configuration, you do not strictly need to know
|
||||
all of the details, but it still might be worth knowing that several of these components share a common base
|
||||
class, the <classname>AbstractReplyProducingMessageHandler</classname>, and it provides a
|
||||
<methodname>setOutputChannel(..)</methodname> method.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="endpoint-namespace">
|
||||
<title>Namespace Support</title>
|
||||
<para>
|
||||
Throughout the reference manual, you will see specific configuration examples for endpoint elements, such as
|
||||
router, transformer, service-activator, and so on. Most of these will support an "input-channel" attribute and
|
||||
many will support an "output-channel" attribute. After being parsed, these endpoint elements produce an instance
|
||||
of either the <classname>PollingConsumer</classname> or the
|
||||
<classname>EventDrivenConsumer</classname> depending on the type of the "input-channel" that is
|
||||
referenced: <interfacename>PollableChannel</interfacename> or <interfacename>SubscribableChannel</interfacename>
|
||||
respectively. When the channel is pollable, then the polling behavior is determined based on the endpoint
|
||||
element's "poller" sub-element and its attributes. For example, a simple interval-based poller with a 1-second interval would be
|
||||
configured like this: <programlisting language="xml"><![CDATA[ <transformer input-channel="pollable"
|
||||
ref="transformer"
|
||||
output-channel="output">
|
||||
<poller fixed-rate="1000"/>
|
||||
</transformer>]]></programlisting>
|
||||
As an alternative to 'fixed-rate' you cna also use 'fixed-delay' attribute.
|
||||
</para>
|
||||
<para>
|
||||
For a poller based on a Cron expression, use the "cron" attribute instead:
|
||||
<programlisting language="xml"><![CDATA[ <transformer input-channel="pollable"
|
||||
ref="transformer"
|
||||
output-channel="output">
|
||||
<poller cron="*/10 * * * * MON-FRI"/>
|
||||
</transformer>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
If the input channel is a <interfacename>PollableChannel</interfacename>, then the poller configuration is
|
||||
required. Specifically, as mentioned above, the 'trigger' is a required property of the PollingConsumer class.
|
||||
Therefore, if you omit the "poller" sub-element for a Polling Consumer endpoint's configuration, an Exception
|
||||
may be thrown. The exception will also be thrown if you attempt to configure a poller on the element that is
|
||||
connected to a non-pollable channel.
|
||||
</para>
|
||||
<para>
|
||||
It is also possible to create top-level pollers in which case only a "ref" is required:
|
||||
<programlisting language="xml"><![CDATA[ <poller id="weekdayPoller" cron="*/10 * * * * MON-FRI"/>
|
||||
|
||||
<transformer input-channel="pollable"
|
||||
ref="transformer"
|
||||
output-channel="output">
|
||||
<poller ref="weekdayPoller"/>
|
||||
</transformer>]]></programlisting>
|
||||
In fact, to simplify the configuration, you can define a global default poller. A single top-level poller within
|
||||
an ApplicationContext may have the <code>default</code> attribute with a value of "true". In that case, any
|
||||
endpoint with a PollableChannel for its input-channel that is defined within the same ApplicationContext and has
|
||||
no explicitly configured 'poller' sub-element will use that default.
|
||||
<programlisting language="xml"><![CDATA[ <poller id="defaultPoller" default="true" max-messages-per-poll="5" fixed-rate="3000"/>
|
||||
|
||||
<!-- No <poller/> sub-element is necessary since there is a default -->
|
||||
<transformer input-channel="pollable"
|
||||
ref="transformer"
|
||||
output-channel="output"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Spring Integration also provides transaction support for the pollers so that each receive-and-forward
|
||||
operation can be performed as an atomic unit-of-work. To configure transactions for a poller, simply add the
|
||||
<transactional/> sub-element. The attributes for this element should be familiar to anyone who has
|
||||
experience with Spring's Transaction management:
|
||||
<programlisting language="xml"><![CDATA[<poller fixed-delay="1000">
|
||||
<transactional transaction-manager="txManager"
|
||||
propagation="REQUIRED"
|
||||
isolation="REPEATABLE_READ"
|
||||
timeout="10000"
|
||||
read-only="false"/>
|
||||
</poller>]]></programlisting>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>AOP Advice chains</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
Since Spring transaction support depends on the Proxy mechanism with <classname>TransactionInterceptor</classname> (AOP Advice) handling transactional
|
||||
behavior of the message flow initiated by the poler, some times there is a need to provide extra Advice(s) to handle other
|
||||
cross cutting behavior associated with the poller. For that poller defines an 'advice-chain' element allowing you to add
|
||||
more advices - class that implements <classname>MethodInterceptor</classname> interface..
|
||||
<programlisting language="xml"><![CDATA[<service-activator id="advicedSa" input-channel="goodInputWithAdvice" ref="testBean"
|
||||
method="good" output-channel="output">
|
||||
<poller max-messages-per-poll="1" fixed-rate="10000">
|
||||
<transactional transaction-manager="txManager" />
|
||||
<advice-chain>
|
||||
<ref bean="adviceA" />
|
||||
<beans:bean class="org.bar.SampleAdvice"/>
|
||||
</advice-chain>
|
||||
</poller>
|
||||
</service-activator>]]></programlisting>
|
||||
For more information on how to implement MethodInterceptor please refer to AOP sections of Spring
|
||||
reference manual (section 7 and 8). Advice chain can also be applied on the poller that does not have
|
||||
any transaction configuration essentially allowing you to enhance the behavior of the message flow initiated by the poller.
|
||||
</para>
|
||||
<para>
|
||||
The polling threads may be executed by any instance of Spring's <interfacename>TaskExecutor</interfacename>
|
||||
abstraction. This enables concurrency for an endpoint or group of endpoints. As of Spring 3.0, there is a "task"
|
||||
namespace in the core Spring Framework, and its <executor/> element supports the creation of a simple thread
|
||||
pool executor. That element accepts attributes for common concurrency settings such as pool-size and queue-capacity.
|
||||
Configuring a thread-pooling executor can make a substantial difference in how the endpoint performs under load. These
|
||||
settings are available per-endpoint since the performance of an endpoint is one of the major factors to consider
|
||||
(the other major factor being the expected volume on the channel to which the endpoint subscribes). To enable
|
||||
concurrency for a polling endpoint that is configured with the XML namespace support, provide the 'task-executor'
|
||||
reference on its <poller/> element and then provide one or more of the properties shown below:
|
||||
<programlisting language="xml"><![CDATA[ <poller task-executor="pool" fixed-rate="1000"/>
|
||||
|
||||
<task:executor id="pool"
|
||||
pool-size="5-25"
|
||||
queue-capacity="20"
|
||||
keep-alive="120"/>]]></programlisting>
|
||||
If no 'task-executor' is provided, the consumer's handler will be invoked in the caller's thread. Note that the
|
||||
"caller" is usually the default <interfacename>TaskScheduler</interfacename>
|
||||
(see <xref linkend="namespace-taskscheduler"/>). Also, keep in mind that the 'task-executor' attribute can
|
||||
provide a reference to any implementation of Spring's <interfacename>TaskExecutor</interfacename> interface by
|
||||
specifying the bean name. The "executor" element above is simply provided for convenience.
|
||||
</para>
|
||||
<para>
|
||||
As mentioned in the background section for Polling Consumers above, you can also configure a Polling Consumer
|
||||
in such a way as to emulate event-driven behavior. With a long receive-timeout and a short interval-trigger,
|
||||
you can ensure a very timely reaction to arriving messages even on a polled message source. Note that this
|
||||
will only apply to sources that have a blocking wait call with a timeout. For example, the File poller does
|
||||
not block, each receive() call returns immediately and either contains new files or not. Therefore, even if
|
||||
a poller contains a long receive-timeout, that value would never be usable in such a scenario. On the other
|
||||
hand when using Spring Integration's own queue-based channels, the timeout value does have a chance to
|
||||
participate. The following example demonstrates how a Polling Consumer will receive Messages nearly
|
||||
instantaneously.
|
||||
<programlisting language="xml"><![CDATA[ <service-activator input-channel="someQueueChannel"
|
||||
output-channel="output">
|
||||
<poller receive-timeout="30000" fixed-rate="10"/>
|
||||
|
||||
</service-activator>]]></programlisting>
|
||||
Using this approach does not carry much overhead since internally it is nothing more then a timed-wait thread
|
||||
which does not require nearly as much CPU resource usage as a thrashing, infinite while loop for example.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="payload-type-conversion">
|
||||
<title>Payload Type Conversion</title>
|
||||
<para>
|
||||
Throughout the reference manual, you will also see specific configuration and implementation examples of various endpoints
|
||||
which can accept a Message or any arbitrary Object as an input parameter. In the case of an Object, such parameter will
|
||||
be mapped to a Message payload or part of the payload or header (when using Spring Expression Language). However there
|
||||
are times when the type of input parameter of the endpoint method does not match the type of the payload or its part.
|
||||
In this scenario we need to perform type conversion. Spring Integration provides a convenient way for registering type
|
||||
converters (using Spring 3.x ConversionService) within its own instance of the conversion service bean named <emphasis>integrationConversionService</emphasis>
|
||||
which is automatically created as soon as the first converter is defined.
|
||||
|
||||
To register such converter all you need is to implement <interfacename> org.springframework.core.convert.converter.Converter</interfacename> and register via
|
||||
cionvinient namespace support:
|
||||
<programlisting language="xml"><![CDATA[ <int:converter ref="sampleConverter"/>
|
||||
|
||||
<bean id="sampleConverter" class="foo.bar.TestConverter"/>]]></programlisting>
|
||||
|
||||
or
|
||||
<programlisting language="xml"><![CDATA[ <int:converter>
|
||||
<bean class="org.springframework.integration.config.xml.ConverterParserTests$TestConverter3"/>
|
||||
</int:converter>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="async-polling">
|
||||
<title>Asynchronous polling</title>
|
||||
<para>
|
||||
If you want the polling to be asynchronous, Poller can optionaly specify 'task-executor' attribute
|
||||
pointing to an existing instance of <classname>TaskExecutor</classname> bean
|
||||
(Spring 3.0 provides a convinient namespaces configuration via the <code>task</code> namespace). However, there are certain things
|
||||
you must understand when configuring Poller with TaskExecutor.
|
||||
</para>
|
||||
<para>
|
||||
The problem is that there are two configurations in place. The <emphasis>Poller</emphasis> and the <emphasis>TaskExecutor</emphasis>
|
||||
and they both have to be in tune with each other otherwise you might end up creating an artificial memory leak.
|
||||
</para>
|
||||
<para>
|
||||
Let's look at the following configuration provided by one of the users on the Spring's
|
||||
forums (http://forum.springsource.org/showthread.php?t=94519):
|
||||
|
||||
<programlisting language="xml"><![CDATA[<int:service-activator input-channel="publishChannel" ref="myService">
|
||||
<int:poller receive-timeout="5000" task-executor="taskExecutor" fixed-rate="50"/>
|
||||
</si:service-activator>
|
||||
|
||||
<task:executor id="taskExecutor" pool-size="20" queue-capacity="20"/>]]></programlisting>
|
||||
|
||||
The above configuration demonstrates one of those out of tune configurations.
|
||||
</para>
|
||||
<para>
|
||||
The poller keeps scheduling new tasks even though all the threads are blocked waiting for either a new message to arrive,
|
||||
or the timeout to expire. Given that there are 20 threads executing tasks with a 5 second timeout, they will be executed
|
||||
at a rate of 4 per second (5000/20 = 250ms). But, new tasks are being scheduled at a rate of 20 per second, so the internal
|
||||
queue in the task executor will grow at a rate of 16 per second (while the process is idle), so we essentially have a memory leak.
|
||||
</para>
|
||||
<para>
|
||||
One of the ways to handle this is to set <code>queue-capacity</code> attribute of Task Executor to 0. You can also manage it by specifying what to do
|
||||
with messages that can not be queued up by setting <code>rejection-policy</code> attribute of Task Executor (e.g., DISCARD). In other
|
||||
words there are certain details you must understand with regard to configuring the TaskExecutor. Please refer
|
||||
to - <emphasis>Section 25 - Task Execution and Scheduling</emphasis> of Spring reference manual.
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,63 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="applicationevent">
|
||||
|
||||
<title>Spring ApplicationEvent Support</title>
|
||||
|
||||
<para>
|
||||
Spring Integration provides support for inbound and outbound <classname>ApplicationEvents</classname>
|
||||
as defined by the underlying Spring Framework. For more information about the events and listeners,
|
||||
refer to the <ulink url="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#context-functionality-events">Spring Reference Manual</ulink>.
|
||||
</para>
|
||||
|
||||
<section id="applicationevent-inbound">
|
||||
<title>Receiving Spring ApplicationEvents</title>
|
||||
<para>
|
||||
To receive events and send them to a channel, simply define an instance of Spring Integration's
|
||||
<classname>ApplicationEventListeningChannelAdapter</classname>. This class is an implementation of
|
||||
Spring's <interfacename>ApplicationListener</interfacename> interface. By default it will pass all
|
||||
received events as Spring Integration Messages. To limit based on the type of event, configure the
|
||||
list of event types that you want to receive with the 'eventTypes' property.
|
||||
</para>
|
||||
<para>
|
||||
For convenience namespace support was provided to configure <classname>ApplicationEventListeningChannelAdapter</classname> via <emphasis>inbound-channel-adapter</emphasis>
|
||||
<programlisting language="xml"><![CDATA[<int-event:inbound-channel-adapter channel="input" event-types="foo.bar.FooApplicationEvent, foo.bar.BarApplicationEvent"/>
|
||||
|
||||
<int:publish-subscribe-channel id="sampleEventChannel"/>]]></programlisting>
|
||||
In the above sample, all Application Context events that are of type specified by the 'event-types' (optional) attribute will be
|
||||
delivered as Spring Integration Messages to 'sampleEventChannel'.
|
||||
</para>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<section id="applicationevent-outbound">
|
||||
<title>Sending Spring ApplicationEvents</title>
|
||||
<para>
|
||||
To send Spring <classname>ApplicationEvents</classname>, create an instance of the
|
||||
<classname>ApplicationEventPublishingMessageHandler</classname> and register it within an endpoint.
|
||||
This implementation of the <interfacename>MessageHandler</interfacename> interface also implements
|
||||
Spring's <interfacename>ApplicationEventPublisherAware</interfacename> interface and thus acts as a
|
||||
bridge between Spring Integration Messages and <classname>ApplicationEvents</classname>.
|
||||
</para>
|
||||
<para>
|
||||
For convenience namespace support was provided to configure <classname>ApplicationEventPublishingMessageHandler</classname> via <emphasis>outbound-channel-adapter</emphasis> element
|
||||
<programlisting language="xml"><![CDATA[<int:channel id="input"/>
|
||||
|
||||
<int-event:outbound-channel-adapter channel="input"/>]]></programlisting>
|
||||
If you are using PollableChannel (e.g., Queue), you can also provide <emphasis>poller</emphasis> as sub-element of <emphasis>outbound-channel-adapter</emphasis>, optionally providing <emphasis>task-executor</emphasis>
|
||||
<programlisting language="xml"><![CDATA[<int:channel id="input">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-event:outbound-channel-adapter channel="input">
|
||||
<int:poller max-messages-per-poll="1" task-executor="executor" fixed-rate="100"/>
|
||||
</int-event:outbound-channel-adapter>
|
||||
|
||||
<task:executor id="executor" pool-size="5"/>]]></programlisting>
|
||||
|
||||
In the above sample, all messages sent to an 'input' channel will be published as ApplicationEvents to Spring Application sContext
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,228 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="files">
|
||||
<title>File Support</title>
|
||||
|
||||
<section id="file-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Spring Integration's File support extends the Spring Integration Core with
|
||||
a dedicated vocabulary to deal with reading, writing, and transforming files.
|
||||
It provides a namespace that enables elements defining Channel Adapters dedicated
|
||||
to files and support for Transformers that can read file contents into strings or
|
||||
byte arrays.
|
||||
</para>
|
||||
<para>
|
||||
This section will explain the workings of <classname>FileReadingMessageSource</classname>
|
||||
and <classname>FileWritingMessageHandler</classname> and how to configure them as
|
||||
<emphasis>beans</emphasis>. Also the support for dealing with files through file specific
|
||||
implementations of <interfacename>Transformer</interfacename> will be discussed. Finally the
|
||||
file specific namespace will be explained.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="file-reading">
|
||||
<title>Reading Files</title>
|
||||
<para>
|
||||
A <classname>FileReadingMessageSource</classname> can be used to consume files from the filesystem.
|
||||
This is an implementation of <interfacename>MessageSource</interfacename> that creates messages from
|
||||
a file system directory. <programlisting language="xml"><![CDATA[<bean id="pollableFileSource"
|
||||
class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${input.directory}"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To prevent creating messages for certain files, you may supply a
|
||||
<interfacename>FileListFilter</interfacename>. By default, an
|
||||
<classname>AcceptOnceFileListFilter</classname> is used. This filter
|
||||
ensures files are picked up only once from the directory.
|
||||
<programlisting language="xml"><![CDATA[<bean id="pollableFileSource"
|
||||
class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${input.directory}"
|
||||
p:filter-ref="customFilterBean"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
A common problem with reading files is that a file may be detected before
|
||||
it is ready. The default <classname>AcceptOnceFileListFilter</classname>
|
||||
does not prevent this. In most cases, this can be prevented if the
|
||||
file-writing process renames each file as soon as it is ready for
|
||||
reading. A pattern-matching filter that accepts only files that are
|
||||
ready (e.g. based on a known suffix), composed with the default
|
||||
<classname>AcceptOnceFileListFilter</classname> allows for this.
|
||||
The <classname>CompositeFileListFilter</classname> enables the
|
||||
composition.
|
||||
<programlisting language="xml"><![CDATA[<bean id="pollableFileSource"
|
||||
class="org.springframework.integration.file.FileReadingMessageSource"
|
||||
p:inputDirectory="file:${input.directory}"
|
||||
p:filter-ref="compositeFilter"/>
|
||||
<bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
|
||||
<constructor-arg>
|
||||
<list>
|
||||
<bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
|
||||
<bean class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
|
||||
<constructor-arg value="^test.*$"/>
|
||||
</bean>
|
||||
</list>
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The configuration can be simplified using the file specific namespace. To do
|
||||
this use the following template.
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:file="http://www.springframework.org/schema/integration/file"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/file
|
||||
http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd">
|
||||
</beans>]]></programlisting>
|
||||
Within this namespace you can reduce the FileReadingMessageSource and wrap
|
||||
it in an inbound Channel Adapter like this:
|
||||
<programlisting language="xml"><![CDATA[ <file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}" prevent-duplicates="true"/>
|
||||
|
||||
<file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}"
|
||||
filter="customFilterBean" />
|
||||
|
||||
<file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}"
|
||||
filename-pattern="test*" /> ]]></programlisting>
|
||||
The first channel adapter is relying on the default filter that just prevents
|
||||
duplication, the second is using a custom filter, and the third is using the
|
||||
<emphasis>filename-pattern</emphasis> attribute to add a <classname>AntPathMatcher</classname>
|
||||
based filter to the <classname>FileReadingMessageSource</classname>.
|
||||
The <emphasis>file-name-pattern</emphasis> and <emphasis>filter</emphasis> attributes are mutually exclusive, but
|
||||
you can use a <classname>CompositeFileListFilter</classname> to use any combination of filters, including a
|
||||
pattern based filter to fit your particular needs.
|
||||
</para>
|
||||
<para>
|
||||
When multiple processes are reading from the same directory it can be desirable to lock files to prevent
|
||||
them from being picked up concurrently. To do this you can use a <interfacename>FileLocker</interfacename>.
|
||||
There is a java.nio based implementation available out of the box, but it is also possible to implement your
|
||||
own locking scheme. The nio locker can be injected as follows
|
||||
<programlisting><![CDATA[ <file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}" prevent-duplicates="true">
|
||||
<file:nio-locker/>
|
||||
</file:inbound-channel-adapter>]]>
|
||||
</programlisting>
|
||||
A custom locker you can configure like this:
|
||||
<programlisting><![CDATA[ <file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}" prevent-duplicates="true">
|
||||
<file:locker ref="customLocker"/>
|
||||
</file:inbound-channel-adapter>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
When filtering and locking files is not enough it might be needed to control the way files are listed entirely. To
|
||||
implement this type of requirement you can use an implementation of <interfacename>DirectoryScanner</interfacename>.
|
||||
This scanner allows you to determine entirely what files are listed each poll. This is also the interface
|
||||
that Spring Integration uses internally to wire FileListFilters FileLocker to the FileReadingMessageSource.
|
||||
A custom DirectoryScanner can be injected into the <file:inbound-channel-adapter/> on the <code>scanner</code>
|
||||
attribute.
|
||||
<programlisting><![CDATA[ <file:inbound-channel-adapter id="filesIn"
|
||||
directory="file:${input.directory}" prevent-duplicates="true" scanner="customDirectoryScanner"/>]]>
|
||||
</programlisting>
|
||||
This gives you full freedom to choose the ordering, listing and locking strategies.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="file-writing">
|
||||
<title>Writing files</title>
|
||||
<para>
|
||||
To write messages to the file system you can use a
|
||||
<classname>FileWritingMessageHandler</classname>. This class can deal with
|
||||
File, String, or byte array payloads. In its simplest form the
|
||||
<classname>FileWritingMessageHandler </classname> only requires a
|
||||
destination directory for writing the files. The name of the file to be
|
||||
written is determined by the handler's <classname>FileNameGenerator</classname>.
|
||||
The default implementation looks for a Message header whose key matches
|
||||
the constant defined as <code>FileHeaders.FILENAME</code>.
|
||||
</para>
|
||||
<para>
|
||||
Additionally, you can configure the encoding and the charset that
|
||||
will be used in case of a String payload.
|
||||
</para>
|
||||
<para>
|
||||
To make things easier you can configure the FileWritingMessageHandler as
|
||||
part of an outbound channel adapter using the namespace.
|
||||
<programlisting language="xml"><![CDATA[ <file:outbound-channel-adapter id="filesOut" directory="file:${input.directory.property}"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The namespace based configuration also supports a <code>delete-source-files</code> attribute.
|
||||
If set to <code>true</code>, it will trigger deletion of the original source files after writing
|
||||
to a destination. The default value for that flag is <code>false</code>.
|
||||
<programlisting language="xml"><![CDATA[ <file:outbound-channel-adapter id="filesOut"
|
||||
directory="file:${output.directory}"
|
||||
delete-source-files="true"/>]]></programlisting>
|
||||
<note>
|
||||
<para>
|
||||
The <code>delete-source-files</code> attribute will only have an effect if the inbound
|
||||
Message has a File payload or if the <classname>FileHeaders.ORIGINAL_FILE</classname> header
|
||||
value contains either the source File instance or a String representing the original file path.
|
||||
</para>
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
In cases where you want to continue processing messages based on the written File you can use
|
||||
the <code>outbound-gateway</code> instead. It plays a very similar role as the
|
||||
<code>outbound-channel-adapter</code>. However after writing the File, it will also send it
|
||||
to the reply channel as the payload of a Message.
|
||||
<programlisting language="xml"><![CDATA[ <file:outbound-gateway id="mover" request-channel="moveInput"
|
||||
reply-channel="output"
|
||||
directory="${output.directory}"
|
||||
delete-source-files="true"/>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
The 'outbound-gateway' works well in cases where you want to first move a File and then send it
|
||||
through a processing pipeline. In such cases, you may connect the file namespace's
|
||||
'inbound-channel-adapter' element to the 'outbound-gateway' and then connect that gateway's
|
||||
reply-channel to the beginning of the pipeline.
|
||||
</note>
|
||||
<para>
|
||||
If you have more elaborate requirements or need to support additional payload types as input
|
||||
to be converted to file content you could extend the FileWritingMessageHandler, but a much
|
||||
better option is to rely on a <classname>Transformer</classname>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="file-transforming">
|
||||
<title>File Transformers</title>
|
||||
<para>
|
||||
To transform data read from the file system to objects and the other way around you need
|
||||
to do some work. Contrary to <classname>FileReadingMessageSource</classname> and to a
|
||||
lesser extent <classname>FileWritingMessageHandler</classname>, it is very likely that you
|
||||
will need your own mechanism to get the job done. For this you can implement the
|
||||
<interfacename>Transformer</interfacename> interface. Or extend the
|
||||
<classname>AbstractFilePayloadTransformer</classname> for inbound messages. Some obvious
|
||||
implementations have been provided.
|
||||
</para>
|
||||
<para>
|
||||
<classname>FileToByteArrayTransformer</classname> transforms Files into byte[]s using
|
||||
Spring's <classname>FileCopyUtils</classname>. It is often better to use a sequence of
|
||||
transformers than to put all transformations in a single class. In that case the File to
|
||||
byte[] conversion might be a logical first step.
|
||||
</para>
|
||||
<para>
|
||||
<classname>FileToStringTransformer</classname> will convert Files to Strings as the name
|
||||
suggests. If nothing else, this can be useful for debugging (consider using with a Wire Tap).
|
||||
</para>
|
||||
<para>
|
||||
To configure File specific transformers you can use the appropriate elements from the file namespace.
|
||||
<programlisting language="xml"><![CDATA[ <file-to-bytes-transformer input-channel="input" output-channel="output"
|
||||
delete-files="true"/>
|
||||
|
||||
<file:file-to-string-transformer input-channel="input" output-channel="output
|
||||
delete-files="true" charset="UTF-8"/>]]></programlisting>
|
||||
The <emphasis>delete-files</emphasis> option signals to the transformer that it should delete
|
||||
the inbound File after the transformation is complete. This is in no way a replacement for using the
|
||||
<classname>AcceptOnceFileListFilter</classname> when the FileReadingMessageSource is being used in a
|
||||
multi-threaded environment (e.g. Spring Integration in general).
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,132 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="filter">
|
||||
<title>Filter</title>
|
||||
|
||||
<section id="filter-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Message Filters are used to decide whether a Message should be passed along or dropped based on some criteria
|
||||
such as a Message Header value or even content within the Message itself. Therefore, a Message Filter is similar
|
||||
to a router, except that for each Message received from the filter's input channel, that same Message may or may
|
||||
not be sent to the filter's output channel. Unlike the router, it makes no decision regarding
|
||||
<emphasis>which</emphasis> Message Channel to send to but only decides <emphasis>whether</emphasis> to send.
|
||||
<note>
|
||||
As you will see momentarily, the Filter does also support a discard channel, so in certain cases it
|
||||
<emphasis>can</emphasis> play the role of a very simple router (or "switch") based on a boolean condition.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
In Spring Integration, a Message Filter may be configured as a Message Endpoint that delegates to some
|
||||
implementation of the <interfacename>MessageSelector</interfacename> interface. That interface is itself quite
|
||||
simple: <programlisting language="java"><![CDATA[ public interface MessageSelector {
|
||||
|
||||
boolean accept(Message<?> message);
|
||||
|
||||
}]]></programlisting>
|
||||
The <classname>MessageFilter</classname> constructor accepts a selector instance:
|
||||
<programlisting language="java"><![CDATA[ MessageFilter filter = new MessageFilter(someSelector);]]></programlisting>
|
||||
</para>
|
||||
In combination with the namespace and SpEL very powerful filters can be configured with very little java code.
|
||||
</section>
|
||||
|
||||
<section id="filter-namespace">
|
||||
<title>The <filter> Element</title>
|
||||
<para>
|
||||
The <filter> element is used to create a Message-selecting endpoint. In addition to "input-channel"
|
||||
and "output-channel" attributes, it requires a "ref". The "ref" may point to a MessageSelector implementation:
|
||||
<programlisting language="xml"><![CDATA[ <filter input-channel="input" ref="selector" output-channel="output"/>
|
||||
|
||||
<bean id="selector" class="example.MessageSelectorImpl"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Alternatively, the "method" attribute can be added at which point the "ref" may refer to any object.
|
||||
The referenced method may expect either the <interfacename>Message</interfacename> type or the payload type of
|
||||
inbound Messages. The return value of the method must be a boolean value. Any time the method returns 'true',
|
||||
the Message <emphasis>will</emphasis> be passed along to the output-channel.
|
||||
<programlisting language="xml"><![CDATA[ <filter input-channel="input" output-channel="output"
|
||||
ref="exampleObject" method="someBooleanReturningMethod"/>
|
||||
|
||||
<bean id="exampleObject" class="example.SomeObject"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
If the selector or adapted POJO method returns <code>false</code>, there are a few settings that control the
|
||||
fate of the rejected Message. By default (if configured like the example above), the rejected Messages will
|
||||
be silently dropped. If rejection should instead indicate an error condition, then set the
|
||||
'throw-exception-on-rejection' flag to <code>true</code>:
|
||||
<programlisting language="xml"><![CDATA[ <filter input-channel="input" ref="selector"
|
||||
output-channel="output" throw-exception-on-rejection="true"/> ]]></programlisting>
|
||||
If you want the rejected messages to go to a specific channel, provide that reference as the 'discard-channel':
|
||||
<programlisting language="xml"><![CDATA[ <filter input-channel="input" ref="selector"
|
||||
output-channel="output" discard-channel="rejectedMessages"/> ]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
A common usage for Message Filters is in conjunction with a Publish Subscribe Channel. Many filter endpoints may
|
||||
be subscribed to the same channel, and they decide whether or not to pass the Message for the next endpoint which
|
||||
could be any of the supported types (e.g. Service Activator). This provides a <emphasis>reactive</emphasis>
|
||||
alternative to the more <emphasis>proactive</emphasis> approach of using a Message Router with a single
|
||||
Point-to-Point input channel and multiple output channels.
|
||||
</note>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the custom filter implementation can be reused in other
|
||||
<code><filter></code> definitions. However if the custom filter implementation should be scoped to a
|
||||
single <code><filter></code> element, provide an inner bean definition:
|
||||
<programlisting language="xml"><![CDATA[<filter method="someMethod" input-channel="inChannel" output-channel="outChannel">
|
||||
<beans:bean class="org.foo.MyCustomFilter"/>
|
||||
</filter>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both the "ref" attribute and an inner handler definition in the same <code><filter></code> configuration
|
||||
is not allowed, as it creates an ambiguous condition, and it will therefore result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
With the introduction of SpEL Spring Integration has added the <code>expression</code> attribute to the filter
|
||||
element. It can be used to avoid Java entirely for simple filters.
|
||||
<programlisting language="xml">
|
||||
<![CDATA[ <filter input-channel="input" expression="payload.equals(nonsense)"/>]]>
|
||||
</programlisting>
|
||||
The string passed as the expression attribute will be evaluated as a SpEL expression in the context of the message.
|
||||
If it is needed to include the result of an expression in the scope of the application context you can use the
|
||||
#{} notation as defined in the SpEL reference documentation
|
||||
<ulink url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html#expressions-beandef">
|
||||
SpEL reference documentation
|
||||
</ulink>.
|
||||
<programlisting language="xml">
|
||||
<![CDATA[ <filter input-channel="input" expression="payload.matches(#{filterPatterns.nonsensePattern})"/>]]>
|
||||
</programlisting>
|
||||
If the Expression itself needs to be dynamic, then an 'expression' sub-element may be used. That provides a level of
|
||||
indirection for resolving the Expression by its key from an ExpressionSource. That is a strategy interface that you
|
||||
can implement directly, or you can rely upon a version available in Spring Integration that loads Expressions from
|
||||
a "resource bundle" and can check for modifications after a given number of seconds. All of this is demonstrated in
|
||||
the following configuration sample where the Expression could be reloaded within one minute if the underlying file
|
||||
had been modified. If the ExpressionSource bean is named "expressionSource", then it is not necessary to provide the
|
||||
"source" attribute on the <expression> element, but in this case it's shown for completeness.
|
||||
<programlisting language="xml">
|
||||
<![CDATA[ <filter input-channel="input" output-channel="output">
|
||||
<expression key="filterPatterns.example" source="myExpressions"/>
|
||||
</filter>
|
||||
|
||||
<beans:bean id="myExpressions" id="myExpressions"
|
||||
class="org.springframework.integration.expression.ReloadableResourceBundleExpressionSource">
|
||||
<beans:property name="basename" value="config/integration/expressions"/>
|
||||
<beans:property name="cacheSeconds" value="60"/>
|
||||
</beans:bean>
|
||||
]]></programlisting>
|
||||
|
||||
Then, the 'config/integration/expressions.properties' file (or any more specific version with a locale extension
|
||||
to be resolved in the typical way that resource-bundles are loaded) would contain a key/value pair:
|
||||
<programlisting language="xml">
|
||||
<![CDATA[ filterPatterns.example=payload > 100
|
||||
]]></programlisting>
|
||||
|
||||
<note>All of the examples that use "expression" as an attribute or sub-element can also be applied within
|
||||
transformer, router, splitter, service-activator, and header-enricher elements. Of course, the semantics/role
|
||||
of the given component type would affect the interpretation of the evaluation result in the same way that the
|
||||
return or a method-invocation would be interpreted. For example, an expression can return Strings that are
|
||||
to be treated as Message Channel names by a router component.</note>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,255 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="gateway">
|
||||
<title>Inbound Messaging Gateways</title>
|
||||
|
||||
<section id="gateway-proxy">
|
||||
<title>GatewayProxyFactoryBean</title>
|
||||
<para>
|
||||
Working with Objects instead of Messages is an improvement. However, it would be even better to have no
|
||||
dependency on the Spring Integration API at all - including the gateway class. For that reason, Spring
|
||||
Integration also provides a <classname>GatewayProxyFactoryBean</classname> that generates a proxy for
|
||||
any interface and internally invokes the gateway methods shown above. Namespace support is also
|
||||
provided as demonstrated by the following example.
|
||||
<programlisting language="xml"><![CDATA[<gateway id="fooService"
|
||||
service-interface="org.example.FooService"
|
||||
default-request-channel="requestChannel"
|
||||
default-reply-channel="replyChannel"/>]]></programlisting>
|
||||
Then, the "fooService" can be injected into other beans, and the code that invokes the methods on that
|
||||
proxied instance of the FooService interface has no awareness of the Spring Integration API. The general
|
||||
approach is similar to that of Spring Remoting (RMI, HttpInvoker, etc.). See the "Samples" Appendix for
|
||||
an example that uses this "gateway" element (in the Cafe demo).
|
||||
</para>
|
||||
<para>
|
||||
The reason that the attributes on the 'gateway' element are named 'default-request-channel' and
|
||||
'default-reply-channel' is that you may also provide per-method channel references by using the
|
||||
@Gateway annotation.
|
||||
<programlisting language="java"><![CDATA[ public interface Cafe {
|
||||
|
||||
@Gateway(requestChannel="orders")
|
||||
void placeOrder(Order order);
|
||||
|
||||
}]]></programlisting>
|
||||
... as well as <code>method</code> sub element if yuo prefer XML configuration (see next paragraph)
|
||||
</para>
|
||||
<para>
|
||||
It is also possible to pass values to be interpreted as Message headers on the Message
|
||||
that is created and sent to the request channel by using the @Header annotation:
|
||||
<programlisting language="java"><![CDATA[ public interface FileWriter {
|
||||
|
||||
@Gateway(requestChannel="filesOut")
|
||||
void write(byte[] content, @Header(FileHeaders.FILENAME) String filename);
|
||||
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you prefer XML way of configuring Gateway methods, you can provide <emphasis>method</emphasis> sub-elements
|
||||
to the gateway configuration (see below)
|
||||
<programlisting language="xml"><![CDATA[<si:gateway id="myGateway" service-interface="org.foo.bar.TestGateway"
|
||||
default-request-channel="inputC">
|
||||
<si:method name="echo" request-channel="inputA" reply-timeout="2" request-timeout="200"/>
|
||||
<si:method name="echoUpperCase" request-channel="inputB"/>
|
||||
<si:method name="echoViaDefault"/>
|
||||
</si:gateway>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
You can also provide individual headers per method invocation via XML.
|
||||
This could be very useful if the headers you want to set are static in nature and you don't want
|
||||
to embed them in the gateway's method signature via <classname>@Header</classname> annotations.
|
||||
For example, in the Loan Broker example we want to influence how aggregation of the Loan quotes
|
||||
will be done based on what type of request was initiated (single quote or all quotes). Determining the
|
||||
type of the request by evaluating what gateway method was invoked, although possible would
|
||||
violate the separation of concerns paradigm (method is a java artifact), but expressing your
|
||||
intention (meta information) via Message headers is natural in a Messaging architecture.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<int:gateway id="loanBrokerGateway"
|
||||
service-interface="org.springframework.integration.loanbroker.LoanBrokerGateway">
|
||||
<int:method name="getLoanQuote" request-channel="loanBrokerPreProcessingChannel">
|
||||
<int:header name="RESPONSE_TYPE" value="BEST"/>
|
||||
</int:method>
|
||||
<int:method name="getAllLoanQuotes" request-channel="loanBrokerPreProcessingChannel">
|
||||
<int:header name="RESPONSE_TYPE" value="ALL"/>
|
||||
</int:method>
|
||||
</int:gateway>]]></programlisting>
|
||||
In the above case you can clearly see how a different header value will be set for the 'RESPONSE_TYPE'
|
||||
header based on the gateway's method.
|
||||
</para>
|
||||
<para>
|
||||
As with anything else, Gateway invocation might result in errors.
|
||||
By default any error that has occurred downstream will be re-thrown as a MessagingExeption (RuntimeException)
|
||||
upon the Gateway's method invocation. However there are times when you may want to treat an Exception as a valid reply,
|
||||
by mapping it to a Message. To accomplish this our Gateway provides support for Exception mappers via the
|
||||
<emphasis>exception-mapper</emphasis> attribute.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<si:gateway id="sampleGateway"
|
||||
default-request-channel="gatewayChannel"
|
||||
service-interface="foo.bar.SimpleGateway"
|
||||
exception-mapper="exceptionMapper"/>
|
||||
|
||||
<bean id="exceptionMapper" class="foo.bar.SampleExceptionMapper"/>
|
||||
|
||||
]]></programlisting>
|
||||
|
||||
<emphasis>foo.bar.SampleExceptionMapper</emphasis> is the implementation of
|
||||
<emphasis>org.springframework.integration.message.InboundMessageMapper</emphasis> which only defines one method: <code>toMessage(Object object)</code>.
|
||||
<programlisting language="java"><![CDATA[public static class SampleExceptionMapper implements InboundMessageMapper<Throwable>{
|
||||
public Message<?> toMessage(Throwable object) throws Exception {
|
||||
MessageHandlingException ex = (MessageHandlingException) object;
|
||||
return MessageBuilder.withPayload("Error happened in message: " +
|
||||
ex.getFailedMessage().getPayload()).build();
|
||||
}
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
<important>
|
||||
Exposing messaging system via POJO Gateway is obviously a great benefit, but it does come at the price so there
|
||||
are certain things you must be aware of.
|
||||
|
||||
We want our Java method to return as quick as possible and not hang for infinite amount of time until they can
|
||||
return (void , exception or return value). When regular methods are used as a proxies in front of the Messaging
|
||||
system we have to take into account the asynchronous nature of the Messaging Systems. This means that there might
|
||||
be a chance that a Message hat was initiated by a Gateway could be dropped by a Filter, thus never reaching a
|
||||
component that is responsible to produce a reply. Some Service Activator method might result in the Exception,
|
||||
thus resulting in no-reply (as we don't generate Null messages).So as you can see there are multiple scenarios
|
||||
where reply message might not be coming which is perfectly natural in messaging systems. However think about the
|
||||
implication on the gateway method. The Gateway's method input arguments were incorporated into a Message and
|
||||
sent downstream. The reply Message would be converted to a return value of the Gateway's method. So you can see
|
||||
how ugly it could get if you can not guarantee that for each Gateway call there will alway be a reply Message.
|
||||
Basically your Gateway method will never return and will hang infinitely. (work in progress!!!!)
|
||||
One of the ways of handling this situation is via AsyncGateway (explained later in this section). Another way of handling it is to explicitly set the reply-timeout attribute. This way gateway will not hang for more then the time that was specified by the reply-timout and will return 'null'.
|
||||
</important>
|
||||
</para>
|
||||
</section>
|
||||
<section id="async-gateway">
|
||||
<title>Asynchronous Gateway</title>
|
||||
<para>
|
||||
As a pattern the Messaging Gateway is a very nice way to hide messaging-specific code while still exposing the full capabilities of the
|
||||
messaging system. And <classname>GatewayProxyFactoryBean</classname> provides a convenient way to expose a Proxy over a service-interface
|
||||
thus giving you a POJO-based access to a messaging system (based on objects in your own domain, or primitives/Strings, etc). But when a
|
||||
gateway is exposed via simple POJO methods which return values it does imply that for each Request message (generated when the method is invoked)
|
||||
there must be a Reply message (generated when the method has returned). Since Messaging systems naturally are asynchronous you may not always be
|
||||
able to guarantee the contract where <emphasis>"for each request there will always be be a reply"</emphasis>.
|
||||
With Spring Integration 2.0 we are introducing support for an <emphasis>Asynchronous Gateway</emphasis> which is a convenient way to initiate
|
||||
flows where you may not know if a reply is expected or how long will it take for it to arrive.
|
||||
</para>
|
||||
<para>
|
||||
A natural way to handle these types of scenarios in Java would be relying upon <emphasis>java.util.concurrent.Future</emphasis> instances, and
|
||||
that is exactly what Spring Integration uses to support an <emphasis>Asynchronous Gateway</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
From the XML configuration, there is nothing different and you still define <emphasis>Asynchronous Gateway</emphasis> the same way as a regular Gateway.
|
||||
<programlisting language="xml"><![CDATA[<int:gateway id="mathService"
|
||||
service-interface="org.springframework.integration.sample.gateway.futures.MathServiceGateway"
|
||||
default-request-channel="requestChannel"/>]]></programlisting>
|
||||
However the Gateway Interface (service-interface) is a bit different.
|
||||
|
||||
<programlisting language="java">public interface MathServiceGateway {
|
||||
Future<Integer> multiplyByTwo(int i);
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
As you can see from the example above the return type for the gateway method is <classname>Future</classname>. When
|
||||
<classname>GatewayProxyFactoryBean</classname> sees that the
|
||||
return type of the gateway method is <classname>Future</classname>, it immediately switches to the async mode by utilizing
|
||||
an <classname>AsyncTaskExecutor</classname>. That is all. The call to a method always returns immediately with <classname>Future</classname>
|
||||
encapsulating the interaction with the framework.
|
||||
Now you can interact with the <classname>Future</classname> at your own pace to get the result, timeout, get the exception etc...
|
||||
<programlisting language="java">MathServiceGateway mathService = ac.getBean("mathService", MathServiceGateway.class);
|
||||
Future<Integer> result = mathService.multiplyByTwo(number);
|
||||
// do something else here since the reply might take a moment
|
||||
int finalResult = result.get(1000, TimeUnit.SECONDS);</programlisting>
|
||||
For a more detailed example, please refer to the <emphasis>async-gateway</emphasis> sample distributed within the Spring Integration samples.
|
||||
</para>
|
||||
|
||||
</section>
|
||||
<section>
|
||||
<title>Gateway behavior when no response is coming</title>
|
||||
<para>
|
||||
As it was explained earlier, Gateway provides a convenient way of interacting with Messaging system via POJO method
|
||||
invocations, but realizing that a typical method invocation, which is generally expected to always return (even with Exception),
|
||||
might not always map one-to-one to message exchanges (e.g., reply message might not be coming which is equivalent to
|
||||
method not returning), it is important to go over several scenarios especially in the Sync Gateway case and understand
|
||||
what the default behavior of the Gateway and how to deal with these scenarios to make Sync Gateway behavior more
|
||||
predictable regardless of the outcome of the message flow that was initialed from such Gateway.
|
||||
</para>
|
||||
<para>
|
||||
There are certain attributes that could be configured to make Sync Gateway behavior more predictable,
|
||||
but some of them might not always work as you might have expected. One of them is <emphasis>reply-timeout</emphasis>.
|
||||
So, lets look at the <emphasis>reply-timeout</emphasis> attribute and see how it can/can't influence the behavior
|
||||
of the Sync Gateway in various scenarios. We will look at single-theraded scenario
|
||||
(all components downstream are connected via Direct Channel) and multi-theraded scenarios
|
||||
(e.g., somewhere downstream you may have Pollable or Executor Channel which breaks single-thread boundary)
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Long running process downstream</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Sync Gateway - single-threaded</emphasis>.
|
||||
If a component downstream is still running (e.g., infinite loop or a very slow service), then setting <emphasis>reply-timeout</emphasis>
|
||||
has no effect and Gateway method call will not return until such downstream service exits (e.g., return or exception).
|
||||
<emphasis>Sync Gateway - multi-threaded</emphasis>.
|
||||
If a component downstream is still running (e.g., infinite loop or a very slow service), in a multi-threaded message
|
||||
flow setting <emphasis>reply-timeout</emphasis> will have an effect by allowing gateway method invocation to
|
||||
return once the timeout has been reached, since <classname>GatewayProxyFactoryBean</classname> will simply
|
||||
poll on the reply channel waiting for a message untill the timeout expires. However it could result in the 'null' return
|
||||
from the Gateway method if the timeout has been reached before the actual reply was produced. It is also important to understand that
|
||||
the reply message (if produced) will be sent to a reply channel after Gateway method invocation might have returned, so you must be aware of that
|
||||
and design your flow with this in mind.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Downstream component returns 'null'</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Sync Gateway - single-threaded</emphasis>.
|
||||
If a component downstream returns 'null' and no <emphasis>reply-timeout</emphasis> has been configured, the Gateway
|
||||
method call will hang indefinitely unless: a) <emphasis>reply-timeout</emphasis> has been configured or b)
|
||||
<emphasis>requires-reply</emphasis> attribute has been set on the downstream component (e.g., service-activator)
|
||||
that might return 'null'. In this case, the exception will be thrown and propagated to the Gateway.
|
||||
<emphasis>Sync Gateway - multi-threaded</emphasis>. Behavior is the same as above.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Downstream component return signature is 'void' while Gateway method signature is non-void</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Sync Gateway - single-threaded</emphasis>.
|
||||
If a component downstream returns 'void' and no <emphasis>reply-timeout</emphasis> has been configured,
|
||||
the Gateway method call will hang indefinitely unless <emphasis>reply-timeout</emphasis> has been configured
|
||||
<emphasis>Sync Gateway - multi-threaded</emphasis> Behavior is the same as above.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Downstream component results in Runtime Exception (regardless of the method signature)</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Sync Gateway - single-threaded</emphasis>.
|
||||
If a component downstream throws a Runtime Exception, such exception will be propagated via Error Message back to
|
||||
the gateway and re-thrown.
|
||||
<emphasis>Sync Gateway - multi-threaded</emphasis> Behavior is the same as above.
|
||||
</para>
|
||||
<para>
|
||||
<important>
|
||||
It is also important to understand that by default <emphasis>reply-timout</emphasis> is unbounded which means that
|
||||
if not explicitly set there are several scenarios (described above) where your Gateway method invocation might
|
||||
hang indefinitely, so make sure you analyze your flow and if there is even a remote possibility of one of these
|
||||
scenarios to occur, set the <emphasis>reply-timout</emphasis> attribute to a 'safe' value or better off
|
||||
set the <emphasis>requires-reply</emphasis> attribute of the downstream component to 'true' to ensure a timely response.
|
||||
But also, realize that there are some scenarios (see the very first one)
|
||||
where <emphasis>reply-timout</emphasis> will not help which means it is also important to analyze your message
|
||||
flow and decide when to use Sync Gateway vs Async Gateway where Gateway method invocation is always guaranteed
|
||||
to return while giving you a more granular control over the results of the invocation via Java Futures.
|
||||
<para>
|
||||
Also, when dealing with Router you should remember that seeting <emphasis>resolution-required</emphasis> attribute to 'true'
|
||||
will result in the exception thrown by the router if it can not resolve a particular chanel. And when dealing with the filter
|
||||
you can also set <emphasis>throw-exception-on-rejection</emphasis> attribute. Both of these will help to ensure a timely response
|
||||
from the Gateway method invocation.
|
||||
</para>
|
||||
</important>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="groovy">
|
||||
<title>Groovy support</title>
|
||||
<para>
|
||||
With Spring Integration 2.0 we've added Groovy support allowing you to use Groovy scripting language to provide
|
||||
integration and business logic for various integration components similar to the way Spring Expression Language (SpEL)
|
||||
is use to implement routing, transformation and other integration concerns.
|
||||
|
||||
For more information about Groovy please refer to Groovy documentation which you can find here: http://groovy.codehaus.org/
|
||||
</para>
|
||||
|
||||
<section id="groovy-config">
|
||||
<title>Groovy configuration</title>
|
||||
<para>
|
||||
Depending on the complexity of your integration requirements Groovy scripts could be provided inline as CDATA in XML
|
||||
configuration or as a reference to a file containing Groovy script.
|
||||
|
||||
To enable Groovy support Spring Integration defines <classname>GroovyScriptExecutingMessageProcessor</classname> which will
|
||||
create a groovy Binding object identifying Message Payload as <code>payload</code> variable and Message Headers as
|
||||
<code>headers</code> variable. All that is left for you to do is write script that uses these variables.
|
||||
Below are couple of sample configurations:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Filter</emphasis>
|
||||
<programlisting language="xml"><filter input-channel="referencedScriptInput">
|
||||
<groovy:script location="some/path/to/groovy/file/GroovyFilterTests.groovy"/>
|
||||
</filter>
|
||||
|
||||
<filter input-channel="inlineScriptInput">
|
||||
<groovy:script><![CDATA[
|
||||
return payload == 'good'
|
||||
]]></groovy:script>
|
||||
</filter></programlisting>
|
||||
You see that script could be included inline or via <code>location</code> attribute using the groovy namespace sport.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Other supported elements are <emphasis>router, service-activator, transformer, splitter</emphasis>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Another interesting aspect of using Groovy support is framework's ability to update (reload) scripts
|
||||
without restarting the Application Context.
|
||||
To accomplish this all you need is specify <code>refresh-check-delay</code> attribute on <emphasis>script</emphasis>
|
||||
element. The reason for this attribute is to make reloading of the script more efficient.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<groovy:script location="..." refresh-check-delay="5000"/>]]></programlisting>
|
||||
|
||||
In the above example for the next 5 seconds after you update the script you'll still be using the old script and
|
||||
after 5 seconds the context will be updated with the new script. This is a good example where 'near real time'
|
||||
is acceptable.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<groovy:script location="..." refresh-check-delay="0"/>]]></programlisting>
|
||||
|
||||
In the above example the context will be updated with the new script every time the script is modified. Basically this is the example of the
|
||||
'real-time' and might not be the most efficient way.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<groovy:script location="..." refresh-check-delay="-1"/>]]></programlisting>
|
||||
|
||||
|
||||
Any negative number value means the script will never be refreshed after initial initialization of application context.
|
||||
DEFAULT BEHAVIOR
|
||||
|
||||
<important>Inline defined script can not be reloaded.</important>
|
||||
|
||||
</para>
|
||||
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,210 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="http">
|
||||
<title>HTTP Support</title>
|
||||
|
||||
<section id="http-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
The HTTP support allows for the execution of HTTP requests and the processing of inbound HTTP requests. Because interaction over HTTP is always synchronous, even if all that is returned is a 200 status code, the HTTP support consists of two gateway implementations:
|
||||
<classname>HttpInboundEndpoint</classname> and <classname>HttpRequestExecutingMessageHandler</classname>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="http-inbound">
|
||||
<title>Http Inbound Gateway</title>
|
||||
<para>
|
||||
To receive messages over HTTP you need to use an HTTP inbound Channel Adapter or Gateway. In common with the HttpInvoker
|
||||
support the HTTP inbound adapters need to be deployed within a servlet container. The easiest way to do this is to provide a servlet
|
||||
definition in <emphasis>web.xml</emphasis>, see
|
||||
<xref linkend="httpinvoker-inbound"/> for further details. Below is an example bean definition for a simple HTTP inbound endpoint.
|
||||
<programlisting language="xml"><![CDATA[<bean id="httpInbound" class="org.springframework.integration.http.HttpRequestHandlingMessagingGateway">
|
||||
<property name="requestChannel" ref="httpRequestChannel" />
|
||||
<property name="replyChannel" ref="httpReplyChannel" />
|
||||
</bean>]]></programlisting>
|
||||
The <classname>HttpRequestHandlingMessagingGateway</classname> accepts a list of <interfacename>HttpMessageConverter</interfacename> instances or else
|
||||
relies on a default list. The converters allow
|
||||
customization of the mapping from <interfacename>HttpServletRequest</interfacename> to <interfacename>Message</interfacename>. The default converters
|
||||
encapsulate simple strategies, which for
|
||||
example will create a String message for a <emphasis>POST</emphasis> request where the content type starts with "text", see the Javadoc for
|
||||
full details.
|
||||
</para>
|
||||
<para>Starting with this release MultiPart File support was implemented. If the request has been wrapped as a
|
||||
<emphasis>MultipartHttpServletRequest</emphasis>, when using the default converters, that request will be converted
|
||||
to a Message payload that is a MultiValueMap containing values that may be byte arrays, Strings, or instances of
|
||||
Spring's <interfacename>MultipartFile</interfacename> depending on the content type of the individual parts.
|
||||
<note>
|
||||
The HTTP inbound Endpoint will locate a MultipartResolver in the context if one exists with the bean name
|
||||
"multipartResolver" (the same name expected by Spring's DispatcherServlet). If it does in fact locate that
|
||||
bean, then the support for MultipartFiles will be enabled on the inbound request mapper. Otherwise, it will
|
||||
fail when trying to map a multipart-file request to a Spring Integration Message. For more on Spring's
|
||||
support for MultipartResolvers, refer to the <ulink url="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-multipart">Spring Reference Manual</ulink>.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
In sending a response to the client there are a number of ways to customize the behavior of the gateway. By default the gateway will
|
||||
simply acknowledge that the request was received by sending a 200 status code back. It is possible to customize this response by providing a
|
||||
'viewName' to be resolved by the Spring MVC <interfacename>ViewResolver</interfacename>.
|
||||
In the case that the gateway should expect a reply to the <interfacename>Message</interfacename> then setting the <property>expectReply</property> flag
|
||||
(constructor argument) will cause
|
||||
the gateway to wait for a reply <interfacename>Message</interfacename> before creating an HTTP response. Below is an example of a gateway
|
||||
configured to serve as a Spring MVC Controller with a view name. Because of the constructor arg value of TRUE, it wait for a reply. This also shows
|
||||
how to customize the HTTP methods accepted by the gateway, which
|
||||
are <emphasis>POST</emphasis> and <emphasis>GET</emphasis> by default.
|
||||
<programlisting language="xml"><![CDATA[<bean id="httpInbound" class="org.springframework.integration.http.HttpRequestHandlingController">
|
||||
<constructor-arg value="true" /> <!-- indicates that a reply is expected -->
|
||||
<property name="requestChannel" ref="httpRequestChannel" />
|
||||
<property name="replyChannel" ref="httpReplyChannel" />
|
||||
<property name="viewName" value="jsonView" />
|
||||
<property name="supportedMethodNames" >
|
||||
<list>
|
||||
<value>GET</value>
|
||||
<value>DELETE</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="expectReply" value="true" />
|
||||
</bean>]]></programlisting>
|
||||
The reply message will be available in the Model map. The key that is used
|
||||
for that map entry by default is 'reply', but this can be overridden by setting the
|
||||
'replyKey' property on the endpoint's configuration.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="http-outbound">
|
||||
<title>Http Outbound Gateway</title>
|
||||
|
||||
<para>
|
||||
To configure the <classname>HttpRequestExecutingMessageHandler</classname> write a bean definition like this:
|
||||
<programlisting language="xml"><![CDATA[<bean id="httpOutbound" class="org.springframework.integration.http.HttpRequestExecutingMessageHandler" >
|
||||
<constructor-arg value="http://localhost:8080/example" />
|
||||
<property name="outputChannel" ref="responseChannel" />
|
||||
</bean>]]></programlisting>
|
||||
This bean definition will execute HTTP requests by delegating to a <classname>RestTemplate</classname>. That template in turn delegates
|
||||
to a list of HttpMessageConverters to generate the HTTP request body from the Message payload. You can configure those converters as well
|
||||
as the ClientHttpRequestFactory instance to use:
|
||||
<programlisting language="xml"><![CDATA[<bean id="httpOutbound" class="org.springframework.integration.http.HttpRequestExecutingMessageHandler" >
|
||||
<constructor-arg value="http://localhost:8080/example" />
|
||||
<property name="outputChannel" ref="responseChannel" />
|
||||
<property name="messageConverters" ref="messageConverterList" />
|
||||
<property name="requestFactory" ref="customRequestFactory" />
|
||||
</bean>]]></programlisting>
|
||||
By default the HTTP request will be generated using an instance of <classname>SimpleClientHttpRequestFactory</classname> which uses the JDK
|
||||
<classname>HttpURLConnection</classname>. Use of the Apache Commons HTTP Client is also supported through the provided
|
||||
<classname>CommonsClientHttpRequestFactory</classname> which can be injected as shown above.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="http-namespace">
|
||||
<title>HTTP Namespace Support</title>
|
||||
<para>
|
||||
Spring Integration provides an "http" namespace and schema definition. To include it in your
|
||||
configuration, simply provide the following URI within a namespace declaration:
|
||||
'http://www.springframework.org/schema/integration/http'. The schema location should then map to
|
||||
'http://www.springframework.org/schema/integration/http/spring-integration-http.xsd'.
|
||||
</para>
|
||||
<para>
|
||||
To configure an inbound http channel adapter which is an instance of <classname>HttpInboundEndpoint</classname> configured
|
||||
not to expect a response.
|
||||
<programlisting language="xml"><![CDATA[ <http:inbound-channel-adapter id="httpChannelAdapter" channel="requests" supported-methods="PUT, DELETE"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure an inbound http gateway which expects a response.
|
||||
<programlisting language="xml"><![CDATA[ <http:inbound-gateway id="inboundGateway" request-channel="requests" reply-channel="responses"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure the outbound gateway you can use the namespace support as well. The following code snippet shows the different configuration options for an outbound Http gateway. Most importantly, notice that the 'http-method' and 'expected-response-type' are provided. Those are two of the most commonly configured values. The
|
||||
default http-method is POST, and the default response type is <emphasis>null</emphasis>. With a null response type, the payload of the reply Message would only
|
||||
contain the status code (e.g. 200) as long as it's a successful status (non-successful status codes will throw Exceptions). If you are expecting a different
|
||||
type, such as a <classname>String</classname>, then provide that fully-qualified class name as shown below.
|
||||
<programlisting language="xml"><![CDATA[<http:outbound-gateway id="example"
|
||||
request-channel="requests"
|
||||
url="http://localhost/test"
|
||||
http-method="POST"
|
||||
extract-request-payload="false"
|
||||
expected-response-type="java.lang.String"
|
||||
charset="UTF-8"
|
||||
request-factory="requestFactory"
|
||||
request-timeout="1234"
|
||||
reply-channel="replies"/>]]></programlisting>
|
||||
</para>
|
||||
<para>If your outbound adapter is to be used in a unidirectional way, then you can use an outbound-channel-adapter instead. This means that
|
||||
a successful response will simply execute without sending any Messages to a reply channel. In the case of any non-successful response
|
||||
status code, it will throw an exception. The configuration looks very similar to the gateway:
|
||||
<programlisting language="xml"><![CDATA[<http:outbound-channel-adapter id="example"
|
||||
url="http://localhost/example"
|
||||
http-method="GET"
|
||||
channel="requests"
|
||||
charset="UTF-8"
|
||||
extract-payload="false"
|
||||
expected-response-type="java.lang.String"
|
||||
request-factory="someRequestFactory"
|
||||
order="3"
|
||||
auto-startup="false"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="http-samples">
|
||||
<title>HTTP Samples</title>
|
||||
<section id="multipart-rest-inbound">
|
||||
<title>Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway (server)</title>
|
||||
<para>
|
||||
This example demonstrates how simple it is to send a Multipart HTTP request via Spring's RestTemplate and receive it by Spring Integration HTTP Inbound Adapter.
|
||||
All we are doing is creating <classname>MultiValueMap</classname> and populating it with multi-part data. <classname>RestTemplate</classname> will take care of the rest
|
||||
by converting it to <classname>MultipartHttpServletRequest</classname>
|
||||
THis particular client will send a multipart Http Request which contains the name of the company as well as the image file with company logo.
|
||||
<programlisting language="java"><![CDATA[RestTemplate template = new RestTemplate();
|
||||
String uri = "http://localhost:8080/multipart-http/inboundAdapter.htm";
|
||||
Resource s2logo =
|
||||
new ClassPathResource("org/springframework/integration/samples/multipart/spring09_logo.png");
|
||||
MultiValueMap map = new LinkedMultiValueMap();
|
||||
map.add("company", "SpringSource");
|
||||
map.add("company-logo", s2logo);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(new MediaType("multipart", "form-data"));
|
||||
HttpEntity request = new HttpEntity(map, headers);
|
||||
ResponseEntity<?> httpResponse = template.exchange(uri, HttpMethod.POST, request, null);]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
That is all for the client.
|
||||
</para>
|
||||
<para>
|
||||
On the server side we have the following configuration:
|
||||
<programlisting language="xml"><![CDATA[<int-http:inbound-channel-adapter id="httpInboundAdapter"
|
||||
channel="receiveChannel"
|
||||
name="/inboundAdapter.htm"
|
||||
supported-methods="GET, POST" />
|
||||
|
||||
<int:channel id="receiveChannel"/>
|
||||
|
||||
<int:service-activator input-channel="receiveChannel">
|
||||
<bean class="org.springframework.integration.samples.multipart.MultipartReceiever"/>
|
||||
</int:service-activator>
|
||||
|
||||
<bean id="multipartResolver"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The 'httpInboundAdapter' will receive the request, convert it to a <classname>Message</classname> with a payload as <classname>LinkedMultiValueMap</classname> which
|
||||
we are parsing in the 'multipartReceiver' service-activator;
|
||||
<programlisting language="java"><![CDATA[public void recieve(LinkedMultiValueMap<String, Object> multipartRequest){
|
||||
System.out.println("### Successfully recieved multipart request ###");
|
||||
for (String elementName : multipartRequest.keySet()) {
|
||||
if (elementName.equals("company")){
|
||||
System.out.println("\t" + elementName + " - " +
|
||||
((String[]) multipartRequest.getFirst("company"))[0]);
|
||||
} else if (elementName.equals("company-logo")){
|
||||
System.out.println("\t" + elementName + " - as UploadedMultipartFile: " +
|
||||
((UploadedMultipartFile) multipartRequest.getFirst("company-logo")).getOriginalFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
]]></programlisting>
|
||||
You should see the following output:
|
||||
<programlisting language="xml"><![CDATA[### Successfully recieved multipart request ###
|
||||
company - SpringSource
|
||||
company-logo - as UploadedMultipartFile: spring09_logo.png]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="httpinvoker">
|
||||
<title>HttpInvoker Support</title>
|
||||
|
||||
<section id="httpinvoker-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
HttpInvoker is a Spring-specific remoting option that essentially enables Remote Procedure Calls (RPC) over HTTP.
|
||||
In order to accomplish this, an outbound representation of a method invocation is serialized using standard Java
|
||||
serialization and then passed within an HTTP POST request. After being invoked on the target system, the method's
|
||||
return value is then serialized and written to the HTTP response. There are two main requirements. First, you
|
||||
must be using Spring on both sides since the marshalling to and from HTTP requests and responses is handled by
|
||||
the client-side invoker and server-side exporter. Second, the Objects that you are passing must implement
|
||||
<interfacename>Serializable</interfacename> and be available on both the client and server.
|
||||
</para>
|
||||
<para>
|
||||
While traditional RPC provides <emphasis>physical</emphasis> decoupling, it does not offer nearly the same degree
|
||||
of <emphasis>logical</emphasis> decoupling as a messaging-based system. In other words, both participants in an
|
||||
RPC-based invocation must be aware of a specific interface and specific argument types. Interestingly, in Spring
|
||||
Integration, the "parameter" being sent is a Spring Integration Message, and the interface is an internal detail
|
||||
of Spring Integration's implementation. Therefore, the RPC mechanism is being used as a
|
||||
<emphasis>transport</emphasis> so that from the end user's perspective, it is not necessary to consider the
|
||||
interface and argument types. It's just another adapter to enable messaging between two systems.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="httpinvoker-inbound">
|
||||
<title>HttpInvoker Inbound Gateway</title>
|
||||
<para>
|
||||
To receive messages over http you can use an <classname>HttpInvokerInboundGateway</classname>. Here is an
|
||||
example bean definition:
|
||||
<programlisting language="xml"><![CDATA[<bean id="inboundGateway"
|
||||
class="org.springframework.integration.httpinvoker.HttpInvokerInboundGateway">
|
||||
<property name="requestChannel" ref="requestChannel"/>
|
||||
<property name="replyChannel" ref="replyChannel"/>
|
||||
<property name="requestTimeout" value="30000"/>
|
||||
<property name="replyTimeout" value="10000"/>
|
||||
</bean>]]></programlisting>
|
||||
Because the inbound gateway must be able to receive HTTP requests, it must be configured within a Servlet
|
||||
container. The easiest way to do this is to provide a servlet definition in <emphasis>web.xml</emphasis>:
|
||||
<programlisting language="xml"><![CDATA[<servlet>
|
||||
<servlet-name>inboundGateway</servlet-name>
|
||||
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
|
||||
</servlet>]]></programlisting>
|
||||
Notice that the servlet name matches the bean name.
|
||||
<note>
|
||||
If you are running within a Spring MVC application and using the BeanNameHandlerMapping, then the servlet
|
||||
definition is not necessary. In that case, the bean name for your gateway can be matched against the URL
|
||||
path just like a Spring MVC Controller bean.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="httpinvoker-outbound">
|
||||
<title>HttpInvoker Outbound Gateway</title>
|
||||
<para>
|
||||
</para>
|
||||
<para>
|
||||
To configure the <classname>HttpInvokerOutboundGateway</classname> write a bean definition like this:
|
||||
<programlisting language="xml"><![CDATA[<bean id="outboundGateway"
|
||||
class="org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway">
|
||||
<property name="replyChannel" ref="replyChannel"/>
|
||||
</bean>]]></programlisting>
|
||||
The outbound gateway is a <interfacename>MessageHandler</interfacename> and can therefore be registered with
|
||||
either a <classname>PollingConsumer</classname> or <classname>EventDrivenConsumer</classname>.
|
||||
The URL must match that defined by an inbound HttpInvoker Gateway as described in the previous section.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="httpinvoker-namespace">
|
||||
<title>HttpInvoker Namespace Support</title>
|
||||
<para>
|
||||
Spring Integration provides an "httpinvoker" namespace and schema definition. To include it in your
|
||||
configuration, simply provide the following URI within a namespace declaration:
|
||||
'http://www.springframework.org/schema/integration/httpinvoker'. The schema location should then map to
|
||||
'http://www.springframework.org/schema/integration/httpinvoker/spring-integration-httpinvoker-2.0.xsd'.
|
||||
</para>
|
||||
<para>
|
||||
To configure the inbound gateway you can choose to use the namespace support for it. The following code snippet shows the different configuration options that are supported.
|
||||
<programlisting language="xml"><![CDATA[<httpinvoker:inbound-gateway id="inboundGateway"
|
||||
request-channel="requestChannel"
|
||||
request-timeout="10000"
|
||||
expect-reply="false"
|
||||
reply-timeout="30000"/>]]></programlisting>
|
||||
<note>
|
||||
A 'reply-channel' may also be provided, but it is recommended to rely on the temporary anonymous channel
|
||||
that will be created automatically for handling replies.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
To configure the outbound gateway you can use the namespace support as well. The following code snippet shows the different configuration for an outbound HttpInvoker gateway. Only the 'url' and 'request-channel' are required.
|
||||
<programlisting language="xml"><![CDATA[<httpinvoker:outbound-gateway id="outboundGateway"
|
||||
url="http://localhost:8080/example"
|
||||
request-channel="requestChannel"
|
||||
request-timeout="5000"
|
||||
reply-channel="replyChannel"
|
||||
reply-timeout="10000"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<book xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<bookinfo>
|
||||
<title>Spring Integration Reference Manual</title>
|
||||
<titleabbrev>Spring Integration &version;</titleabbrev>
|
||||
<productname>Spring Integration</productname>
|
||||
<releaseinfo>&version;</releaseinfo>
|
||||
|
||||
<!-- TODO: this isn't showing up. -->
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/logo.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/logo.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
<!-- END TODO -->
|
||||
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Mark</firstname>
|
||||
<surname>Fisher</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Marius</firstname>
|
||||
<surname>Bogoevici</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Iwein</firstname>
|
||||
<surname>Fuld</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Jonas</firstname>
|
||||
<surname>Partner</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Oleg</firstname>
|
||||
<surname>Zhurakousky</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Gary</firstname>
|
||||
<surname>Russell</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Josh</firstname>
|
||||
<surname>Long</surname>
|
||||
</author>
|
||||
</authorgroup>
|
||||
|
||||
<legalnotice><para>© SpringSource Inc., 2010</para></legalnotice>
|
||||
</bookinfo>
|
||||
|
||||
<toc></toc>
|
||||
|
||||
<xi:include href="./overview.xml"/>
|
||||
<xi:include href="./message.xml"/>
|
||||
<xi:include href="./channel.xml"/>
|
||||
<xi:include href="./endpoint.xml"/>
|
||||
<xi:include href="./service-activator.xml"/>
|
||||
<xi:include href="./channel-adapter.xml"/>
|
||||
<xi:include href="./router.xml"/>
|
||||
<xi:include href="./filter.xml"/>
|
||||
<xi:include href="./transformer.xml"/>
|
||||
<xi:include href="./splitter.xml"/>
|
||||
<xi:include href="./aggregator.xml"/>
|
||||
<xi:include href="./resequencer.xml"/>
|
||||
<xi:include href="./delayer.xml"/>
|
||||
<xi:include href="./chain.xml"/>
|
||||
<xi:include href="./bridge.xml"/>
|
||||
<xi:include href="./gateway.xml"/>
|
||||
<xi:include href="./message-publishing.xml"/>
|
||||
<xi:include href="./transactions.xml"/>
|
||||
<xi:include href="./message-history.xml"/>
|
||||
<xi:include href="./file.xml"/>
|
||||
<xi:include href="./jdbc.xml"/>
|
||||
<xi:include href="./jms.xml"/>
|
||||
<xi:include href="./ws.xml"/>
|
||||
<xi:include href="./rmi.xml"/>
|
||||
<xi:include href="./httpinvoker.xml"/>
|
||||
<xi:include href="./http.xml"/>
|
||||
<xi:include href="./ip.xml"/>
|
||||
<xi:include href="./mail.xml"/>
|
||||
<xi:include href="./jmx.xml"/>
|
||||
<xi:include href="./xmpp.xml"/>
|
||||
<xi:include href="./stream.xml"/>
|
||||
<xi:include href="./event.xml"/>
|
||||
<xi:include href="./xml.xml"/>
|
||||
<xi:include href="./security.xml"/>
|
||||
<xi:include href="./groovy.xml"/>
|
||||
<xi:include href="./samples.xml"/>
|
||||
<xi:include href="./configuration.xml"/>
|
||||
<xi:include href="./resources.xml"/>
|
||||
|
||||
</book>
|
||||
@@ -1,881 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="ip">
|
||||
<title>TCP and UDP Support</title>
|
||||
<para>
|
||||
Spring Integration provides Channel Adapters for receiving and sending messages over internet protocols. Both UDP
|
||||
(User Datagram Protocol)
|
||||
and TCP (Transmission Control Protocol) adapters are provided. Each adapter provides for one-way communication
|
||||
over the underlying protocol.
|
||||
In addition, simple inbound and outbound tcp gateways are provided. These are used when two-way communication is
|
||||
needed.
|
||||
</para>
|
||||
<section id="ip-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Two flavors each of UDP inbound and outbound adapters are provided <classname>UnicastSendingMessageHandler</classname>
|
||||
sends a datagram packet to a single destination. <classname>UnicastReceivingChannelAdapter</classname> receives
|
||||
incoming datagram packets. <classname>MulticastSendingMessageHandler</classname> sends (broadcasts) datagram packets to
|
||||
a multicast address. <classname>MulticastReceivingChannelAdapter</classname> receives incoming datagram packets
|
||||
by joining to a multicast address.
|
||||
</para>
|
||||
<para>
|
||||
TCP inbound and outbound adapters are provided <classname>TcpSendingMessageHandler</classname>
|
||||
sends messages over TCP. <classname>TcpReceivingChannelAdapter</classname> receives messages over TCP.
|
||||
</para>
|
||||
<para>
|
||||
An inbound TCP gateway is provided; this allows for simple request/response processing. While
|
||||
the gateway can support any number of connections, each connection can only process serially. The thread
|
||||
that reads from the socket waits for, and sends, the response before reading again. If the connection factory
|
||||
is configured for single use connections, the connection is closed after the socket times out.
|
||||
</para>
|
||||
<para>
|
||||
An outbound TCP gateway is provided; this allows for simple request/response processing.
|
||||
If the associated connection factory is configured for single use connections, a new connection is
|
||||
immediately created for each new request. Otherwise, if the connection is in use,
|
||||
the calling thread blocks on the connection until either a response is received or a timeout
|
||||
or I/O error occurs.
|
||||
</para>
|
||||
</section>
|
||||
<section id="udp-adapters">
|
||||
<title>UDP Adapters</title>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[ <ip:udp-outbound-channel-adapter id="udpOut"
|
||||
host="somehost"
|
||||
port="11111"
|
||||
multicast="false"
|
||||
channel="exampleChannel" />]]></programlisting>
|
||||
A simple UDP outbound channel adapter.
|
||||
<tip>
|
||||
When setting multicast to true, provide the multicast address in the host
|
||||
attribute.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
UDP is an efficient, but unreliable protocol. Two attributes are added to improve reliability. When check-length is
|
||||
set to true, the adapter precedes the message data with a length field (4 bytes in network byte order). This enables
|
||||
the receiving side to verify the length of the packet received. If a receiving system uses a buffer that is too
|
||||
short the contain the packet, the packet can be truncated. The length header provides a mechanism to detect this.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[ <ip:udp-outbound-channel-adapter id="udpOut"
|
||||
host="somehost"
|
||||
port="11111"
|
||||
multicast="false"
|
||||
check-length="true"
|
||||
channel="exampleChannel" />]]></programlisting>
|
||||
An outbound channel adapter that adds length checking to the datagram packets.
|
||||
<tip>
|
||||
The recipient of the packet must also be configured to expect a length to precede the
|
||||
actual data. For a Spring Integration UDP inbound channel adapter, set its
|
||||
<classname>check-length</classname> attribute.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
The second reliability improvement allows an application-level acknowledgment protocol to be used. The receiver
|
||||
must send an acknowledgment to the sender within a specified time.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[ <ip:udp-outbound-channel-adapter id="udpOut"
|
||||
host="somehost"
|
||||
port="11111"
|
||||
multicast="false"
|
||||
check-length="true"
|
||||
acknowledge="true"
|
||||
ack-host="thishost"
|
||||
ack-port="22222"
|
||||
ack-timeout="10000"
|
||||
channel="exampleChannel" />]]></programlisting>
|
||||
An outbound channel adapter that adds length checking to the datagram packets and waits for an acknowledgment.
|
||||
<tip>
|
||||
Setting acknowledge to true implies the recipient of the packet can interpret the header added to the packet
|
||||
containing acknowledgment data (host and port). Most likely, the recipient will be a Spring Integration inbound
|
||||
channel adapter.
|
||||
</tip>
|
||||
<tip>
|
||||
When multicast is true, an additional attribute min-acks-for-success specifies
|
||||
how many acknowledgments must be received within the ack-timeout.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
For even more reliable networking, TCP can be used.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[ <ip:udp-inbound-channel-adapter id="udpReceiver"
|
||||
channel="udpOutChannel"
|
||||
port="11111"
|
||||
receive-buffer-size="500"
|
||||
multicast="false"
|
||||
check-length="true" />]]></programlisting>
|
||||
A basic unicast inbound udp channel adapter.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[ <ip:udp-inbound-channel-adapter id="udpReceiver"
|
||||
channel="udpOutChannel"
|
||||
port="11111"
|
||||
receive-buffer-size="500"
|
||||
multicast="true"
|
||||
multicast-address="225.6.7.8"
|
||||
check-length="true" />]]></programlisting>
|
||||
A basic multicast inbound udp channel adapter.
|
||||
</para>
|
||||
</section>
|
||||
<section id="connection-factories">
|
||||
<title>TCP Connection Factories</title>
|
||||
<para>
|
||||
For TCP, the configuration of the underlying connection is provided using a
|
||||
Connection Factory. Two types of connection factory are provided; a
|
||||
client connection factory and a server connection factory. Client connection
|
||||
factories are used to establish outgoing connections; Server connection factories
|
||||
listen for incoming connections.
|
||||
</para>
|
||||
<para>
|
||||
A client connection factory is used
|
||||
by an outbound channel adapter but a reference to a client connection factory
|
||||
can also be provided to an inbound channel adapter and that adapter will receive
|
||||
any incoming messages received on connections created by the outbound adapter.
|
||||
</para>
|
||||
<para>
|
||||
A server connection factory is used by an inbound channel adapter or gateway (in fact
|
||||
the connection factory will not function without one). A reference to a server
|
||||
connection factory can also be provided to an outbound adapter; that adapter
|
||||
can then be used to send replies to incoming messages to the same connection.
|
||||
<tip>Reply messages will only be routed to the connection if the reply contains
|
||||
the header $ip_connection_id that was inserted into the original message by
|
||||
the connection factory.</tip>
|
||||
<tip>This is the extent of message correlation performed when sharing connection
|
||||
factories between inbound and outbound adapters. Such sharing allows for
|
||||
asynchronous two-way communication over TCP. Only payload information is
|
||||
transferred using TCP; therefore any message correlation must be performed
|
||||
by downstream components such as aggregators or other endpoints.</tip>
|
||||
</para>
|
||||
<para>
|
||||
A maximum of one adapter of each type may be given a reference to a connection
|
||||
factory.
|
||||
</para>
|
||||
<para>
|
||||
Connection factories using <classname>java.net.Socket</classname> and
|
||||
<classname>java.nio.channel.SocketChannel</classname> are provided.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="1234"
|
||||
/>]]></programlisting>
|
||||
A simple server connection factory that uses <classname>java.net.Socket</classname>
|
||||
connections.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="1234"
|
||||
using-nio="true"
|
||||
/>]]></programlisting>
|
||||
A simple server connection factory that uses <classname>java.nio.channel.SocketChannel</classname>
|
||||
connections.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="1234"
|
||||
single-use="true"
|
||||
so-timeout="10000"
|
||||
/>]]></programlisting>
|
||||
A client connection factory that uses <classname>java.net.Socket</classname>
|
||||
connections and creates a new connection for each message.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="1234"
|
||||
single-use="true"
|
||||
so-timeout="10000"
|
||||
using-nio=true
|
||||
/>]]></programlisting>
|
||||
A client connection factory that uses <classname>java.nio.channel.Socket</classname>
|
||||
connections and creates a new connection for each message.
|
||||
</para>
|
||||
<para>
|
||||
TCP is a streaming protocol; this means that some structure has to be provided to data
|
||||
transported over TCP, so the receiver can demarcate the data into discrete messages.
|
||||
Connection factories are configured to use (de)serializers to convert between the message
|
||||
payload and the bits that are sent over TCP. This is accomplished by providing a
|
||||
deserializer and serializer for inbound and outbound messages respectively.
|
||||
Four standard (de)serializers are provided; the first is <classname>ByteArrayCrlfSerializer</classname>,
|
||||
which can convert a byte array to a stream of bytes followed by carriage
|
||||
return and linefeed characters (\r\n). This is the default (de)serializer and can be used with
|
||||
telnet as a client, for example. The second is is <classname>ByteArrayStxEtxSerializer</classname>,
|
||||
which can convert a byte array to a stream of bytes preceded by an STX (0x02) and
|
||||
followed by an ETX (0x03). The third is <classname>ByteArrayLengthHeaderSerializer</classname>,
|
||||
which can convert a byte array to a stream of bytes preceded by a 4 byte binary
|
||||
length in network byte order. Each of these is a subclass of
|
||||
<classname>AbstractByteArraySerializer</classname> which implements both
|
||||
<classname>org.springframework.core.serializer.Serializer</classname> and
|
||||
<classname>org.springframework.core.serializer.Deserializer</classname>.
|
||||
For backwards compatibility, connections using any subclass of
|
||||
<classname>AbstractByteArraySerializer</classname> for serialization
|
||||
will also accept a String which will be converted to a byte array first.
|
||||
Each of these (de)serializers converts an input stream containing the
|
||||
corresponding format to a byte array payload. The fourth standard serializer is
|
||||
<classname>org.springframework.core.serializer.DefaultSerializer</classname> which can be
|
||||
used to convert Serializable objects using java serialization.
|
||||
<classname>org.springframework.core.serializer.DefaultDeserializer</classname> is provided for
|
||||
inbound deserialization of streams containing Serializable objects.
|
||||
To implement a custom (de)serializer pair, implement the
|
||||
<classname>org.springframework.core.serializer.Deserializer</classname> and
|
||||
<classname>org.springframework.core.serializer.Serializer</classname> interfaces. If you do not wish to use
|
||||
the default (de)serializer (<classname>ByteArrayCrLfSerializer</classname>), you must supply
|
||||
<classname>serializer</classname> and
|
||||
<classname>deserializer</classname> attributes on the connection factory (example below).
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<bean id="javaSerializer"
|
||||
class="org.springframework.core.serializer.DefaultSerializer" />
|
||||
<bean id="javaDeserializer"
|
||||
class="org.springframework.core.serializer.DefaultDeserializer" />
|
||||
|
||||
<ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="1234"
|
||||
deserializer="JavaDeserializer"
|
||||
serializer="javaSerializer"
|
||||
/>]]></programlisting>
|
||||
A server connection factory that uses <classname>java.net.Socket</classname>
|
||||
connections and uses Java serialization on the wire.
|
||||
</para>
|
||||
<para>
|
||||
For full details of the attributes available on connection factories, see the
|
||||
reference at the end of this section.
|
||||
</para>
|
||||
</section>
|
||||
<section id="ip-interceptors">
|
||||
<title>Tcp Connection Interceptors</title>
|
||||
<para>
|
||||
Connection factories can be configured with a reference to a
|
||||
<classname>TcpConnectionInterceptorFactoryChain</classname>. Interceptors can be used
|
||||
to add behavior to connections, such as negotiation, security, and other setup.
|
||||
No interceptors are currently provided by the framework but, for an example,
|
||||
see the <classname>InterceptedSharedConnectionTests</classname> in the source
|
||||
repository.
|
||||
</para>
|
||||
<para>
|
||||
The <classname>HelloWorldInterceptor</classname> used in the test case works as follows:
|
||||
</para>
|
||||
<para>
|
||||
When configured with a client connection factory,
|
||||
when the first message is sent over a connection that is intercepted, the interceptor
|
||||
sends 'Hello' over the connection, and expects to receive 'world!'. When that occurs,
|
||||
the negotiation is complete and the original message is sent; further messages
|
||||
that use the same connection are sent without any additional negotiation.
|
||||
</para>
|
||||
<para>
|
||||
When configured with a server connection factory, the interceptor requires the first
|
||||
message to be 'Hello' and, if it is, returns 'world!'. Otherwise it throws an exception causing
|
||||
the connection to be closed.
|
||||
</para>
|
||||
<para>
|
||||
All <classname>TcpConnection</classname> methods are intercepted.
|
||||
Interceptor instances are created for each connection by an interceptor factory.
|
||||
If an interceptor is stateful, the factory should create a new instance for each connection.
|
||||
Interceptor
|
||||
factories are added to the configuration of an interceptor factory chain, which is provided
|
||||
to a connection factory using the <classname>interceptor-factory</classname> attribute.
|
||||
Interceptors must implement the <classname>TcpConnectionInterceptor</classname> interface;
|
||||
factories
|
||||
must implement the <classname>TcpConnectionInterceptorFactory</classname> interface. A
|
||||
convenience class <classname>AbstractTcpConnectionInterceptor</classname> is provided
|
||||
with passthrough methods; by extending this class, you only need to implement those
|
||||
methods you wish to intercept.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<bean id="helloWorldInterceptorFactory"
|
||||
class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain">
|
||||
<property name="interceptors">
|
||||
<array>
|
||||
<bean class="org.springframework.integration.ip.tcp.connection.HelloWorldInterceptorFactory"/>
|
||||
</array>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<int-ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="12345"
|
||||
using-nio="true"
|
||||
single-use="true"
|
||||
interceptor-factory-chain="helloWorldInterceptorFactory"
|
||||
/>
|
||||
|
||||
<int-ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="12345"
|
||||
single-use="true"
|
||||
so-timeout="100000"
|
||||
using-nio="true"
|
||||
interceptor-factory-chain="helloWorldInterceptorFactory"
|
||||
/>]]></programlisting>
|
||||
Configuring a connection interceptor factory chain.
|
||||
</para>
|
||||
</section>
|
||||
<section id="tcp-adapters">
|
||||
<title>TCP Adapters</title>
|
||||
<para>
|
||||
TCP inbound and outbound channel adapters that utilize the above connection
|
||||
factories are provided. These adapters have just 2 attributes
|
||||
<classname>connection-factory</classname> and <classname>channel</classname>.
|
||||
The channel attribute specifies the channel on which messages arrive at an
|
||||
outbound adapter and on which messages are placed by an inbound adapter.
|
||||
The connection-factory attribute indicates which connection factory is to be used to
|
||||
manage connections for the adapter. While both inbound and outbound adapters
|
||||
can share a connection factory, server connection factories are always 'owned'
|
||||
by an inbound adapter; client connection factories are always 'owned' by an
|
||||
outbound adapter. One, and only one, adapter of each type may get a reference
|
||||
to a connection factory.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<bean id="javaSerializer"
|
||||
class="org.springframework.core.serializer.DefaultSerializer" />
|
||||
<bean id="javaDeserializer"
|
||||
class="org.springframework.core.serializer.DefaultDeserializer" />
|
||||
|
||||
<int-ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="1234"
|
||||
deserializer="javaDeserializer"
|
||||
serializer="javaSerializer"
|
||||
using-nio="true"
|
||||
single-use="true"
|
||||
/>
|
||||
|
||||
<int-ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="#{server.port}"
|
||||
single-use="true"
|
||||
so-timeout="10000"
|
||||
deserializer="javaDeserializer"
|
||||
serializer="javaSerializer"
|
||||
/>
|
||||
|
||||
<int:channel id="input" />
|
||||
|
||||
<int:channel id="replies">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-ip:tcp-outbound-channel-adapter id="outboundClient"
|
||||
channel="input"
|
||||
connection-factory="client"/>
|
||||
|
||||
<int-ip:tcp-inbound-channel-adapter id="inboundClient"
|
||||
channel="replies"
|
||||
connection-factory="client"/>
|
||||
|
||||
<int-ip:tcp-inbound-channel-adapter id="inboundServer"
|
||||
channel="loop"
|
||||
connection-factory="server"/>
|
||||
|
||||
<int-ip:tcp-outbound-channel-adapter id="outboundServer"
|
||||
channel="loop"
|
||||
connection-factory="server"/>
|
||||
|
||||
<int:channel id="loop" />]]></programlisting>
|
||||
In this configuration, messages arriving in channel 'input'
|
||||
are serialized over connections created by 'client' received
|
||||
at the server and placed on channel 'loop'. Since 'loop' is
|
||||
the input channel for 'outboundServer' the message is simply
|
||||
looped back over the same connection and received by
|
||||
'inboundClient' and deposited in channel 'replies'. Java
|
||||
serialization is used on the wire.
|
||||
</para>
|
||||
</section>
|
||||
<section id="tcp-gateways">
|
||||
<title>TCP Gateways</title>
|
||||
<para>
|
||||
The inbound TCP gateway <classname>TcpInboundGateway</classname>
|
||||
and oubound TCP gateway <classname>TcpOutboundGateway</classname>
|
||||
use a server and client connection factory respectively. Each connection
|
||||
can process a single request/response at a time.
|
||||
</para>
|
||||
<para>
|
||||
The intbound gateway, after constructing a message with the incoming payload and sending
|
||||
it to the requestChannel, waits for a response and sends the payload
|
||||
from the response message by writing it to the connection.
|
||||
</para>
|
||||
<para>
|
||||
The outbound gateway, after sending a message over the connection, waits for a response and
|
||||
constructs a response message and puts in on the reply channel.
|
||||
Communications over the connections are single-threaded. Users should be aware that only one
|
||||
message can be handled at a time and, if another thread attempts to send
|
||||
a message before the current response has been received, it will block until
|
||||
any previous requests are complete (or time out).
|
||||
If, however, the client connection factory is configured for single-use connections
|
||||
each new request gets its own connection and is processed immediately.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-inbound-gateway id="inGateway"
|
||||
request-channel="tcpChannel"
|
||||
reply-channel="replyChannel"
|
||||
connection-factory="cfServer"
|
||||
reply-timeout="10000"
|
||||
/>]]></programlisting>
|
||||
A simple inbound TCP gateway; if a connection factory configured with the default
|
||||
(de)serializer is used, messages will be \r\n delimited data and the gateway can be
|
||||
used by a simple client such as telnet.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<ip:tcp-outbound-gateway id="outGateway"
|
||||
request-channel="tcpChannel"
|
||||
reply-channel="replyChannel"
|
||||
connection-factory="cfClient"
|
||||
request-timeout="10000"
|
||||
reply-timeout="10000"
|
||||
/>]]></programlisting>
|
||||
A simple oubound TCP gateway.
|
||||
</para>
|
||||
</section>
|
||||
<section id="ip-endpoint-reference">
|
||||
<title>IP Configuration Attributes</title>
|
||||
<para>
|
||||
<table id="connection-factory-attributes">
|
||||
<title>Connection Factory Attributes</title>
|
||||
<tgroup cols="5">
|
||||
<colspec align="left" />
|
||||
<colspec colnum="1" colname="col1" colwidth="1*"/>
|
||||
<colspec colnum="2" colname="col2" colwidth="0.4*" align="center"/>
|
||||
<colspec colnum="3" colname="col3" colwidth="0.4*" align="center"/>
|
||||
<colspec colnum="4" colname="col4" colwidth="1*"/>
|
||||
<colspec colnum="5" colname="col5" colwidth="2*"/>
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Attribute Name</entry>
|
||||
<entry align="center">Client?</entry>
|
||||
<entry align="center">Server?</entry>
|
||||
<entry align="center">Allowed Values</entry>
|
||||
<entry align="center">Attribute Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>type</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>client, server</entry>
|
||||
<entry>Determines whether the connection factory is a client or server.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>host</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>N</entry>
|
||||
<entry></entry>
|
||||
<entry>The host name or ip address of the destination.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>port</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>The port.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>serializer</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>An implementation of <classname>Serializer</classname> used to serialize
|
||||
the payload. Defaults to <classname>ByteArrayCrLfSerializer</classname></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>deserializer</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>An implementation of <classname>Deserializer</classname> used to deserialize
|
||||
the payload. Defaults to <classname>ByteArrayCrLfSerializer</classname></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>using-nio</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not the tcp adapter is using NIO. Refer to the java.nio
|
||||
package for more information. Default false.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>using-direct-buffers</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>N</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>When using NIO, whether or not the tcp adapter uses direct buffers.
|
||||
Refer to <classname>java.nio.ByteBuffer</classname> documentation for
|
||||
more information. Must be false if using-nio is false. </entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-timeout</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.Socket</classname>
|
||||
setSoTimeout() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-send-buffer-size</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.Socket</classname>
|
||||
setSendBufferSize() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-receive-buffer- size</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.Socket</classname>
|
||||
setReceiveBufferSize() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-keep-alive</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>See <classname>java.net.Socket. setKeepAlive()</classname>.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-linger</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>Sets linger to true with supplied value.
|
||||
See <classname>java.net.Socket. setSoLinger()</classname>.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-tcp-no-delay</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>See <classname>java.net.Socket. setTcpNoDelay()</classname>.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-traffic-class</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.Socket. setTrafficClass()</classname>.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>local-address</entry>
|
||||
<entry>N</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>On a multi-homed system, specifies an IP address
|
||||
for the interface to which the socket will be bound.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>task-executor</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>
|
||||
Specifies a specific Executor to be used for socket handling. If not supplied, an internal
|
||||
pooled executor will be used. Needed on some platforms that require the use of specific
|
||||
task executors such as a WorkManagerTaskExecutor. See pool-size for thread
|
||||
requirements, depending on other options.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>single-use</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Specifies whether a connection can be used for multiple messages.
|
||||
If true, a new connection will be used for each message.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>pool-size</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>Specifies the concurrency. For tcp, not using nio, specifies the
|
||||
number of concurrent connections supported by the adapter. For tcp,
|
||||
using nio, specifies the number of tcp fragments that are concurrently
|
||||
reassembled into complete messages.
|
||||
It only applies in this sense if task-executor is not configured.
|
||||
However, pool-size is also used for the server socket backlog,
|
||||
regardless of whether an external task executor is used. Defaults to 5.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>interceptor-factory-chain</entry>
|
||||
<entry>Y</entry>
|
||||
<entry>Y</entry>
|
||||
<entry></entry>
|
||||
<entry>Documentation to be supplied.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<table id="ip-ob-adapter-attributes">
|
||||
<title>UDP Outbound Channel Adapter Attributes</title>
|
||||
<tgroup cols="3">
|
||||
<colspec align="left" />
|
||||
<colspec colnum="1" colname="col1" colwidth="1*"/>
|
||||
<colspec colnum="2" colname="col4" colwidth="1*"/>
|
||||
<colspec colnum="3" colname="col5" colwidth="2*"/>
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Attribute Name</entry>
|
||||
<entry align="center">Allowed Values</entry>
|
||||
<entry align="center">Attribute Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>host</entry>
|
||||
<entry></entry>
|
||||
<entry>The host name or ip address of the destination. For multicast udp
|
||||
adapters, the multicast address.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>port</entry>
|
||||
<entry></entry>
|
||||
<entry>The port on the destination.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>multicast</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not the udp adapter uses multicast.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>acknowledge</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not a udp adapter requires an acknowledgment from the destination.
|
||||
when enabled, requires setting the following 4 attributes.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>ack-host</entry>
|
||||
<entry></entry>
|
||||
<entry>When acknowledge is true, indicates the host or ip address to which the
|
||||
acknowledgment should be sent. Usually the current host, but may be
|
||||
different, for example when Network Address Transation (NAT) is
|
||||
being used.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>ack-port</entry>
|
||||
<entry></entry>
|
||||
<entry>When acknowledge is true, indicates the port to which the
|
||||
acknowledgment should be sent. The adapter listens on this port for
|
||||
acknowledgments.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>ack-timeout</entry>
|
||||
<entry></entry>
|
||||
<entry>When acknowledge is true, indicates the time in milliseconds that the
|
||||
adapter will wait for an acknowlegment. If an acknowlegment is not
|
||||
received in time, the adapter will throw an exception.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>min-acks-for- success</entry>
|
||||
<entry></entry>
|
||||
<entry>Defaults to 1. For multicast adapters, you can set this to a larger
|
||||
value, requiring acknowlegments from multiple destinations.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>check-length</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not a udp adapter includes a data length field in the
|
||||
packet sent to the destination.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>time-to-live</entry>
|
||||
<entry></entry>
|
||||
<entry>For multicast adapters, specifies the time to live attribute for
|
||||
the <classname>MulticastSocket</classname>; controls the scope
|
||||
of the multicasts. Refer to the Java API
|
||||
documentation for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-timeout</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.DatagramSocket</classname>
|
||||
setSoTimeout() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-send-buffer-size</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.DatagramSocket</classname>
|
||||
setSendBufferSize() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-receive-buffer- size</entry>
|
||||
<entry></entry>
|
||||
<entry>Used for udp acknowlegment packets. See <classname>java.net.DatagramSocket</classname>
|
||||
setReceiveBufferSize() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>local-address</entry>
|
||||
<entry></entry>
|
||||
<entry>On a multi-homed system, for the UDP adapter, specifies an IP address
|
||||
for the interface to which the socket will be bound for reply messages.
|
||||
For a multicast adapter it is also used to determine which interface
|
||||
the multicast packets will be sent over.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>task-executor</entry>
|
||||
<entry></entry>
|
||||
<entry>
|
||||
Specifies a specific Executor to be used for acknowledgment handling. If not supplied, an internal
|
||||
single threaded executor will be used. Needed on some platforms that require the use of specific
|
||||
task executors such as a WorkManagerTaskExecutor. One thread will be dedicated to handling
|
||||
acknowledgments (if the acknowledge option is true).</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<table id="ip-ib-adapter-attributes">
|
||||
<title>UDP Inbound Channel Adapter Attributes</title>
|
||||
<tgroup cols="3">
|
||||
<colspec align="left" />
|
||||
<colspec colnum="1" colname="col1" colwidth="1*"/>
|
||||
<colspec colnum="2" colname="col4" colwidth="1*"/>
|
||||
<colspec colnum="3" colname="col5" colwidth="2*"/>
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Attribute Name</entry>
|
||||
<entry align="center">Allowed Values</entry>
|
||||
<entry align="center">Attribute Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>port</entry>
|
||||
<entry></entry>
|
||||
<entry>The port on which the adapter listens.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>multicast</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not the udp adapter uses multicast.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>multicast-address</entry>
|
||||
<entry></entry>
|
||||
<entry>When multicast is true, the multicast address to which the adapter
|
||||
joins.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>pool-size</entry>
|
||||
<entry></entry>
|
||||
<entry>Specifies the concurrency. Specifies how many packets can
|
||||
be handled concurrently.
|
||||
It only applies if task-executor is not configured.
|
||||
Defaults to 5.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>task-executor</entry>
|
||||
<entry></entry>
|
||||
<entry>
|
||||
Specifies a specific Executor to be used for socket handling. If not supplied, an internal
|
||||
pooled executor will be used. Needed on some platforms that require the use of specific
|
||||
task executors such as a WorkManagerTaskExecutor. See pool-size for thread
|
||||
requirements.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>receive-buffer-size</entry>
|
||||
<entry></entry>
|
||||
<entry>The size of the buffer used to receive DatagramPackets.
|
||||
Usually set to the MTU size. If a smaller buffer is used than the
|
||||
size of the sent packet, truncation can occur. This can be detected
|
||||
by means of the check-length attribute..</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>check-length</entry>
|
||||
<entry>true, false</entry>
|
||||
<entry>Whether or not a udp adapter expects a data length field in the
|
||||
packet received. Used to detect packet truncation.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-timeout</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.DatagramSocket</classname>
|
||||
setSoTimeout() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-send-buffer-size</entry>
|
||||
<entry></entry>
|
||||
<entry>Used for udp acknowlegment packets. See <classname>java.net.DatagramSocket</classname>
|
||||
setSendBufferSize() methods for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>so-receive-buffer- size</entry>
|
||||
<entry></entry>
|
||||
<entry>See <classname>java.net.DatagramSocket</classname>
|
||||
setReceiveBufferSize() for more information.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>local-address</entry>
|
||||
<entry></entry>
|
||||
<entry>On a multi-homed system, specifies an IP address
|
||||
for the interface to which the socket will be bound.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<table id="tcp-ib-gateway-attributes">
|
||||
<title>TCP Inbound Gateway Attributes</title>
|
||||
<tgroup cols="3">
|
||||
<colspec align="left" />
|
||||
<colspec colnum="1" colname="col1" colwidth="1*"/>
|
||||
<colspec colnum="2" colname="col2" colwidth="1*"/>
|
||||
<colspec colnum="3" colname="col3" colwidth="3*"/>
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Attribute Name</entry>
|
||||
<entry align="left">Allowed Values</entry>
|
||||
<entry align="center">Attribute Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>port</entry>
|
||||
<entry></entry>
|
||||
<entry>The port on which the gateway listens.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<table id="tcp-ob-gateway-attributes">
|
||||
<title>TCP Outbound Gateway Attributes</title>
|
||||
<tgroup cols="3">
|
||||
<colspec align="left" />
|
||||
<colspec colnum="1" colname="col1" colwidth="1*"/>
|
||||
<colspec colnum="2" colname="col2" colwidth="1*"/>
|
||||
<colspec colnum="3" colname="col3" colwidth="3*"/>
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Attribute Name</entry>
|
||||
<entry align="left">Allowed Values</entry>
|
||||
<entry align="center">Attribute Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>host</entry>
|
||||
<entry></entry>
|
||||
<entry>The host name or ip address of the destination.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,225 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="jdbc">
|
||||
<title>JDBC Support</title>
|
||||
|
||||
<para>Spring Integration provides Channel Adapters for receiving and sending
|
||||
messages via database queries.</para>
|
||||
|
||||
<section id="jdbc-inbound-channel-adapter">
|
||||
<title>Inbound Channel Adapter</title>
|
||||
|
||||
<para>The main function of an inbound Channel Adapter is to execute a SQL
|
||||
<code>SELECT</code> query and turn the result set into a message. The
|
||||
message payload is the whole result set, expressed as a
|
||||
<classname>List</classname>, and the types of the items in the list
|
||||
depends on the row-mapping strategy that is used. The default strategy is
|
||||
a generic mapper that just returns a <classname>Map</classname> for each
|
||||
row i nthe query. Optionally this can be changed by adding a reference to
|
||||
requires a reference to a <classname>RowMapper</classname> instance (see
|
||||
the <ulink
|
||||
url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html">Spring
|
||||
JDBC</ulink> documentation for more detailed information about row
|
||||
mapping).<note>
|
||||
<para>If you want to convert rows in the SELECT query result to
|
||||
individual messages you can use a downstream splitter.</para>
|
||||
</note></para>
|
||||
|
||||
<para>The inbound adapter also requires a reference to either
|
||||
<classname>JdbcTemplate</classname> instance or
|
||||
<interfacename>DataSource</interfacename>.</para>
|
||||
|
||||
<para>As well as the <code>SELECT</code> statement to generate the
|
||||
messages, the adapter above also has an <code>UPDATE</code> statement that
|
||||
is being used to mark the records as processed, so they don't show up in
|
||||
the next poll. The update can be parameterised by the list of ids from the
|
||||
original select. This is done through a naming convention by default (a
|
||||
column in the input result set called "id" is translated into a list in
|
||||
the parameter map for the update called "id"). The following example
|
||||
defines an inbound Channel Adapter with an update query and a
|
||||
<classname>DataSource</classname> reference. <programlisting
|
||||
language="xml"><jdbc:inbound-channel-adapter query="select * from item where status=2"
|
||||
channel="target" data-source="dataSource"
|
||||
update="update item set status=10 where id in (:id)" /></programlisting>
|
||||
<note>
|
||||
The parameters in the update query are specified with a colon (:) prefix to the name of a parameter (which in this case is an expression to be applied to each of the rows in the polled result set). This is a standard feature of the named parameter JDBC support in Spring JDBC combined with a convention (projection onto the polled result list) adopted in Spring Integration. The underlying Spring JDBC features limit the available expressions (e.g. most special characters other than period are disallowed), but since the target is usually a list of or an individual object addressable by simple bean paths this isn't unduly restrictive.
|
||||
</note> To change the parameter generation strategy you can inject a
|
||||
<classname>SqlParameterSourceFactory</classname> into the adapter to
|
||||
override the default behaviour (the adapter has a
|
||||
<code>sql-parameter-source-factory</code> attribute).</para>
|
||||
|
||||
<section>
|
||||
<title>Polling and Transactions</title>
|
||||
|
||||
<para>The inbound adapter accepts a regular Spring Integration poller as
|
||||
a sub element, so for instance the frequency of the polling can be
|
||||
controlled. A very important feature of the poller for JDBC usage is the
|
||||
option to wrap the poll operation in a transaction, for example:</para>
|
||||
|
||||
<programlisting><jdbc:inbound-channel-adapter query="..."
|
||||
channel="target" data-source="dataSource"
|
||||
update="...">
|
||||
<poller fixed-rate"1000">
|
||||
<transactional/>
|
||||
</poller>
|
||||
</jdbc:inbound-channel-adapter></programlisting>
|
||||
|
||||
<para><note>
|
||||
If a poller is not explicitly specified a default value will be used (and as per normal with Spring Integration can be defined as a top level bean)
|
||||
</note> In this example the database is polled every 1000
|
||||
milliseconds, and the update and select queries are both executed in the
|
||||
same transaction. The transaction manager configuration is not shown,
|
||||
but as long as it is aware of the data source then the poll is
|
||||
transactional. A common use case is for the downstream channels to be
|
||||
direct channels (the default), so that the endpoints are invoked in the
|
||||
same thread, and hence the same transaction. then if any of them fails,
|
||||
the transaction rolls back and the input data are reverted to their
|
||||
original state.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="jdbc-outbound-channel-adapter">
|
||||
<title>Outbound Channel Adapter</title>
|
||||
|
||||
<para>The outbound Channel Adapter is the inverse of the inbound: its role
|
||||
is to handle a message and use it to execute a SQL query. The message
|
||||
payload and headers are available by default as input parameters to the
|
||||
query, for instance: <programlisting language="xml"><jdbc:outbound-channel-adapter
|
||||
query="insert into foos (id, status, name) values (:headers[$id], 0, :payload[foo])"
|
||||
channel="input" data-source="dataSource"/></programlisting> In the
|
||||
example above, messages arriving on the channel "input" have a payload of
|
||||
a map with key "foo", so the <code>[]</code> operator dereferences that
|
||||
value from the map. The headers are also accessed as a map. <note>
|
||||
The parameters in the query above are bean property expressions on the incoming message (not Spring EL expressions). This behaviour is part of the
|
||||
|
||||
<classname>SqlParameterSource</classname>
|
||||
|
||||
which is the default source created by the outbound adapter. Other behaviour is possible in the adapter, and requires the user to inject a different
|
||||
|
||||
<classname>SqlParameterSourceFactory</classname>
|
||||
|
||||
.
|
||||
</note></para>
|
||||
|
||||
<para>The outbound adapter requires a reference to either a DataSource or
|
||||
a JdbcTemplate. It can also have a
|
||||
<classname>SqlParameterSourceFactory</classname> injected to control the
|
||||
binding of incoming message to the query.</para>
|
||||
|
||||
<para>If the input channel is a direct channel then the outbound adapter
|
||||
runs its query in the same thread, and therefor ethe same transaction (if
|
||||
there is one) as the sender of the message.</para>
|
||||
</section>
|
||||
|
||||
<section id="jdbc-outbound-gateway">
|
||||
<title>Outbound Gateway</title>
|
||||
|
||||
<para>The outbound Gateway is like a combination of the outbound and
|
||||
inbound adapters: its role is to handle a message and use it to execute a
|
||||
SQL query and then respond with the result sending it to a reply channel.
|
||||
The message payload and headers are available by default as input
|
||||
parameters to the query, for instance: <programlisting language="xml"><jdbc:outbound-gateway
|
||||
update="insert into foos (id, status, name) values (:headers[$id], 0, :payload[foo])"
|
||||
request-channel="input" reply-channel="output" data-source="dataSource" /></programlisting></para>
|
||||
|
||||
<para>The result of the above would be to insert a record into the "foos"
|
||||
table and return a message to the output channel indicating the number of
|
||||
rows affected (the payload is a map <literal>{UPDATED=1}</literal>.</para>
|
||||
|
||||
<para>If the update query is an insert with auto-generated keys, the reply
|
||||
message can be populated with the generated keys by adding
|
||||
<literal>keys-generated="true"</literal> to the above example (this is not
|
||||
the default because it is not supported by some database platforms). For
|
||||
example:</para>
|
||||
|
||||
<programlisting><jdbc:outbound-gateway
|
||||
update="insert into foos (status, name) values (0, :payload[foo])"
|
||||
request-channel="input" reply-channel="output" data-source="dataSource"
|
||||
keys-generated="true"/></programlisting>
|
||||
|
||||
<para>Instead of the update count or the generated keys, you can also
|
||||
provide a select query to execute and generate a reply message that way
|
||||
(like the inbound adapter), e.g:</para>
|
||||
|
||||
<programlisting><jdbc:outbound-gateway
|
||||
update="insert into foos (id, status, name) values (:headers[$id], 0, :payload[foo])"
|
||||
query="select * from foos where id=:headers[$id]"
|
||||
request-channel="input" reply-channel="output" data-source="dataSource" /></programlisting>
|
||||
|
||||
<para>Like with the adapters there is also the option to provide
|
||||
<classname>SqlParameterSourceFactory</classname> instances for request and
|
||||
reply. The default is the same as for the outbound adapter, so the request
|
||||
message is available as the root of an expression. If
|
||||
keys-generated="true" then the root of the expression is the generated
|
||||
keys (a map if there is only one or a list of maps if
|
||||
multi-valued).</para>
|
||||
|
||||
<para>The outbound gateway requires a reference to either a DataSource or
|
||||
a JdbcTemplate. It can also have a
|
||||
<classname>SqlParameterSourceFactory</classname> injected to control the
|
||||
binding of incoming message to the query.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Message Store</title>
|
||||
|
||||
<para>The JDBC module provides an implementation of the Spring Integration
|
||||
<classname>MessageStore</classname> (important in the Claim Check pattern)
|
||||
and <classname>MessageGroupStore</classname> (important in stateful
|
||||
patterns like Aggregator) backed by a database. Both interfaces are
|
||||
implemented by the JdbcMessageStore and there is also support for
|
||||
configuring store instances in XML. For example:</para>
|
||||
|
||||
<programlisting><jdbc:message-store id="messageStore" data-source="dataSource"/></programlisting>
|
||||
|
||||
<para>A <classname>JdbcTemplate</classname> can be specified instead of a
|
||||
<classname>DataSource</classname>.</para>
|
||||
|
||||
<para>Other optional attributes are show in the next example:</para>
|
||||
|
||||
<para><programlisting><jdbc:message-store id="messageStore" data-source="dataSource"
|
||||
lob-handler="lobHandler" table-prefix="MY_INT_"/></programlisting>Here we
|
||||
have specified a <classname>LobHandler</classname> for dealing with
|
||||
messages as large objects (e.g. often necessary if using Oracle) and a
|
||||
prefix for the table names in the queries generated by the store. The
|
||||
table name prefix defaults to "INT_".</para>
|
||||
|
||||
<section>
|
||||
<title>Initializing the Database</title>
|
||||
|
||||
<para>Spring Integration ships with some sample scripts that can be used
|
||||
to initialize a database. In the spring-integration-jdbc JAR file you
|
||||
will find scripts in the
|
||||
<classname>org.springframework.integration.jdbc</classname> package:
|
||||
there is a create and a drop script example for a range of common
|
||||
database platforms. A common way to use these scripts is to reference
|
||||
them in a <ulink
|
||||
url="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html#d0e24182">Spring
|
||||
JDBC data source initializer</ulink>. Note that the scripts are provided
|
||||
as samples or specifications of the the required table and column names.
|
||||
You may find that you need to enhance them for production use (e.g. with
|
||||
index declarations).</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Partitioning a Message Store</title>
|
||||
|
||||
<para>It is common to use a <classname>JdbcMessageStore</classname> as a
|
||||
global store for a group of applications, or nodes in the same
|
||||
application. To provide some portection against name clashes, and to
|
||||
give control over the database meta-data configuration, the message
|
||||
store allows the tables to be partitioned in two ways. One is to use
|
||||
separate table names, by changing the prefix as described above, and the
|
||||
other is to specify a "region" name for partitioning data within a
|
||||
single table. An important use case for this is using the store to
|
||||
manage persistent queues backing a Spring Integration channel. The
|
||||
message data for a persistent channel is keyed in the store on the
|
||||
channel name, so if the channel names are not globally unique then there
|
||||
is the danger of channels picking up data that was not intended for
|
||||
them. To avoid this the message store region can be used to keep data
|
||||
separate for different physical channels that happen to have the same
|
||||
logical name.</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,312 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="jms">
|
||||
<title>JMS Support</title>
|
||||
<para>
|
||||
Spring Integration provides Channel Adapters for receiving and sending JMS messages. There are actually two
|
||||
JMS-based inbound Channel Adapters. The first uses Spring's <classname>JmsTemplate</classname> to receive based on
|
||||
a polling period. The second is "message-driven" and relies upon a Spring MessageListener container. There is also
|
||||
an outbound Channel Adapter which uses the <classname>JmsTemplate</classname> to convert and send a JMS Message on
|
||||
demand.
|
||||
</para>
|
||||
<para>
|
||||
Whereas the JMS Channel Adapters are intended for unidirectional Messaging (send-only or receive-only), Spring
|
||||
Integration also provides inbound and outbound JMS Gateways for request/reply operations. The inbound gateway
|
||||
relies on one of Spring's MessageListener container implementations for Message-driven reception that is also
|
||||
capable of sending a return value to the "reply-to" Destination as provided by the received Message. The outbound
|
||||
Gateway sends a JMS Message to a "request-destination" and then receives a reply Message. The "reply-destination"
|
||||
reference (or "reply-destination-name") can be configured explicitly or else the outbound gateway will use a
|
||||
JMS TemporaryQueue.
|
||||
</para>
|
||||
|
||||
<section id="jms-inbound-channel-adapter">
|
||||
<title>Inbound Channel Adapter</title>
|
||||
<para>
|
||||
The inbound Channel Adapter requires a reference to either a single <classname>JmsTemplate</classname>
|
||||
instance or both <interfacename>ConnectionFactory</interfacename> and <interfacename>Destination</interfacename>
|
||||
(a 'destinationName' can be provided in place of the 'destination' reference). The following example defines an
|
||||
inbound Channel Adapter with a <classname>Destination</classname> reference.
|
||||
<programlisting language="xml"><![CDATA[ <jms:inbound-channel-adapter id="jmsIn" destination="inQueue" channel="exampleChannel">
|
||||
<integration:poller fixed-rate="30000"/>
|
||||
</jms:inbound-channel-adapter>]]></programlisting>
|
||||
<tip>
|
||||
Notice from the configuration that the inbound-channel-adapter is a Polling Consumer. That means that
|
||||
it invokes receive() when triggered. This should only be used in situations where polling is done relatively
|
||||
infrequently and timeliness is not important. For all other situations (a vast majority of JMS-based use-cases),
|
||||
the <emphasis>message-driven-channel-adapter</emphasis> described below is a better option.
|
||||
</tip>
|
||||
<note>
|
||||
All of the JMS adapters that require a reference to the ConnectionFactory will automatically look for
|
||||
a bean named "connectionFactory" by default. That is why you don't see a "connection-factory" attribute
|
||||
in many of the examples. However, if your JMS ConnectionFactory has a different bean name, then you will
|
||||
need to provide that attribute.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
If 'extract-payload' is set to true (which is the default), the received JMS Message will be passed through
|
||||
the MessageConverter. When relying on the default SimpleMessageConverter, this means that the resulting Spring
|
||||
Integration Message will have the JMS Message's body as its payload. A JMS TextMessage will produce a
|
||||
String-based payload, a JMS BytesMessage will produce a byte array payload, and a JMS ObjectMessage's
|
||||
Serializable instance will become the Spring Integration Message's payload. If instead you prefer to have
|
||||
the raw JMS Message as the Spring Integration Message's payload, then set 'extract-payload' to false.
|
||||
<programlisting language="xml"><![CDATA[ <jms:inbound-channel-adapter id="jmsIn"
|
||||
destination="inQueue"
|
||||
channel="exampleChannel"
|
||||
extract-payload="false"/>
|
||||
<integration:poller fixed-rate="30000"/>
|
||||
</jms:inbound-channel-adapter>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="jms-message-driven-channel-adapter">
|
||||
<title>Message-Driven Channel Adapter</title>
|
||||
<para>
|
||||
The "message-driven-channel-adapter" requires a reference to either an instance of a Spring MessageListener
|
||||
container (any subclass of <classname>AbstractMessageListenerContainer</classname>) or both
|
||||
<interfacename>ConnectionFactory</interfacename> and <interfacename>Destination</interfacename>
|
||||
(a 'destinationName' can be provided in place of the 'destination' reference). The following example defines a
|
||||
message-driven Channel Adapter with a <classname>Destination</classname> reference.
|
||||
<programlisting language="xml"><![CDATA[ <jms:message-driven-channel-adapter id="jmsIn" destination="inQueue" channel="exampleChannel"/>]]></programlisting>
|
||||
<note>
|
||||
The Message-Driven adapter also accepts several properties that pertain to the MessageListener container.
|
||||
These values are only considered if you do not provide an actual 'container' reference. In that case,
|
||||
an instance of DefaultMessageListenerContainer will be created and configured based on these properties.
|
||||
For example, you can specify the "transaction-manager" reference, the "concurrent-consumers" value, and
|
||||
several other property references and values. Refer to the JavaDoc and Spring Integration's JMS Schema
|
||||
(spring-integration-jms-2.0.xsd) for more detail.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
The 'extract-payload' property has the same effect as described above, and once again its default value
|
||||
is 'true'. The poller sub-element is not applicable for a message-driven
|
||||
Channel Adapter, as it will be actively invoked. For most usage scenarios, the message-driven approach is better since the Messages will
|
||||
be passed along to the <interfacename>MessageChannel</interfacename> as soon as they are received from the underlying
|
||||
JMS consumer.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="jms-outbound-channel-adapter">
|
||||
<title>Outbound Channel Adapter</title>
|
||||
<para>
|
||||
The <classname>JmsSendingMessageHandler</classname> implements the <interfacename>MessageHandler</interfacename>
|
||||
interface and is capable of converting Spring Integration <interfacename>Messages</interfacename> to JMS messages
|
||||
and then sending to a JMS destination. It requires either a 'jmsTemplate' reference or both 'connectionFactory' and
|
||||
'destination' references (again, the 'destinationName' may be provided in place of the 'destination'). As with the
|
||||
inbound Channel Adapter, the easiest way to configure this adapter is with the namespace support. The following
|
||||
configuration will produce an adapter that receives Spring Integration Messages from the "exampleChannel" and then
|
||||
converts those into JMS Messages and sends them to the JMS Destination reference whose bean name is "outQueue".
|
||||
<programlisting language="xml"><![CDATA[<jms:outbound-channel-adapter id="jmsOut" destination="outQueue" channel="exampleChannel"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
As with the inbound Channel Adapters, there is an 'extract-payload' property. However, the meaning is reversed
|
||||
for the outbound adapter. Rather than applying to the JMS Message, the boolean property applies to the Spring
|
||||
Integration Message payload. In other words, the decision is whether to pass the Spring Integration Message
|
||||
<emphasis>itself</emphasis> as the JMS Message body or whether to pass the Spring Integration Message's
|
||||
payload as the JMS Message body. The default value is once again 'true'. Therefore, if you pass a Spring
|
||||
Integration Message whose payload is a String, a JMS TextMessage will be created. If on the other hand you
|
||||
want to send the actual Spring Integration Message to another system via JMS, then simply set this to 'false'.
|
||||
<note>
|
||||
Regardless of the boolean value for payload extraction, the Spring Integration MessageHeaders will map to
|
||||
JMS properties as long as you are relying on the default converter or provide a reference to another
|
||||
instance of HeaderMappingMessageConverter (the same holds true for 'inbound' adapters except that in
|
||||
those cases, it's the JMS properties mapping <emphasis>to</emphasis> Spring Integration MessageHeaders).
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="jms-inbound-gateway">
|
||||
<title>Inbound Gateway</title>
|
||||
<para>
|
||||
Spring Integration's message-driven JMS inbound-gateway delegates to a
|
||||
<interfacename>MessageListener</interfacename> container, supports dynamically adjusting concurrent consumers,
|
||||
and can also handle replies. The inbound gateway requires references to a
|
||||
<interfacename>ConnectionFactory</interfacename>, and a request <interfacename>Destination</interfacename> (or
|
||||
'requestDestinationName'). The following example defines a JMS "inbound-gateway" that receives from the JMS
|
||||
queue referenced by the bean id "inQueue" and sends to the Spring Integration channel named "exampleChannel".
|
||||
<programlisting language="xml"><![CDATA[ <jms:inbound-gateway id="jmsInGateway"
|
||||
request-destination="inQueue"
|
||||
request-channel="exampleChannel"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Since the gateways provide request/reply behavior instead of unidirectional send <emphasis>or</emphasis>
|
||||
receive, they also have two distinct properties for the "payload extraction" (as discussed above for the
|
||||
Channel Adapters' 'extract-payload' setting). For an inbound-gateway, the 'extract-request-payload' property
|
||||
determines whether the received JMS Message body will be extracted. If 'false', the JMS Message itself will
|
||||
become the Spring Integration Message payload. The default is 'true'.
|
||||
</para>
|
||||
<para>
|
||||
Similarly, for an inbound-gateway the 'extract-reply-payload' property applies to the Spring Integration Message
|
||||
that is going to be converted into a reply JMS Message. If you want to pass the whole Spring Integration Message
|
||||
(as the body of a JMS ObjectMessage) then set this to 'false'. By default, it is also 'true' such that the Spring
|
||||
Integration Message <emphasis>payload</emphasis> will be converted into a JMS Message (e.g. String payload
|
||||
becomes a JMS TextMessage).
|
||||
</para>
|
||||
<para>
|
||||
As with anything else, Gateway invocation might result in error.
|
||||
By default Producer will not be notified of the errors thta might have occurredon ythe consumer side and will time out waiting for
|
||||
the reply. However there might be times when you to communicate error condition back to the consumer,
|
||||
in other words treat the Exception as a valid reply valid reply by mapping it to a Message. To accomplish this
|
||||
JMS Inbound Gateway provides support for Exception mappers via <emphasis>exception-mapper</emphasis>
|
||||
attribute.
|
||||
|
||||
|
||||
<programlisting language="xml"><![CDATA[<int-jms:inbound-gateway request-destination="requestQueue"
|
||||
request-channel="jmsinputchannel"
|
||||
exception-mapper="errorMessageMapper"/>
|
||||
|
||||
<bean id="exceptionMapper" class="foo.bar.SampleExceptionMapper"/>
|
||||
|
||||
]]></programlisting>
|
||||
|
||||
<emphasis>foo.bar.SampleExceptionMapper</emphasis> is the implementation of
|
||||
<emphasis>org.springframework.integration.message.InboundMessageMapper</emphasis> which only defines one method <code>toMessage(Object object)</code>.
|
||||
<programlisting language="java"><![CDATA[public static class SampleExceptionMapper implements InboundMessageMapper<Throwable>{
|
||||
public Message<?> toMessage(Throwable object) throws Exception {
|
||||
MessageHandlingException ex = (MessageHandlingException) object;
|
||||
return MessageBuilder.withPayload("Error happened in message: " +
|
||||
ex.getFailedMessage().getPayload()).build();
|
||||
}
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="jms-outbound-gateway">
|
||||
<title>Outbound Gateway</title>
|
||||
<para>
|
||||
The outbound Gateway creates JMS Messages from Spring Integration Messages and then sends to a
|
||||
'request-destination'. It will then handle the JMS reply Message either by using a selector to
|
||||
receive from the 'reply-destination' that you configure, or if no 'reply-destination' is provided,
|
||||
it will create JMS TemporaryQueues. Notice that the "reply-channel" is also provided.
|
||||
<programlisting language="xml"><![CDATA[ <jms:outbound-gateway id="jmsOutGateway"
|
||||
request-destination="outQueue"
|
||||
request-channel="outboundJmsRequests"
|
||||
reply-channel="jmsReplies"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The 'outbound-gateway' payload extraction properties are inversely related to those of the
|
||||
'inbound-gateway' (see the discussion above). That means that the 'extract-request-payload' property value
|
||||
applies to the Spring Integration Message that is being converted into a JMS Message to be
|
||||
<emphasis>sent as a request</emphasis>, and the 'extract-reply-payload' property value applies to the
|
||||
JMS Message that is <emphasis>received as a reply</emphasis> and then converted into a Spring Integration
|
||||
Message to be subsequently sent to the 'reply-channel' as shown in the example configuration above.
|
||||
</para>
|
||||
</section>
|
||||
<section id="jms-conversion-and-marshalling">
|
||||
<title>Message Conversion, Marshalling and Unmarshalling</title>
|
||||
<para>
|
||||
If you need to convert the message, all JMS adapters and gateways, allow you to
|
||||
provide a <interfacename>MessageConverter</interfacename> via <emphasis>message-converter</emphasis> attribute. Simply provide the
|
||||
bean name of an instance of <interfacename>MessageConverter</interfacename> that is available within the same
|
||||
ApplicationContext.
|
||||
Also, to provide some consistency with Marshaller and Unmarshaller interfaces Spring provides <interfacename>MarshallingMessageConverter</interfacename>
|
||||
which you can configure with your own custom Marshallers and Unmarshallers
|
||||
</para>
|
||||
<programlisting language="xml"><![CDATA[ <int-jms:inbound-gateway request-destination="requestQueue"
|
||||
request-channel="inbound-gateway-channel"
|
||||
message-converter="marshallingMessageConverter"/>
|
||||
|
||||
<bean id="marshallingMessageConverter"
|
||||
class="org.springframework.jms.support.converter.MarshallingMessageConverter">
|
||||
<constructor-arg>
|
||||
<bean class="org.bar.SampleMarshaller"/>
|
||||
</constructor-arg>
|
||||
<constructor-arg>
|
||||
<bean class="org.bar.SampleUnmarshaller"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
]]></programlisting>
|
||||
|
||||
|
||||
<note>
|
||||
Note, however, that when you provide your own MessageConverter instance, it will still
|
||||
be wrapped within the HeaderMappingMessageConverter. This means that the 'extract-request-payload'
|
||||
and 'extract-reply-payload' properties may effect what actual objects are passed to your converter. The
|
||||
HeaderMappingMessageConverter itself simply delegates to a target MessageConverter while also mapping the
|
||||
Spring Integration MessageHeaders to JMS Message properties and vice-versa.
|
||||
</note>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="jms-channel">
|
||||
<title>JMS Backed Message Channels</title>
|
||||
<para>
|
||||
The Channel Adapters and Gateways featured above are all intended for applications that are integrating
|
||||
with other external systems. The inbound options assume that some other system is sending JMS Messages
|
||||
to the JMS Destination and the outbound options assume that some other system is receiving from the
|
||||
Destination. The other system may or may not be a Spring Integration application. Of course, when sending
|
||||
the Spring Integration Message instance as the body of the JMS Message itself (with the 'extract-payload'
|
||||
value set to false), it is assumed that the other system is based on Spring Integration. However,
|
||||
that is by no means a requirement. That flexibility is one of the benefits of using a Message-based
|
||||
integration option with the abstraction of "channels" or Destinations in the case of JMS.
|
||||
</para>
|
||||
<para>
|
||||
There are cases where both the producer and consumer for a given JMS Destination are intended to be
|
||||
part of the same application, running within the same process. This could be accomplished by using a
|
||||
pair of inbound and outbound Channel Adapters. The problem with that approach is that two adapters are
|
||||
required even though conceptually the goal is to have a single Message Channel. A better option is
|
||||
supported as of Spring Integration version 2.0. Now it is possible to define a single "channel" when
|
||||
using the JMS namespace.
|
||||
<programlisting language="xml"><![CDATA[ <jms:channel id="jmsChannel" queue="exampleQueue"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The channel in the above example will behave much like a normal <channel/> element from the main
|
||||
Spring Integration namespace. It can be referenced by both "input-channel" and "output-channel" attributes
|
||||
of any endpoint. The difference is that this channel is backed by a JMS Queue instance named "exampleQueue".
|
||||
This means that asynchronous messaging is possible between the producing and consuming endpoints, but
|
||||
unlike the simpler asynchronous Message Channels created by adding a <queue/> sub-element within a
|
||||
non-JMS <channel/> element, the Messages are not just stored in an in-memory queue. Instead those
|
||||
Messages are passed within a JMS Message body, and the full power of the underlying JMS provider is then
|
||||
available for that channel. Probably the most common rationale for using this alternative would be to
|
||||
take advantage of the persistence made available by the <emphasis>store and forward</emphasis> approach
|
||||
of JMS messaging. If configured properly, the JMS-backed Message Channel also supports transactions.
|
||||
In other words, a producer would not actually write to a transactional JMS-backed channel if its send
|
||||
operation is part of a transaction that rolls back. Likewise, a consumer would not physically remove a
|
||||
JMS Message from the channel if the reception of that Message is part of a transaction that rolls back.
|
||||
Note that the producer and consumer transactions are separate in such a scenario. This is significantly
|
||||
different than the propagation of a transactional context across the simple, synchronous <channel/>
|
||||
element that has no <queue/> sub-element.
|
||||
</para>
|
||||
<para>
|
||||
Since the example above is referencing a JMS Queue instance, it will act as a point-to-point channel. If
|
||||
on the other hand, publish/subscribe behavior is needed, then a separate element can be used, and a JMS
|
||||
Topic can be referenced instead.
|
||||
<programlisting language="xml"><![CDATA[ <jms:publish-subscribe-channel id="jmsChannel" topic="exampleTopic"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
For either type of JMS-backed channel, the name of the destination may be provided instead of a reference.
|
||||
<programlisting language="xml"><![CDATA[ <jms:channel id="jmsQueueChannel" queue-name="exampleQueueName"/>
|
||||
|
||||
<jms:publish-subscribe-channel id="jmsTopicChannel" topic-name="exampleTopicName"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In the examples above, the Destination names would be resolved by Spring's default
|
||||
<classname>DynamicDestinationResolver</classname> implementation, but any implementation of the
|
||||
<interfacename>DestinationResolver</interfacename> interface could be provided. Also, the JMS
|
||||
<interfacename>ConnectionFactory</interfacename> is a required property of the channel, but by default
|
||||
the expected bean name would be "connectionFactory". The example below provides both a custom instance
|
||||
for resolution of the JMS Destination names and a different name for the ConnectionFactory.
|
||||
<programlisting language="xml"><![CDATA[ <jms:channel id="jmsChannel" queue-name="exampleQueueName"
|
||||
destination-resolver="customDestinationResolver"
|
||||
connection-factory="customConnectionFactory"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="jms-samples">
|
||||
<title>JMS Samples</title>
|
||||
<para>
|
||||
To experiment with these JMS adapters, check out the samples available within the "samples/jms" directory in
|
||||
the distribution. There are two samples included. One provides inbound and outbound Channel Adapters, and the
|
||||
other provides inbound and outbound Gateways. They are configured to run with an embedded ActiveMQ process, but
|
||||
the "common.xml" file can easily be modified to support either a different JMS provider or a standalone
|
||||
ActiveMQ process. In other words, you can split the configuration so that the inbound and outbound adapters are
|
||||
running in separate JVMs. If you have ActiveMQ installed, simply modify the "brokerURL" property within the
|
||||
configuration to use "tcp://localhost:61616" for example (instead of "vm://localhost"). Both of the samples
|
||||
accept input via stdin and then echo back to stdout. Look at the configuration to see how these messages are
|
||||
routed over JMS.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,191 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="jmx">
|
||||
<title>JMX Support</title>
|
||||
|
||||
<para>Spring Integration provides Channel Adapters for receiving and
|
||||
publishing JMX Notifications. There is also an inbound Channel Adapter for
|
||||
polling JMX MBean attribute values, and an outbound Channel Adapter for
|
||||
invoking JMX MBean operations.</para>
|
||||
|
||||
<section id="jmx-notification-listening-channel-adapter">
|
||||
<title>Notification Listening Channel Adapter</title>
|
||||
|
||||
<para>The Notification-listening Channel Adapter requires a JMX ObjectName
|
||||
for the MBean that publishes Notifications to which this listener should
|
||||
be registered. A very simple configuration might look like this:
|
||||
<programlisting language="xml"> <jmx:notification-listening-channel-adapter id="adapter"
|
||||
channel="channel"
|
||||
object-name="example.domain:name=publisher"/>
|
||||
</programlisting> <tip>
|
||||
The
|
||||
|
||||
<emphasis>notification-listening-channel-adapter</emphasis>
|
||||
|
||||
registers with an MBeanServer at startup, and the default bean name is "mbeanServer" which happens to be the same bean name generated when using Spring's <context:mbean-server/> element. If you need to use a different name be sure to include the "mbean-server" attribute.
|
||||
</tip> The adapter can also accept a reference to a NotificationFilter
|
||||
and a "handback" Object to provide some context that is passed back with
|
||||
each Notification. Both of those attributes are optional. Extending the
|
||||
above example to include those attributes as well as an explicit
|
||||
MBeanServer bean name would produce the following: <programlisting
|
||||
language="xml"> <jmx:notification-listening-channel-adapter id="adapter"
|
||||
channel="channel"
|
||||
mbean-server="someServer"
|
||||
object-name="example.domain:name=somePublisher"
|
||||
notification-fliter="notificationFilter"
|
||||
handback="myHandback"/>
|
||||
</programlisting> Since the notification-listening adapter is registered with
|
||||
the MBeanServer directly, it is event-driven and does not require any
|
||||
poller configuration.</para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-notification-publishing-channel-adapter">
|
||||
<title>Notification Publishing Channel Adapter</title>
|
||||
|
||||
<para>The Notification-publishing Channel Adapter is relatively simple. It
|
||||
only requires a JMX ObjectName in its configuration as shown below.
|
||||
<programlisting language="xml"> <context:mbean:export/>
|
||||
|
||||
<jmx:notification-publishing-channel-adapter id="adapter"
|
||||
channel="channel"
|
||||
object-name="example.domain:name=publisher"/>
|
||||
</programlisting> It does also require that an MBeanExporter be present in the
|
||||
context. That is why the <context:mbean-export/> element is shown
|
||||
above as well.</para>
|
||||
|
||||
<para>When Messages are sent to the channel for this adapter, the
|
||||
Notification is created from the Message content. If the payload is a
|
||||
String it will be passed as the "message" text for the Notification. Any
|
||||
other payload type will be passed as the "userData" of the
|
||||
Notification.</para>
|
||||
|
||||
<para>JMX Notifications also have a "type", and it should be a
|
||||
dot-delimited String. There are two ways to provide the type. Precedence
|
||||
will always be given to a Message header value associated with the
|
||||
JmxHeaders.NOTIFICATION_TYPE key. On the other hand, you can rely on a
|
||||
fallback "default-notification-type" attribute provided in the
|
||||
configuration. <programlisting language="xml"> <context:mbean:export/>
|
||||
|
||||
<jmx:notification-publishing-channel-adapter id="adapter"
|
||||
channel="channel"
|
||||
object-name="example.domain:name=publisher"
|
||||
default-notification-type="some.default.type"/>
|
||||
</programlisting></para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-attribute-polling-channel-adapter">
|
||||
<title>Attribute Polling Channel Adapter</title>
|
||||
|
||||
<para>The attribute polling adapter is useful when you have a requirement
|
||||
to periodically check on some value that is available through an MBean as
|
||||
a managed attribute. The poller can be configured in the same way as any
|
||||
other polling adapter in Spring Integration (or it's possible to rely on
|
||||
the default poller). The "object-name" and "attribute-name" are required.
|
||||
An MBeanServer reference is also required, but it will automatically check
|
||||
for a bean named "mbeanServer" by default just like the
|
||||
notification-listening-channel-adapter described above. <programlisting
|
||||
language="xml"> <jmx:attribute-polling-channel-adapter id="adapter"
|
||||
channel="channel"
|
||||
object-name="example.domain:name=someService"
|
||||
attribute-name="InvocationCount">
|
||||
<si:poller max-messages-per-poll="1" fixed-rate="5000"/>
|
||||
</jmx:attribute-polling-channel-adapter>
|
||||
</programlisting></para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-operation-invoking-channel-adapter">
|
||||
<title>Operation Invoking Channel Adapter</title>
|
||||
|
||||
<para>The <emphasis>operation-invoking-channel-adapter</emphasis> enables
|
||||
Message-driven invocation of any managed operation exposed by an MBean.
|
||||
Each invocation requires the operation name to be invoked and the
|
||||
ObjectName of the target MBean. Both of these must be explicitly provided
|
||||
via adapter configuration: <programlisting language="xml"> <jmx:operation-invoking-channel-adapter id="adapter"
|
||||
object-name="example.domain:name=TestBean"
|
||||
operation-name="ping"/>
|
||||
</programlisting> Then the adapter only needs to be able to discover the
|
||||
"mbeanServer" bean. If a different bean name is required, then provide the
|
||||
"mbean-server" attribute with a reference.</para>
|
||||
|
||||
<para>The payload of the Message will be mapped to the parameters of the
|
||||
operation, if any. A Map-typed payload with String keys is treated as
|
||||
name/value pairs whereas a List or array would be passed as a simple
|
||||
argument list (with no explicit parameter names). If the operation
|
||||
requires a single parameter value, then the payload can represent that
|
||||
single value, and if the operation requires no parameters, then the
|
||||
payload would be ignored.</para>
|
||||
|
||||
<para>If you want to expose a channel for a single common operation to be
|
||||
invoked by Messages that need not contain headers, then that option works
|
||||
well.</para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-operation-invoking-outbound-gateway">
|
||||
<title>Operation Invoking outbound Gateway</title>
|
||||
|
||||
<para>Similar to <emphasis>operation-invoking-channel-adapter</emphasis>
|
||||
Spring Integration also provides
|
||||
<emphasis>operation-invoking-outbound-gateway</emphasis> which could be
|
||||
used when dealing with non-void operations and return value is required.
|
||||
Such return value will be sent as message payload to the 'reply-channel'
|
||||
specified by this Gateway. <programlisting language="xml"> <jmx:operation-invoking-outbound-gateway request-channel="requestChannel"
|
||||
reply-channel="replyChannel"
|
||||
object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBeanGateway"
|
||||
operation-name="testWithReturn"/></programlisting> Another way of
|
||||
provideing the 'reply-channel' is by setting
|
||||
<interfacename>MessageHeaders.REPLY_CHANNEL</interfacename> Message
|
||||
Header</para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-mbean-exporter">
|
||||
<title>MBean Exporter</title>
|
||||
|
||||
<para>Spring Integration components themselves may be exposed as MBeans
|
||||
when the <classname>IntegrationMBeanExporter</classname> is configured. To
|
||||
create an instance of the <classname>IntegrationMBeanExporter</classname>,
|
||||
define a bean and provide a reference to an MBeanServer and a domain name
|
||||
(if desired). The domain can be left out in which case the default domain
|
||||
is "spring.application". <programlisting language="xml"> <jmx:mbean-exporter domain="my.company.domain" mbean-server="mbeanServer"/>
|
||||
|
||||
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
|
||||
<property name="locateExistingServerIfPossible" value="true"/>
|
||||
</bean></programlisting></para>
|
||||
|
||||
<para>The MBean exporter is orthogonal to the one provided in Spring core
|
||||
- it registers message channels and message handlers, but not itself (you
|
||||
can expose the exporter itself using the standard
|
||||
<literal><context:mbean-export/></literal> tag).</para>
|
||||
</section>
|
||||
|
||||
<section id="jmx-control-bus">
|
||||
<title>Control Bus</title>
|
||||
|
||||
<para>As described in (<ulink
|
||||
url="http://www.eaipatterns.com/ControlBus.html">EIP</ulink>), the idea
|
||||
behind the Control Bus is that the same messaging system can be used for
|
||||
monitoring and managing the components within the framework as is used for
|
||||
"application-level" messaging. In Spring Integration we build upon the
|
||||
adapters described above so that it's possible to send Messages as a means
|
||||
of invoking exposed operations. Internally, the Control Bus uses a Spring
|
||||
MBeanExporter instance to expose the various endpoints and channels. To
|
||||
create an instance of the Control Bus, define a bean and provide a
|
||||
reference to an MBeanServer and a domain name. <programlisting
|
||||
language="xml"> <jmx:control-bus mbean-exporter="mbeanExporter" operation-channel="operationChannel"/>
|
||||
|
||||
<jmx:mbean-exporter id="mbeanExporter" mbean-server="mbeanServer"/>
|
||||
</programlisting></para>
|
||||
|
||||
<para>The Control Bus has an "operationChannel" that can be accessed for
|
||||
invoking operations on the MBeans that it has exported. This will also be
|
||||
covered by namespace support soon to make it easier to configure
|
||||
references to that channel for other producers. We will likely add some
|
||||
other channels for notifications and attribute polling as well.</para>
|
||||
|
||||
<para>The Control Bus functionality is a work in progress. At this time,
|
||||
one can perform some basic monitoring of Message Channels and/or invoke
|
||||
Lifecycle operations (start/stop) on Message Endpoints. Now that the
|
||||
foundation is available, however, we will be able to extend the attributes
|
||||
and operations that are being exposed.</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,161 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="mail">
|
||||
<title>Mail Support</title>
|
||||
|
||||
<section id="mail-outbound">
|
||||
<title>Mail-Sending Channel Adapter</title>
|
||||
<para>
|
||||
Spring Integration provides support for outbound email with the
|
||||
<classname>MailSendingMessageHandler</classname>. It delegates to a configured instance of Spring's
|
||||
<interfacename>JavaMailSender</interfacename>:
|
||||
<programlisting language="java"> JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
|
||||
|
||||
MailSendingMessageHandler mailSendingHandler = new MailSendingMessageHandler(mailSender);</programlisting>
|
||||
<classname>MailSendingMessageHandler</classname> has various mapping strategies that use Spring's
|
||||
<interfacename>MailMessage</interfacename> abstraction. If the received Message's payload is already
|
||||
a <classname>MailMessage</classname> instance, it will be sent directly.
|
||||
Therefore, it is generally recommended to precede this
|
||||
consumer with a Transformer for non-trivial MailMessage construction requirements. However, a few simple
|
||||
Message mapping strategies are supported out-of-the-box. For example, if the message payload is a byte array,
|
||||
then that will be mapped to an attachment. For simple text-based emails, you can provide a String-based
|
||||
Message payload. In that case, a MailMessage will be created with that String as the text content. If you
|
||||
are working with a Message payload type whose toString() method returns appropriate mail text content, then
|
||||
consider adding Spring Integration's <emphasis>ObjectToStringTransformer</emphasis> prior to the outbound
|
||||
Mail adapter (see the example within <xref linkend="transformer-namespace"/> for more detail).
|
||||
</para>
|
||||
<para>
|
||||
The outbound MailMessage may also be configured with certain values from the
|
||||
<classname>MessageHeaders</classname>. If available, values will be mapped to the outbound mail's
|
||||
properties, such as the recipients (TO, CC, and BCC), the from/reply-to, and the subject. The header names are
|
||||
defined by the following constants:
|
||||
<programlisting language="java"> MailHeaders.SUBJECT
|
||||
MailHeaders.TO
|
||||
MailHeaders.CC
|
||||
MailHeaders.BCC
|
||||
MailHeaders.FROM
|
||||
MailHeaders.REPLY_TO</programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<classname>MailHeaders</classname> also allows you to override corresponding <classname>MailMessage</classname> values.
|
||||
For example: If <classname>MailMessage.to</classname> is set to 'foo@bar.com' and <classname>MailHeaders.TO</classname>
|
||||
Message header is provided it will take precedence and override the corresponding value in <classname>MailMessage</classname>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="mail-inbound">
|
||||
<title>Mail-Receiving Channel Adapter</title>
|
||||
<para>
|
||||
Spring Integration also provides support for inbound email with the
|
||||
<classname>MailReceivingMessageSource</classname>. It delegates to a configured instance of Spring
|
||||
Integration's own <interfacename>MailReceiver</interfacename> interface, and there are two implementations:
|
||||
<classname>Pop3MailReceiver</classname> and <classname>ImapMailReceiver</classname>. The easiest way to
|
||||
instantiate either of these is by passing the 'uri' for a Mail store to the receiver's constructor. For example:
|
||||
<programlisting language="java"><![CDATA[ MailReceiver receiver = new Pop3MailReceiver("pop3://usr:pwd@localhost/INBOX");
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Another option for receiving mail is the IMAP "idle" command (if supported by the mail server you are using).
|
||||
Spring Integration provides the <classname>ImapIdleChannelAdapter</classname> which is itself a Message-producing
|
||||
endpoint. It delegates to an instance of the <classname>ImapMailReceiver</classname> but enables asynchronous
|
||||
reception of Mail Messages. There are examples in the next section of configuring both types of inbound Channel
|
||||
Adapter with Spring Integration's namespace support in the 'mail' schema.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="mail-namespace">
|
||||
<title>Mail Namespace Support</title>
|
||||
<para>
|
||||
Spring Integration provides a namespace for mail-related configuration. To use it, configure the following schema
|
||||
locations.<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mail="http://www.springframework.org/schema/integration/mail"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/mail
|
||||
http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd">]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure an outbound Channel Adapter, provide the channel to receive from, and the MailSender:
|
||||
<programlisting language="xml"><![CDATA[<mail:outbound-channel-adapter channel="outboundMail"
|
||||
mail-sender="mailSender"/>]]></programlisting>
|
||||
Alternatively, provide the host, username, and password:
|
||||
<programlisting language="xml"><![CDATA[<mail:outbound-channel-adapter channel="outboundMail"
|
||||
host="somehost" username="someuser" password="somepassword"/>]]></programlisting>
|
||||
<note>
|
||||
Keep in mind, as with any outbound Channel Adapter, if the referenced channel is a PollableChannel, a
|
||||
<poller> sub-element should be provided with either an interval-trigger or cron-trigger.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
To configure an inbound Channel Adapter, you have the choice between polling or event-driven (assuming your
|
||||
mail server supports IMAP IDLE - if not, then polling is the only option). A polling Channel Adapter simply
|
||||
requires the store URI and the channel to send inbound Messages to. The URI may begin with "pop3" or "imap":
|
||||
<programlisting language="xml"><![CDATA[<int-mail:inbound-channel-adapter id="imapAdapter"
|
||||
store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX"
|
||||
java-mail-properties="javaMailProperties"
|
||||
channel="recieveChannel"
|
||||
should-delete-messages="true"
|
||||
should-mark-messages-as-read="true"
|
||||
auto-startup="true">
|
||||
<int:poller max-messages-per-poll="1" fixed-rate="5000"/>
|
||||
</int-mail:inbound-channel-adapter>]]></programlisting>
|
||||
If you do have IMAP idle support, then you may want to configure the "imap-idle-channel-adapter" element instead.
|
||||
Since the "idle" command enables event-driven notifications, no poller is necessary for this adapter. It will
|
||||
send a Message to the specified channel as soon as it receives the notification that new mail is available:
|
||||
<programlisting language="xml"><![CDATA[<int-mail:imap-idle-channel-adapter id="customAdapter"
|
||||
store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX"
|
||||
channel="recieveChannel"
|
||||
auto-startup="true"
|
||||
should-delete-messages="false"
|
||||
should-mark-messages-as-read="true"
|
||||
java-mail-properties="javaMailProperties"/>]]></programlisting>
|
||||
... where <emphasis>javaMailProperties</emphasis> could be provided by creating and populating
|
||||
a regular <classname>java.utils.Properties</classname> object. For example via <emphasis>util</emphasis> namespace
|
||||
provided by Spring.
|
||||
<programlisting language="xml"><![CDATA[<util:properties id="javaMailProperties">
|
||||
<prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
|
||||
<prop key="mail.imap.socketFactory.fallback">false</prop>
|
||||
<prop key="mail.store.protocol">imaps</prop>
|
||||
<prop key="mail.debug">false</prop>
|
||||
</util:properties>]]></programlisting>
|
||||
</para>
|
||||
|
||||
<important>
|
||||
In both configurations <code>channel</code> and <code>should-delete-messages</code> are the <emphasis>REQUIRED</emphasis>
|
||||
attributes. The important thing to understand is why <code>should-delete-messages</code> is required?
|
||||
The issue is with POP3 protocol, which does NOT have any knowlege of messages that were READ. It can only know what's been read
|
||||
within a single session. This means that when your POP3 mail adapter is running emails are successfully consumed as as they become available during each poll
|
||||
and no single email message will be delivered more then once. However, as soon as you restart your adapter and begin a new session
|
||||
all the email messages that might have been retreeved in the previous session will be retrieved again. That is the nature of POP3. Some might argue
|
||||
that why not set <code>should-delete-messages</code> to TRUE by default? Becouse there are two valid amd mutually exclusive use cases
|
||||
which makes it very hard pick the right default. You may want to configure your adapter as the only email receiever in which
|
||||
case you want to be able to restart such adapter without fear that messages that were delivered before will not be redelivered again.
|
||||
In this case setting <code>should-delete-messages</code> to TRUE would make most sence. However, you may have anoher use case where
|
||||
you may want to have multiple adapters that simply monitor email servers and their content. In other words you just want to 'peek but not touch'.
|
||||
Then setting <code>should-delete-messages</code> to FALSE would be much more appropriate. So since it is hard to choose what should be
|
||||
the right default value for <code>should-delete-messages</code> attribute we simply made it required to be set - leaving it up to you
|
||||
while also not letting you to forget that you must set it.
|
||||
</important>
|
||||
|
||||
<note>When configuring a polling adapter (e.g., inbound-channel-adapter) <emphasis>should-mark-messages-as-read</emphasis>
|
||||
be aware of the protocol you are configuring to retrieve messages. For example POP3 does not support this flag
|
||||
which means setting it to either value will have no effect as messages will NOT be marked as read</note>
|
||||
|
||||
|
||||
<para>
|
||||
When using the namespace support, a <emphasis>header-enricher</emphasis> Message Transformer is also available.
|
||||
This simplifies the application of the headers mentioned above to any Message prior to sending to the
|
||||
Mail-sending Channel Adapter.
|
||||
<programlisting language="xml"><![CDATA[<mail:header-enricher subject="Example Mail"
|
||||
to="to@example.org"
|
||||
cc="cc@example.org"
|
||||
bcc="bcc@example.org"
|
||||
from="from@example.org"
|
||||
reply-to="replyTo@example.org"
|
||||
overwrite="false"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="message-history">
|
||||
<title>Message History</title>
|
||||
<para>
|
||||
The key benefit of messaging architecture is loose coupling where participating components do not maintain any awareness about one another. This fact
|
||||
alone makes you architecture extremely flexible allowing you to change components without affecting the rest of the flow, change messaging routs,
|
||||
message consuming styles (polling vs event driven) etc...
|
||||
However, this unassuming style of architecture could prove to be problematic when things go wrong. For example, if something happened
|
||||
you would probably like to get as much information about the message as you can (its origin, where it was etc.)
|
||||
</para>
|
||||
<para>
|
||||
Message History is one of those patterns that could help by giving you an option to maintain some level of awareness of a
|
||||
message path either for debugging purposes or to maintain an audit trail.
|
||||
Spring integration provides a simple way to configure your message flows to maintain Message History by adding Message History header to a
|
||||
Message every time a message goes through a tracked component.
|
||||
</para>
|
||||
<section id="message-history-config">
|
||||
<title>Message History Configuration</title>
|
||||
<para>
|
||||
To enable Message History all you need is define <code>message-history</code> element in your configuration.
|
||||
<programlisting language="xml"><![CDATA[<int:message-history/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Now every named component (component that has an 'id' defined) will be tracked.
|
||||
The framework will set the '$history' header in your Message who's value is very simple - <classname>List<Properties></classname>.
|
||||
The need for this simple structure is mandated by the loosely coupled architecture of messaging systems where the framework
|
||||
must not require you to share any dependencies outside of Java itself.
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<int:gateway id="sampleGateway"
|
||||
service-interface="org.springframework.integration.history.sample.SampleGateway"
|
||||
default-request-channel="bridgeInChannel"/>
|
||||
|
||||
<int:chain id="sampleChain" input-channel="chainChannel" output-channel="filterChannel">
|
||||
<int:header-enricher>
|
||||
<int:header name="baz" value="baz"/>
|
||||
</int:header-enricher>
|
||||
</int:chain>]]></programlisting>
|
||||
The above configuration will produce a very simple Message History structure:
|
||||
<programlisting language="java"><![CDATA[[{name=sampleGateway, type=gateway, timestamp=1283281668091},
|
||||
{name=sampleChain, type=chain, timestamp=1283281668094}]]]></programlisting>
|
||||
To get access to Message History all you need is access the MessageHistory header. For example:
|
||||
<programlisting language="java"><![CDATA[Iterator<Properties> historyIterator =
|
||||
message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
|
||||
assertTrue(historyIterator.hasNext());
|
||||
Properties gatewayHistory = historyIterator.next();
|
||||
assertEquals("sampleGateway", gatewayHistory.get("name"));
|
||||
assertTrue(historyIterator.hasNext());
|
||||
Properties chainHistory = historyIterator.next();
|
||||
assertEquals("sampleChain", chainHistory.get("name"));]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Some times you might not want to track all of the components. To accomplish this all you need is provide <code>tracked-components</code> attribute where you can specify
|
||||
comma delimited list of component names and/or patterns you want to track.
|
||||
<programlisting language="xml"><![CDATA[<int:message-history tracked-components="*Gateway, sample*, foo"/>]]></programlisting>
|
||||
In the above example, Message History will only be maintained for all of the components that end with 'Gateway', all components that start with 'sample' and 'foo' component.
|
||||
</para>
|
||||
<note>
|
||||
Remember, that by definition History is immutable (you can't re-write history,although some try), therefore Message History can not
|
||||
be changed once written. Every attempt will end in exception.
|
||||
</note>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,371 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="message-publishing">
|
||||
<title>Message Publishing</title>
|
||||
<para>
|
||||
The AOP Message Publishing feature allows you to construct and send a message as a by-product of method invocation. For example, imagine you
|
||||
have a component and every time the state of this component changes you would like to be notified via a Message. The easiest
|
||||
way to send such notifications would be to send a message to a dedicated channel, but how would you connect the method invocation that
|
||||
changes the state of the object to a message sending process, and how should the notification Message be structured?
|
||||
The AOP Message Publishing feature handles these responsibilities with a configuration-driven approach.
|
||||
</para>
|
||||
<section id="message-publishing-config">
|
||||
<title>Message Publishing Configuration</title>
|
||||
<para>
|
||||
Spring Integration provides two approaches: XML and Annotation-driven.
|
||||
</para>
|
||||
<section id="publisher-annotation">
|
||||
<title>Annotation-driven approach via @Publisher annotation</title>
|
||||
<para>
|
||||
The annotation-driven approach allows you to annotate any method with the <interfacename>@Publisher</interfacename> annotation, specifying 'channel' attribute.
|
||||
The Message will be constructed from the return value of method invocation and sent to a channel specified by 'channel' attribute.
|
||||
To further manage message structure you can also use a combination of both <interfacename>@Payload</interfacename> and <interfacename>@Header</interfacename> annotations.
|
||||
</para>
|
||||
<para>
|
||||
Internally message publishing feature of Spring Integration uses both Spring AOP by defining <classname>PublisherAnnotationAdvisor</classname> and
|
||||
Spring 3.0 Expression Language (SpEL) support, giving you considerable flexibility and control over the structure of the <emphasis>Message</emphasis> it will build.
|
||||
</para>
|
||||
<para>
|
||||
<classname>PublisherAnnotationAdvisor</classname> defines and binds the following variables:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>#return</emphasis> - will bind to a return value allowing you to reference it or its
|
||||
attributes (e.g., <emphasis>#return.foo</emphasis> where 'foo' is an attribute of the object bound to
|
||||
<emphasis>#return</emphasis>)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>#exception</emphasis> - will bind to an exception if one is thrown by the method invocation.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>#args</emphasis> - will bind to method arguments, so individual arguments could be extracted by name
|
||||
(e.g., <emphasis>#args.fname</emphasis> as in the above method)</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Let's look at couple of examples:
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="java">@Publisher
|
||||
public String defaultPayload(String fname, String lname) {
|
||||
return fname + " " + lname;
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In the above example the Message will be constructed with the following structure:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Message payload - will be the return type and value of the method. This is the default.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>A newly constructed message will be sent to a default publisher channel configured with annotation post processor (see the end of this section).</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="java">@Publisher(channel="testChannel")
|
||||
public String defaultPayload(String fname, @Header("last") String lname) {
|
||||
return fname + " " + lname;
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In this example everything is the same as above, however we are not using default publishing channel. Instead we are specifying
|
||||
the publishing channel via 'channel' attribute of <interface>@Publisher</interface> annotation.
|
||||
We are also adding <interface>@Header</interface> annotation which results in the Message header with the name 'last' and the value of 'lname' input parameter
|
||||
to be added to the newly constructed Message.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<programlisting language="java">@Publisher(channel="testChannel")
|
||||
@Payload
|
||||
public String defaultPayloadButExplicitAnnotation(String fname, @Header String lname) {
|
||||
return fname + " " + lname;
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The above example is almost identical to the previous one. The only difference here is that we are using <interface>@Payload</interface> annotation
|
||||
on the method, thus explicitly specifying that the return value of the method should be used as a payload of the Message.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<programlisting language="java">@Publisher(channel="testChannel")
|
||||
@Payload("#return + #args.lname")
|
||||
public String setName(String fname, String lname, @Header("x") int num) {
|
||||
return fname + " " + lname;
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Here we are expending on the previous configuration by using Spring Expression language in the <interface>@Payload</interface> annotation further instructing
|
||||
the framework on how the message should be constructed. In this particular case the message will be a concatenation of the return value of the method invocation and
|
||||
'lname' input argument. Message header 'x' with value of 'num' input argument will be added to the newly constructed Message.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<programlisting language="java">@Publisher(channel="testChannel")
|
||||
public String argumentAsPayload(@Payload String fname, @Header String lname) {
|
||||
return fname + " " + lname;
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In the above example you see another usage of <interface>@Payload</interface> annotation. Here we are annotating method argument
|
||||
which will become a payload of newly constructed message.
|
||||
</para>
|
||||
|
||||
|
||||
<para>
|
||||
As with most other annotation-driven features in Spring, you will need to register a post-processor
|
||||
(<classname>PublisherAnnotationBeanPostProcessor</classname>).
|
||||
<programlisting language="xml"><bean class="org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor"/></programlisting>
|
||||
You can also use namespace support for added convenience:
|
||||
|
||||
<programlisting language="xml"><si:annotation-config default-publisher-channel="defaultChannel"/></programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Similar to other Spring annotations (e.g., @Controller), <classname>@Publisher</classname> is a meta-annotation, which means you can define your own annotations
|
||||
that will be treated as <classname>@Publisher</classname>
|
||||
<programlisting language="java"><![CDATA[@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Publisher(channel="auditChannel")
|
||||
public @interface Audit {
|
||||
}]]></programlisting>
|
||||
Here we defined <classname>@Audit</classname> annotation which itself is a <classname>@Publisher</classname>. Also note that you can define <code>channel</code>
|
||||
attribute on the meta-annotation thus encapsulating the behavior of where messages will be sent inside of this annotation.
|
||||
|
||||
Now you can annotate any method:
|
||||
<programlisting language="java"><![CDATA[@Audit
|
||||
public String test() {
|
||||
return "foo";
|
||||
}]]></programlisting>
|
||||
|
||||
In the above example every invocation of <code>test()</code> method will result in Message with payload which is the return value of the method
|
||||
invocation to be sent to <emphasis>auditChannel</emphasis>
|
||||
|
||||
You can also annotate the class which would mean that the properties of this annotation will be applied on every public method of this class
|
||||
|
||||
<programlisting language="java"><![CDATA[@Audit
|
||||
static class BankingOperationsImpl implements BankingOperations {
|
||||
|
||||
public String debit(String amount) {
|
||||
. . .
|
||||
}
|
||||
|
||||
public String credit(String amount) {
|
||||
. . .
|
||||
}
|
||||
}]]></programlisting>
|
||||
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="aop-based-interceptor">
|
||||
<title>XML-based approach via <publishing-interceptor> element</title>
|
||||
<para>
|
||||
The XML-based approach allows you to configure the same AOP-based Message Publishing functionality with
|
||||
simple namespace-based configuration of a <classname>MessagePublishingInterceptor</classname>.
|
||||
It certainly has some benefits over the annotation-driven approach since it
|
||||
allows you to use AOP pointcut expressions, thus possibly intercepting multiple methods at once or
|
||||
intercepting and publishing methods to which you don't have the source code.
|
||||
</para>
|
||||
<para>
|
||||
To configure Message Publishing via XML, you only need to do the following two things:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Provide configuration for <classname>MessagePublishingInterceptor</classname>
|
||||
via the <code><publishing-interceptor></code> XML element.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Provide AOP configuration to apply the <classname>MessagePublishingInterceptor</classname> to managed objects.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<aop:config>
|
||||
<aop:advisor advice-ref="interceptor" pointcut="bean(testBean)" />
|
||||
</aop:config>
|
||||
<publishing-interceptor id="interceptor" default-channel="defaultChannel">
|
||||
<method pattern="echo" payload="'Echoing: ' + #return" channel="echoChannel">
|
||||
<header name="foo" value="bar"/>
|
||||
</method>
|
||||
<method pattern="repl*" payload="'Echoing: ' + #return" channel="echoChannel">
|
||||
<header name="foo" expression="'bar'.toUpperCase()"/>
|
||||
</method>
|
||||
<method pattern="echoDef*" payload="#return"/>
|
||||
</publishing-interceptor>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
As you can see the <code><publishing-interceptor></code> configuration look rather similar to Annotation-based approach
|
||||
and it also utilizes the power of the Spring 3.0 Expression Language.
|
||||
</para>
|
||||
<para>
|
||||
In the above example the execution of the <code>echo</code> method of a <code>testBean</code> will
|
||||
render a <emphasis>Message</emphasis> with the following structure:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>The Message payload will be of type String and value of "Echoing: [value]" where <code>value</code> is the value
|
||||
returned by an executed method.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The Message will have header with the key "foo" value "bar".</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The Message will be sent to <code>echoChannel</code>.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The second method is very similar to the first. Here every method that begins with 'repl' will render a Message with the following structure:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>The Message payload will be the same as in the above sample</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The Message will have header with the key "foo" and value that is the result of the SpEL expression <code>'bar'.toUpperCase()</code> .</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The Message will be sent to <code>echoChannel</code>.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The second method, mapping the execution of any method that begins with <code>echoDef</code> of <code>testBean</code>, will produce a
|
||||
Message with the following structure.
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>The Message payload will be the value returned by an executed method.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Since the <code>channel</code> attribute is not provided explicitly, the Message will be sent to the
|
||||
<code>defaultChannel</code> defined by the <emphasis>publisher</emphasis>.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For simple mapping rules you can rely on the <emphasis>publisher</emphasis> defaults. For example:
|
||||
<programlisting language="xml">
|
||||
<publishing-interceptor id="anotherInterceptor"/>
|
||||
</programlisting>
|
||||
This will map the return value of every method that matches the pointcut expression to a payload and will be sent to a <emphasis>default-channel</emphasis>.
|
||||
If the <emphasis>defaultChannel</emphasis>is not specified (as above) the messages will be sent to the global <emphasis>nullChannel</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Async Publishing</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
One important thing to understand is that publishing occurs in the same thread as your component's execution. So by default in is synchronous.
|
||||
This means that the entire message flow would have to wait until he publisher flow completes.
|
||||
However, quite often you want the complete opposite and that is to use Message publishing feature to initiate asynchronous sub-flows.
|
||||
For example, you might host a service (HTTP, WS etc.) which receives a remote request.You may want to send this request internally into a
|
||||
process that might take a while. However you may also want to reply to the user right away. So, instead of sending inbound
|
||||
request for processing via the output channel (the conventional way), you can simply use ''outout-channel or $replyChannel'' header
|
||||
to send simple acknowledgment-like reply back to the caller while using Message publisher feature to initiate a complex flow.
|
||||
</para>
|
||||
<para>
|
||||
EXAMPLE:
|
||||
Here is the simple service that receives a complex payload, which needs to be sent further for processing, but it
|
||||
also need to reply to the caller with a simple acknowledgment.
|
||||
<programlisting language="java"><![CDATA[public String echo(Object complexPayload){
|
||||
return "ACK";
|
||||
}]]></programlisting>
|
||||
So instead of hooking up the complex flow to the output channel we use Message publishing feature instead configuring it to create a
|
||||
new Message using the input argument of the service method (above) and sending it to the 'localProcessChannel'. And to make sure this sub-flow
|
||||
is asynchronous all we need to do is make sure that we send it to any type of async channel (ExecutorChannel in this example).
|
||||
<programlisting language="xml"><![CDATA[<int:service-activator input-channel="inputChannel" output-channel="outputChannel" ref="sampleservice"/>
|
||||
|
||||
<bean id="sampleservice" class="test.SampleService"/>
|
||||
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="interceptor" pointcut="bean(sampleservice)" />
|
||||
</aop:config>
|
||||
|
||||
<int:publishing-interceptor id="interceptor" >
|
||||
<int:method pattern="echo" payload="#args[0]" channel="localProcessChannel">
|
||||
<int:header name="sample_header" expression="'some sample value'"/>
|
||||
</int:method>
|
||||
</int:publishing-interceptor>
|
||||
|
||||
<int:channel id="localProcessChannel">
|
||||
<int:dispatcher task-executor="executor"/>
|
||||
</int:channel>
|
||||
<task:executor id="executor" pool-size="5"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Another way of handling thi type of scenario is through wire-tap
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="scheduled-producer">
|
||||
<title>Producing and publishing messages based on a scheduled trigger</title>
|
||||
<para>
|
||||
In the above sections we looked at the Message publishing feature of Spring Integration which constructs and publishes messages as by-products of Method invocations.
|
||||
However in that case, you are still responsible for invoking the method.
|
||||
In Spring Integration 2.0 we've added another related useful feature: support for scheduled Message producers/publishers via the new "expression" attribute
|
||||
on the 'inbound-channel-adapter' element. Scheduling could be based on several triggers, any one of which may be configured on the 'poller' sub-element.
|
||||
Currently we support <code>cron</code>, <code>fixed-rate</code>, <code>fixed-delay</code> as well as any custom trigger implemented by you.
|
||||
</para>
|
||||
<para>
|
||||
As mentioned above, support for scheduled producers/publishers is provided via the <emphasis><inbound-channel-adapter></emphasis> xml element.
|
||||
Let's look at couple of examples:
|
||||
</para>
|
||||
<para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter id="fixedDelayProducer"
|
||||
expression="'fixedDelayTest'"
|
||||
channel="fixedDelayChannel">
|
||||
<poller fixed-delay="1000"/>
|
||||
</inbound-channel-adapter>]]></programlisting>
|
||||
|
||||
In the above example an inbound Channel Adapter will be created which will construct a Message with its payload being the result of the expression
|
||||
defined in the <code>expression</code> attribute. Such message will be created and sent every time after the delay specified by the <code>fixed-delay</code> attribute.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter id="fixedRateProducer"
|
||||
expression="'fixedRateTest'"
|
||||
channel="fixedRateChannel">
|
||||
<poller fixed-rate="1000"/>
|
||||
</inbound-channel-adapter>]]></programlisting>
|
||||
|
||||
This example is very similar to the previous one, except that we are using the <code>fixed-rate</code> attribute which will allow us to send messages at a fixed rate (measuring from the start time of each task).
|
||||
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter id="cronProducer"
|
||||
expression="'cronTest'"
|
||||
channel="cronChannel">
|
||||
<poller cron="7 6 5 4 3 ?"/>
|
||||
</inbound-channel-adapter>]]></programlisting>
|
||||
|
||||
This example demonstrates how you can apply a Cron trigger with a value specified in the <code>cron</code> attribute.
|
||||
|
||||
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter id="headerExpressionsProducer"
|
||||
expression="'headerExpressionsTest'"
|
||||
channel="headerExpressionsChannel"
|
||||
auto-startup="false">
|
||||
<poller fixed-delay="5000"/>
|
||||
<header name="foo" expression="6 * 7"/>
|
||||
<header name="bar" value="x"/>
|
||||
</inbound-channel-adapter>]]></programlisting>
|
||||
|
||||
Here you can see that in a way very similar to the Message publishing feature we are enriching a newly constructed Message with
|
||||
extra Message headers which could take scalar values as well as the results of evaluating Spring expressions.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you need to implement your own custom trigger you can use the <code>trigger</code> attribute to provide a reference to any spring configured
|
||||
bean which implements the <classname>org.springframework.scheduling.Trigger</classname> interface.
|
||||
|
||||
<programlisting language="xml"><![CDATA[<inbound-channel-adapter id="triggerRefProducer"
|
||||
expression="'triggerRefTest'" channel="triggerRefChannel">
|
||||
<poller trigger="customTrigger"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<beans:bean id="customTrigger" class="org.springframework.scheduling.support.PeriodicTrigger">
|
||||
<beans:constructor-arg value="9999"/>
|
||||
</beans:bean>]]></programlisting>
|
||||
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,222 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="message">
|
||||
<title>Message Construction</title>
|
||||
<para>
|
||||
The Spring Integration <interfacename>Message</interfacename> is a generic container for data. Any object can
|
||||
be provided as the payload, and each <interfacename>Message</interfacename> also includes headers containing
|
||||
user-extensible properties as key-value pairs.
|
||||
</para>
|
||||
|
||||
<section id="message-interface">
|
||||
<title>The Message Interface</title>
|
||||
<para>Here is the definition of the <interfacename>Message</interfacename> interface:
|
||||
<programlisting language="java">public interface Message<T> {
|
||||
|
||||
T getPayload();
|
||||
|
||||
MessageHeaders getHeaders();
|
||||
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The <interfacename>Message</interfacename> is obviously a very important part of the API. By encapsulating the
|
||||
data in a generic wrapper, the messaging system can pass it around without any knowledge of the data's type. As
|
||||
an application evolves to support new types, or when the types themselves are modified and/or extended, the
|
||||
messaging system will not be affected by such changes. On the other hand, when some component in the messaging
|
||||
system <emphasis>does</emphasis> require access to information about the <interfacename>Message</interfacename>,
|
||||
such metadata can typically be stored to and retrieved from the metadata in the Message Headers.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="message-headers">
|
||||
<title>Message Headers</title>
|
||||
<para>
|
||||
Just as Spring Integration allows any Object to be used as the payload of a Message, it also supports any Object
|
||||
types as header values. In fact, the <classname>MessageHeaders</classname> class implements the
|
||||
<emphasis>java.util.Map</emphasis> interface:
|
||||
<programlisting language="java">public final class MessageHeaders implements Map<String, Object>, Serializable {
|
||||
...
|
||||
}</programlisting>
|
||||
<note>
|
||||
Even though the MessageHeaders implements Map, it is effectively a read-only implementation. Any attempt to
|
||||
<emphasis>put</emphasis> a value in the Map will result in an <classname>UnsupportedOperationException</classname>.
|
||||
The same applies for <emphasis>remove</emphasis> and <emphasis>clear</emphasis>. Since Messages may be passed to
|
||||
multiple consumers, the structure of the Map cannot be modified. Likewise, the Message's payload Object can not
|
||||
be <emphasis>set</emphasis> after the initial creation. However, the mutability of the header values themselves
|
||||
(or the payload Object) is intentionally left as a decision for the framework user.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
As an implementation of Map, the headers can obviously be retrieved by calling <methodname>get(..)</methodname>
|
||||
with the name of the header. Alternatively, you can provide the expected <emphasis>Class</emphasis> as an
|
||||
additional parameter. Even better, when retrieving one of the pre-defined values, convenient getters are
|
||||
available. Here is an example of each of these three options:
|
||||
<programlisting language="java"> Object someValue = message.getHeaders().get("someKey");
|
||||
|
||||
CustomerId customerId = message.getHeaders().get("customerId", CustomerId.class);
|
||||
|
||||
Long timestamp = message.getHeaders().getTimestamp();
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The following Message headers are pre-defined:
|
||||
<table id="message-headers-table">
|
||||
<title>Pre-defined Message Headers</title>
|
||||
<tgroup cols="2">
|
||||
<colspec align="left" />
|
||||
<thead>
|
||||
<row>
|
||||
<entry align="center">Header Name</entry>
|
||||
<entry align="center">Header Type</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>ID</entry>
|
||||
<entry>java.util.UUID</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>TIMESTAMP</entry>
|
||||
<entry>java.lang.Long</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>EXPIRATION_DATE</entry>
|
||||
<entry>java.lang.Long</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>CORRELATION_ID</entry>
|
||||
<entry>java.lang.Object</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>REPLY_CHANNEL</entry>
|
||||
<entry>java.lang.Object (can be a String or MessageChannel)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>ERROR_CHANNEL</entry>
|
||||
<entry>java.lang.Object (can be a String or MessageChannel)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>SEQUENCE_NUMBER</entry>
|
||||
<entry>java.lang.Integer</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>SEQUENCE_SIZE</entry>
|
||||
<entry>java.lang.Integer</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>PRIORITY</entry>
|
||||
<entry>MessagePriority (an <emphasis>enum</emphasis>)</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</para>
|
||||
<para>
|
||||
Many inbound and outbound adapter implementations will also provide and/or expect certain headers, and additional
|
||||
user-defined headers can also be configured.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="message-implementations">
|
||||
<title>Message Implementations</title>
|
||||
<para>
|
||||
The base implementation of the <interfacename>Message</interfacename> interface is
|
||||
<classname>GenericMessage<T></classname>, and it provides two constructors:
|
||||
<programlisting language="java">new GenericMessage<T>(T payload);
|
||||
|
||||
new GenericMessage<T>(T payload, Map<String, Object> headers)</programlisting>
|
||||
When a Message is created, a random unique id will be generated. The constructor that accepts a Map of headers
|
||||
will copy the provided headers to the newly created Message.
|
||||
</para>
|
||||
<para>
|
||||
There are also two convenient subclasses available: <classname>StringMessage</classname> and
|
||||
<classname>ErrorMessage</classname>. The former accepts a String as its payload:
|
||||
<programlisting language="java">StringMessage message = new StringMessage("hello world");
|
||||
|
||||
String s = message.getPayload();</programlisting>
|
||||
And, the latter accepts any <classname>Throwable</classname> object as its payload:
|
||||
<programlisting language="java">ErrorMessage message = new ErrorMessage(someThrowable);
|
||||
|
||||
Throwable t = message.getPayload();</programlisting>
|
||||
Notice that these implementations take advantage of the fact that the <classname>GenericMessage</classname>
|
||||
base class is parameterized. Therefore, as shown in both examples, no casting is necessary when retrieving
|
||||
the Message payload Object.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="message-builder">
|
||||
<title>The MessageBuilder Helper Class</title>
|
||||
<para>
|
||||
You may notice that the Message interface defines retrieval methods for its payload and headers but no setters.
|
||||
The reason for this is that a Message cannot be modified after its initial creation. Therefore, when a Message
|
||||
instance is sent to multiple consumers (e.g. through a Publish Subscribe Channel), if one of those consumers
|
||||
needs to send a reply with a different payload type, it will need to create a new Message. As a result, the
|
||||
other consumers are not affected by those changes. Keep in mind, that multiple consumers may access the same
|
||||
payload instance or header value, and whether such an instance is itself immutable is a decision left to the
|
||||
developer. In other words, the contract for Messages is similar to that of an
|
||||
<emphasis>unmodifiable Collection</emphasis>, and the MessageHeaders' map further exemplifies that; even though
|
||||
the MessageHeaders class implements <interfacename>java.util.Map</interfacename>, any attempt to invoke a
|
||||
<emphasis>put</emphasis> operation (or 'remove' or 'clear') on the MessageHeaders will result in an
|
||||
<classname>UnsupportedOperationException</classname>.
|
||||
</para>
|
||||
<para>
|
||||
Rather than requiring the creation and population of a Map to pass into the GenericMessage constructor, Spring
|
||||
Integration does provide a far more convenient way to construct Messages: <classname>MessageBuilder</classname>.
|
||||
The MessageBuilder provides two factory methods for creating Messages from either an existing Message or with a
|
||||
payload Object. When building from an existing Message, the headers <emphasis>and payload</emphasis> of that
|
||||
Message will be copied to the new Message:
|
||||
<programlisting language="java">Message<String> message1 = MessageBuilder.withPayload("test")
|
||||
.setHeader("foo", "bar")
|
||||
.build();
|
||||
|
||||
Message<String> message2 = MessageBuilder.fromMessage(message1).build();
|
||||
|
||||
assertEquals("test", message2.getPayload());
|
||||
assertEquals("bar", message2.getHeaders().get("foo"));</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
If you need to create a Message with a new payload but still want to copy the
|
||||
headers from an existing Message, you can use one of the 'copy' methods.
|
||||
<programlisting language="java">Message<String> message3 = MessageBuilder.withPayload("test3")
|
||||
.copyHeaders(message1.getHeaders())
|
||||
.build();
|
||||
|
||||
Message<String> message4 = MessageBuilder.withPayload("test4")
|
||||
.setHeader("foo", 123)
|
||||
.copyHeadersIfAbsent(message1.getHeaders())
|
||||
.build();
|
||||
|
||||
assertEquals("bar", message3.getHeaders().get("foo"));
|
||||
assertEquals(123, message4.getHeaders().get("foo"));</programlisting>
|
||||
Notice that the <methodname>copyHeadersIfAbsent</methodname> does not overwrite existing values. Also, in the
|
||||
second example above, you can see how to set any user-defined header with <methodname>setHeader</methodname>.
|
||||
Finally, there are set methods available for the predefined headers as well as a non-destructive method for
|
||||
setting any header (MessageHeaders also defines constants for the pre-defined header names).
|
||||
<programlisting language="java">Message<Integer> importantMessage = MessageBuilder.withPayload(99)
|
||||
.setPriority(MessagePriority.HIGHEST)
|
||||
.build();
|
||||
|
||||
assertEquals(MessagePriority.HIGHEST, importantMessage.getHeaders().getPriority());
|
||||
|
||||
Message<Integer> anotherMessage = MessageBuilder.fromMessage(importantMessage)
|
||||
.setHeaderIfAbsent(MessageHeaders.PRIORITY, MessagePriority.LOW)
|
||||
.build();
|
||||
|
||||
assertEquals(MessagePriority.HIGHEST, anotherMessage.getHeaders().getPriority());
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The <classname>MessagePriority</classname> is only considered when using a <classname>PriorityChannel</classname>
|
||||
(as described in the next chapter). It is defined as an <emphasis>enum</emphasis> with five possible values:
|
||||
<programlisting language="java">public enum MessagePriority {
|
||||
HIGHEST,
|
||||
HIGH,
|
||||
NORMAL,
|
||||
LOW,
|
||||
LOWEST
|
||||
}</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,327 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="overview">
|
||||
<title>Spring Integration Overview</title>
|
||||
|
||||
<section id="overview-background">
|
||||
<title>Background</title>
|
||||
<para>
|
||||
One of the key themes of the Spring Framework is <emphasis>inversion of control</emphasis>. In its broadest
|
||||
sense, this means that the framework handles responsibilities on behalf of the components that are managed within
|
||||
its context. The components themselves are simplified since they are relieved of those responsibilities. For
|
||||
example, <emphasis>dependency injection</emphasis> relieves the components of the responsibility of locating or
|
||||
creating their dependencies. Likewise, <emphasis>aspect-oriented programming</emphasis> relieves business
|
||||
components of generic cross-cutting concerns by modularizing them into reusable aspects. In each case, the end
|
||||
result is a system that is easier to test, understand, maintain, and extend.
|
||||
</para>
|
||||
<para>
|
||||
Furthermore, the Spring framework and portfolio provide a comprehensive programming model for building
|
||||
enterprise applications. Developers benefit from the consistency of this model and especially the fact that it is
|
||||
based upon well-established best practices such as programming to interfaces and favoring composition over
|
||||
inheritance. Spring's simplified abstractions and powerful support libraries boost developer productivity while
|
||||
simultaneously increasing the level of testability and portability.
|
||||
</para>
|
||||
<para>
|
||||
Spring Integration is a new member of the Spring portfolio motivated by these same goals and principles. It
|
||||
extends the Spring programming model into the messaging domain and builds upon Spring's existing enterprise
|
||||
integration support to provide an even higher level of abstraction. It supports message-driven architectures
|
||||
where inversion of control applies to runtime concerns, such as <emphasis>when</emphasis> certain business logic
|
||||
should execute and <emphasis>where</emphasis> the response should be sent. It supports routing and transformation
|
||||
of messages so that different transports and different data formats can be integrated without impacting
|
||||
testability. In other words, the messaging and integration concerns are handled by the framework, so business
|
||||
components are further isolated from the infrastructure and developers are relieved of complex integration
|
||||
responsibilities.
|
||||
</para>
|
||||
<para>
|
||||
As an extension of the Spring programming model, Spring Integration provides a wide variety of configuration
|
||||
options including annotations, XML with namespace support, XML with generic "bean" elements, and of course direct
|
||||
usage of the underlying API. That API is based upon well-defined strategy interfaces and non-invasive, delegating
|
||||
adapters. Spring Integration's design is inspired by the recognition of a strong affinity between common patterns
|
||||
within Spring and the well-known <ulink url="http://www.eaipatterns.com">Enterprise Integration Patterns</ulink>
|
||||
as described in the book of the same name by Gregor Hohpe and Bobby Woolf (Addison Wesley, 2004). Developers who
|
||||
have read that book should be immediately comfortable with the Spring Integration concepts and terminology.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-goalsandprinciples">
|
||||
<title>Goals and Principles</title>
|
||||
<para>Spring Integration is motivated by the following goals:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Provide a simple model for implementing complex enterprise integration solutions.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Facilitate asynchronous, message-driven behavior within a Spring-based application.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Promote intuitive, incremental adoption for existing Spring users.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>Spring Integration is guided by the following principles:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Components should be <emphasis>loosely coupled</emphasis> for modularity and testability.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>The framework should enforce <emphasis>separation of concerns</emphasis> between business logic and
|
||||
integration logic.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Extension points should be abstract in nature but within well-defined boundaries to promote
|
||||
<emphasis>reuse</emphasis> and <emphasis>portability</emphasis>.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-components">
|
||||
<title>Main Components</title>
|
||||
<para>
|
||||
From the <emphasis>vertical</emphasis> perspective, a layered architecture facilitates separation of concerns,
|
||||
and interface-based contracts between layers promote loose coupling. Spring-based applications are typically
|
||||
designed this way, and the Spring framework and portfolio provide a strong foundation for following this best
|
||||
practice for the full-stack of an enterprise application. Message-driven architectures add a
|
||||
<emphasis>horizontal</emphasis> perspective, yet these same goals are still relevant. Just as "layered
|
||||
architecture" is an extremely generic and abstract paradigm, messaging systems typically follow the similarly
|
||||
abstract "pipes-and-filters" model. The "filters" represent any component that is capable of producing and/or
|
||||
consuming messages, and the "pipes" transport the messages between filters so that the components themselves
|
||||
remain loosely-coupled. It is important to note that these two high-level paradigms are not mutually exclusive.
|
||||
The underlying messaging infrastructure that supports the "pipes" should still be encapsulated in a layer whose
|
||||
contracts are defined as interfaces. Likewise, the "filters" themselves would typically be managed within a layer
|
||||
that is logically above the application's service layer, interacting with those services through interfaces much
|
||||
in the same way that a web-tier would.
|
||||
</para>
|
||||
|
||||
<section id="overview-components-message">
|
||||
<title>Message</title>
|
||||
<para>
|
||||
In Spring Integration, a Message is a generic wrapper for any Java object combined with metadata used by the
|
||||
framework while handling that object. It consists of a payload and headers. The payload can be of any type and
|
||||
the headers hold commonly required information such as id, timestamp, expiration, and return address. Headers
|
||||
are also used for passing values to and from connected transports. For example, when creating a Message from a
|
||||
received File, the file name may be stored in a header to be accessed by downstream components. Likewise, if a
|
||||
Message's content is ultimately going to be sent by an outbound Mail adapter, the various properties (to, from,
|
||||
cc, subject, etc.) may be configured as Message header values by an upstream component. Developers can also
|
||||
store any arbitrary key-value pairs in the headers.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/message.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/message.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-components-channel">
|
||||
<title>Message Channel</title>
|
||||
<para>
|
||||
A Message Channel represents the "pipe" of a pipes-and-filters architecture. Producers send Messages to
|
||||
a channel, and consumers receive Messages from a channel. The Message Channel therefore decouples the
|
||||
messaging components, and also provides a convenient point for interception and monitoring of Messages.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/channel.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/channel.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
A Message Channel may follow either Point-to-Point or Publish/Subscribe semantics. With a Point-to-Point
|
||||
channel, at most one consumer can receive each Message sent to the channel. Publish/Subscribe channels, on the
|
||||
other hand, will attempt to broadcast each Message to all of its subscribers. Spring Integration supports
|
||||
both of these.
|
||||
</para>
|
||||
<para>
|
||||
Whereas "Point-to-Point" and "Publish/Subscribe" define the two options for <emphasis>how many</emphasis>
|
||||
consumers will ultimately receive each Message, there is another important consideration: should the channel
|
||||
buffer messages? In Spring Integration, <emphasis>Pollable Channels</emphasis> are capable of buffering
|
||||
Messages within a queue. The advantage of buffering is that it allows for throttling the inbound Messages and
|
||||
thereby prevents overloading a consumer. However, as the name suggests, this also adds some complexity, since a
|
||||
consumer can only receive the Messages from such a channel if a <emphasis>poller</emphasis> is configured. On
|
||||
the other hand, a consumer connected to a <emphasis>Subscribable Channel</emphasis> is simply Message-driven.
|
||||
The variety of channel implementations available in Spring Integration will be discussed in detail in
|
||||
<xref linkend="channel-implementations"/>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-components-endpoint">
|
||||
<title>Message Endpoint</title>
|
||||
<para>
|
||||
One of the primary goals of Spring Integration is to simplify the development of enterprise integration
|
||||
solutions through <emphasis>inversion of control</emphasis>. This means that you should not have to implement
|
||||
consumers and producers directly, and you should not even have to build Messages and invoke send or receive
|
||||
operations on a Message Channel. Instead, you should be able to focus on your specific domain model with an
|
||||
implementation based on plain Objects. Then, by providing declarative configuration, you can "connect"
|
||||
your domain-specific code to the messaging infrastructure provided by Spring Integration. The components
|
||||
responsible for these connections are Message Endpoints. This does not mean that you will necessarily connect
|
||||
your existing application code directly. Any real-world enterprise integration solution will require some
|
||||
amount of code focused upon integration concerns such as <emphasis>routing</emphasis> and
|
||||
<emphasis>transformation</emphasis>. The important thing is to achieve separation of concerns between such
|
||||
integration logic and business logic. In other words, as with the Model-View-Controller paradigm for web
|
||||
applications, the goal should be to provide a thin but dedicated layer that translates inbound requests into
|
||||
service layer invocations, and then translates service layer return values into outbound replies. The next
|
||||
section will provide an overview of the Message Endpoint types that handle these responsibilities, and in
|
||||
upcoming chapters, you will see how Spring Integration's declarative configuration options provide a
|
||||
non-invasive way to use each of these.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints">
|
||||
<title>Message Endpoints</title>
|
||||
<para>
|
||||
A Message Endpoint represents the "filter" of a pipes-and-filters architecture. As mentioned above, the
|
||||
endpoint's primary role is to connect application code to the messaging framework and to do so in a non-invasive
|
||||
manner. In other words, the application code should ideally have no awareness of the Message objects or the
|
||||
Message Channels. This is similar to the role of a Controller in the MVC paradigm. Just as a Controller handles
|
||||
HTTP requests, the Message Endpoint handles Messages. Just as Controllers are mapped to URL patterns, Message
|
||||
Endpoints are mapped to Message Channels. The goal is the same in both cases: isolate application code from the
|
||||
infrastructure. These concepts are discussed at length along with all of the patterns that follow in the
|
||||
<ulink url="http://www.eaipatterns.com">Enterprise Integration Patterns</ulink> book. Here, we provide only a
|
||||
high-level description of the main endpoint types supported by Spring Integration and their roles. The chapters
|
||||
that follow will elaborate and provide sample code as well as configuration examples.
|
||||
</para>
|
||||
|
||||
<section id="overview-endpoints-transformer">
|
||||
<title>Transformer</title>
|
||||
<para>
|
||||
A Message Transformer is responsible for converting a Message's content or structure and returning the modified
|
||||
Message. Probably the most common type of transformer is one that converts the payload of the Message from one
|
||||
format to another (e.g. from XML Document to java.lang.String). Similarly, a transformer may be used to add,
|
||||
remove, or modify the Message's header values.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-filter">
|
||||
<title>Filter</title>
|
||||
<para>
|
||||
A Message Filter determines whether a Message should be passed to an output channel at all. This simply
|
||||
requires a boolean test method that may check for a particular payload content type, a property value, the
|
||||
presence of a header, etc. If the Message is accepted, it is sent to the output channel, but if not it will be
|
||||
dropped (or for a more severe implementation, an Exception could be thrown). Message Filters are often used in
|
||||
conjunction with a Publish Subscribe channel, where multiple consumers may receive the same Message and use the
|
||||
filter to narrow down the set of Messages to be processed based on some criteria.
|
||||
<note>
|
||||
Be careful not to confuse the generic use of "filter" within the Pipes-and-Filters architectural pattern with
|
||||
this specific endpoint type that selectively narrows down the Messages flowing between two channels. The
|
||||
Pipes-and-Filters concept of "filter" matches more closely with Spring Integration's Message Endpoint: any
|
||||
component that can be connected to Message Channel(s) in order to send and/or receive Messages.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-router">
|
||||
<title>Router</title>
|
||||
<para>
|
||||
A Message Router is responsible for deciding what channel or channels should receive the Message next (if any).
|
||||
Typically the decision is based upon the Message's content and/or metadata available in the Message Headers.
|
||||
A Message Router is often used as a dynamic alternative to a statically configured output channel on
|
||||
a Service Activator or other endpoint capable of sending reply Messages. Likewise, a Message Router provides a
|
||||
proactive alternative to the reactive Message Filters used by multiple subscribers as described above.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/router.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/router.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-splitter">
|
||||
<title>Splitter</title>
|
||||
<para>
|
||||
A Splitter is another type of Message Endpoint whose responsibility is to accept a Message from its input
|
||||
channel, split that Message into multiple Messages, and then send each of those to its output channel. This
|
||||
is typically used for dividing a "composite" payload object into a group of Messages containing the
|
||||
sub-divided payloads.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-aggregator">
|
||||
<title>Aggregator</title>
|
||||
<para>
|
||||
Basically a mirror-image of the Splitter, the Aggregator is a type of Message Endpoint that receives multiple
|
||||
Messages and combines them into a single Message. In fact, Aggregators are often downstream consumers in a
|
||||
pipeline that includes a Splitter. Technically, the Aggregator is more complex than a Splitter, because it
|
||||
is required to maintain state (the Messages to-be-aggregated), to decide when the complete group of Messages
|
||||
is available, and to timeout if necessary. Furthermore, in case of a timeout, the Aggregator needs to know
|
||||
whether to send the partial results or to discard them to a separate channel. Spring Integration provides
|
||||
a <interfacename>CompletionStrategy</interfacename> as well as configurable settings for timeout, whether
|
||||
to send partial results upon timeout, and the discard channel.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-service-activator">
|
||||
<title>Service Activator</title>
|
||||
<para>
|
||||
A Service Activator is a generic endpoint for connecting a service instance to the messaging system. The
|
||||
input Message Channel must be configured, and if the service method to be invoked is capable of returning a
|
||||
value, an output Message Channel may also be provided.
|
||||
<note>
|
||||
The output channel is optional, since each Message may also provide its own 'Return Address' header. This
|
||||
same rule applies for all consumer endpoints.
|
||||
</note>
|
||||
The Service Activator invokes an operation on some service object to process the request Message, extracting
|
||||
the request Message's payload and converting if necessary (if the method does not expect a Message-typed
|
||||
parameter). Whenever the service object's method returns a value, that return value will likewise be converted
|
||||
to a reply Message if necessary (if it's not already a Message). That reply Message is sent to the output
|
||||
channel. If no output channel has been configured, then the reply will be sent to the channel specified in the
|
||||
Message's "return address" if available.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/handler-endpoint.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/handler-endpoint.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<caption>
|
||||
A request-reply "Service Activator" endpoint connects a target object's method to input and output
|
||||
Message Channels.
|
||||
</caption>
|
||||
</mediaobject>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="overview-endpoints-channeladapter">
|
||||
<title>Channel Adapter</title>
|
||||
<para>
|
||||
A Channel Adapter is an endpoint that connects a Message Channel to some other system or transport. Channel
|
||||
Adapters may be either inbound or outbound. Typically, the Channel Adapter will do some mapping between the
|
||||
Message and whatever object or resource is received-from or sent-to the other system (File, HTTP Request, JMS
|
||||
Message, etc). Depending on the transport, the Channel Adapter may also populate or extract Message header
|
||||
values. Spring Integration provides a number of Channel Adapters, and they will be described in upcoming
|
||||
chapters.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/source-endpoint.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/source-endpoint.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<caption>An inbound "Channel Adapter" endpoint connects a source system to a MessageChannel.</caption>
|
||||
</mediaobject>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/target-endpoint.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/target-endpoint.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<caption>An outbound "Channel Adapter" endpoint connects a MessageChannel to a target system.</caption>
|
||||
</mediaobject>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="resequencer">
|
||||
<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 with XML</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[<channel id="inputChannel"/>
|
||||
|
||||
<channel id="outputChannel"/>
|
||||
|
||||
<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[ /> ]]></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 where the resequencer will send the reordered
|
||||
messages. <emphasis>Optional</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="resxml4-co" id="resxml4">
|
||||
<para>The channel where 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>
|
||||
|
||||
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
|
||||
|
||||
<code>Comparator</code>
|
||||
|
||||
to be used to order the messages when sending (use the XML attribute
|
||||
|
||||
<literal>comparator</literal>
|
||||
|
||||
to point to a bean definition). If
|
||||
|
||||
<literal>release-partial-sequences</literal>
|
||||
|
||||
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
|
||||
|
||||
<literal>release-strategy</literal>
|
||||
|
||||
(also a reference to another bean definition, either a POJO or a
|
||||
|
||||
<code>ReleaseStrategy</code>
|
||||
|
||||
).
|
||||
</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 for sending out messages.
|
||||
<emphasis>Optional</emphasis>.</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>
|
||||
</chapter>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<appendix id="resources">
|
||||
<title>Additional Resources</title>
|
||||
|
||||
<section id="resources-home">
|
||||
<title>Spring Integration Home</title>
|
||||
<para>
|
||||
The definitive source of information about Spring Integration is the
|
||||
<ulink url="http://www.springsource.org/spring-integration">Spring Integration Home</ulink> at
|
||||
<ulink url="http://www.springsource.org">http://www.springsource.org</ulink>. That site serves as a hub of
|
||||
information and is the best place to find up-to-date announcements about the project as well as links to
|
||||
articles, blogs, and new sample applications.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</appendix>
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
code highlight CSS resemblign the Eclipse IDE default color schema
|
||||
@author Costin Leau
|
||||
*/
|
||||
|
||||
.hl-keyword {
|
||||
color: #7F0055;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hl-comment {
|
||||
color: #3F5F5F;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-multiline-comment {
|
||||
color: #3F5FBF;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-tag {
|
||||
color: #3F7F7F;
|
||||
}
|
||||
|
||||
.hl-attribute {
|
||||
color: #7F007F;
|
||||
}
|
||||
|
||||
.hl-value {
|
||||
color: #2A00FF;
|
||||
}
|
||||
|
||||
.hl-string {
|
||||
color: #2A00FF;
|
||||
}
|
||||
@@ -1,421 +0,0 @@
|
||||
body {
|
||||
text-align: justify;
|
||||
margin-right: 2em;
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
||||
a,
|
||||
a[accesskey^
|
||||
|
||||
=
|
||||
"h"
|
||||
]
|
||||
,
|
||||
a[accesskey^
|
||||
|
||||
=
|
||||
"n"
|
||||
]
|
||||
,
|
||||
a[accesskey^
|
||||
|
||||
=
|
||||
"u"
|
||||
]
|
||||
,
|
||||
a[accesskey^
|
||||
|
||||
=
|
||||
"p"
|
||||
]
|
||||
{
|
||||
font-family: Verdana, Arial, helvetica, sans-serif
|
||||
|
||||
;
|
||||
font-size:
|
||||
|
||||
12
|
||||
px
|
||||
|
||||
;
|
||||
color: #003399
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
a:active {
|
||||
color: #003399;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
p {
|
||||
font-family: Verdana, Arial, sans-serif;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-family: Verdana, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
p, dl, dt, dd, blockquote {
|
||||
color: #000000;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 3px;
|
||||
padding-top: 0px;
|
||||
}
|
||||
|
||||
ol, ul, p {
|
||||
margin-top: 6px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
p, blockquote {
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
p.releaseinfo {
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
p.pubdate {
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
td {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
td, th, span {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
td[width^
|
||||
|
||||
=
|
||||
"40%"
|
||||
]
|
||||
{
|
||||
font-family: Verdana, Arial, helvetica, sans-serif
|
||||
|
||||
;
|
||||
font-size:
|
||||
|
||||
12
|
||||
px
|
||||
|
||||
;
|
||||
color: #003399
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
table[summary^
|
||||
|
||||
=
|
||||
"Navigation header"
|
||||
]
|
||||
tbody tr th[colspan^
|
||||
|
||||
=
|
||||
"3"
|
||||
]
|
||||
{
|
||||
font-family: Verdana, Arial, helvetica, sans-serif
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h6, H6 {
|
||||
color: #000000;
|
||||
font-weight: 500;
|
||||
margin-top: 0px;
|
||||
padding-top: 14px;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
h2.title {
|
||||
font-weight: 800;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
h2.subtitle {
|
||||
font-weight: 800;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.firstname, .surname {
|
||||
font-size: 12px;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
border: 1px black;
|
||||
empty-cells: hide;
|
||||
margin: 10px 0px 30px 50px;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
div.table {
|
||||
margin: 30px 0px 30px 0px;
|
||||
border: 1px dashed gray;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
div .table-contents table {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
div.table > p.title {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
table[summary^
|
||||
|
||||
=
|
||||
"Navigation footer"
|
||||
]
|
||||
{
|
||||
border-collapse: collapse
|
||||
|
||||
;
|
||||
border-spacing:
|
||||
|
||||
0
|
||||
;
|
||||
border:
|
||||
|
||||
1
|
||||
px black
|
||||
|
||||
;
|
||||
empty-cells: hide
|
||||
|
||||
;
|
||||
margin:
|
||||
|
||||
0
|
||||
px
|
||||
|
||||
;
|
||||
width:
|
||||
|
||||
100
|
||||
%
|
||||
;
|
||||
}
|
||||
|
||||
table[summary^
|
||||
|
||||
=
|
||||
"Note"
|
||||
]
|
||||
,
|
||||
table[summary^
|
||||
|
||||
=
|
||||
"Warning"
|
||||
]
|
||||
,
|
||||
table[summary^
|
||||
|
||||
=
|
||||
"Tip"
|
||||
]
|
||||
{
|
||||
border-collapse: collapse
|
||||
|
||||
;
|
||||
border-spacing:
|
||||
|
||||
0
|
||||
;
|
||||
border:
|
||||
|
||||
1
|
||||
px black
|
||||
|
||||
;
|
||||
empty-cells: hide
|
||||
|
||||
;
|
||||
margin:
|
||||
|
||||
10
|
||||
px
|
||||
|
||||
0
|
||||
px
|
||||
|
||||
10
|
||||
px
|
||||
|
||||
-
|
||||
20
|
||||
px
|
||||
|
||||
;
|
||||
width:
|
||||
|
||||
100
|
||||
%
|
||||
;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 4pt;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
div.warning TD {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 150%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 90%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
h5 {
|
||||
font-size: 90%;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
h6 {
|
||||
font-size: 100%;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
tt {
|
||||
font-size: 110%;
|
||||
font-family: "Courier New", Courier, monospace;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.navheader, .navfooter {
|
||||
border: none;
|
||||
}
|
||||
|
||||
div.navfooter table {
|
||||
border: dashed gray;
|
||||
border-width: 1px 1px 1px 1px;
|
||||
background-color: #cde48d;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-size: 110%;
|
||||
padding: 5px;
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-color: #CCCCCC;
|
||||
background-color: #f3f5e9;
|
||||
}
|
||||
|
||||
ul, ol, li {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
hr {
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
background-color: #CCCCCC;
|
||||
border-width: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.variablelist {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.term {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.mediaobject {
|
||||
padding-top: 30px;
|
||||
padding-bottom: 30px;
|
||||
}
|
||||
|
||||
.legalnotice {
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
float: right;
|
||||
margin: 10px 0px 10px 30px;
|
||||
padding: 10px 20px 20px 20px;
|
||||
width: 33%;
|
||||
border: 1px solid black;
|
||||
background-color: #F4F4F4;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.property {
|
||||
font-family: "Courier New", Courier, monospace;
|
||||
}
|
||||
|
||||
a code {
|
||||
font-family: Verdana, Arial, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
td code {
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
div.note * td,
|
||||
div.tip * td,
|
||||
div.warning * td,
|
||||
div.calloutlist * td {
|
||||
text-align: justify;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
.programlisting .interfacename,
|
||||
.programlisting .literal,
|
||||
.programlisting .classname {
|
||||
font-size: 95%;
|
||||
}
|
||||
|
||||
.title .interfacename,
|
||||
.title .literal,
|
||||
.title .classname {
|
||||
font-size: 130%;
|
||||
}
|
||||
|
||||
/* everything in a <lineannotation/> is displayed in a coloured, comment-like font */
|
||||
.programlisting * .lineannotation,
|
||||
.programlisting * .lineannotation * {
|
||||
color: green;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
@IMPORT url("highlight.css");
|
||||
|
||||
html {
|
||||
padding: 0pt;
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-left: 10%;
|
||||
margin-right: 10%;
|
||||
font-family: Arial, Sans-serif;
|
||||
}
|
||||
|
||||
div {
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid gray;
|
||||
background: gray;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4 {
|
||||
color: #234623;
|
||||
font-family: Arial, Sans-serif;
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1.0;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre.programlisting {
|
||||
font-size: 10pt;
|
||||
padding: 7pt 3pt;
|
||||
border: 1pt solid black;
|
||||
background: #eeeeee;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
div.table {
|
||||
margin: 1em;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.table table {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.table td {
|
||||
padding-left: 7px;
|
||||
padding-right: 7px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
float: right;
|
||||
margin: 10px 0 10px 30px;
|
||||
padding: 10px 20px 20px 20px;
|
||||
width: 33%;
|
||||
border: 1px solid black;
|
||||
background-color: #F4F4F4;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.mediaobject {
|
||||
padding-top: 30px;
|
||||
padding-bottom: 30px;
|
||||
}
|
||||
|
||||
.legalnotice {
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
p.releaseinfo {
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
p.pubdate {
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
}
|
||||
|
||||
span.productname {
|
||||
font-size: 200%;
|
||||
font-weight: bold;
|
||||
font-family: Verdana, Arial, helvetica, sans-serif;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 36 KiB |
@@ -1,418 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This is the XSL FO (PDF) stylesheet for the Spring reference
|
||||
documentation.
|
||||
|
||||
Thanks are due to Christian Bauer of the Hibernate project
|
||||
team for writing the original stylesheet upon which this one
|
||||
is based.
|
||||
-->
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
version="1.0">
|
||||
|
||||
|
||||
<xsl:import href="urn:docbkx:stylesheet"/>
|
||||
|
||||
<!--###################################################
|
||||
Custom Title Page
|
||||
################################################### -->
|
||||
|
||||
<xsl:template name="book.titlepage.recto">
|
||||
<fo:block>
|
||||
<fo:table table-layout="fixed" width="175mm">
|
||||
<fo:table-column column-width="175mm"/>
|
||||
<fo:table-body>
|
||||
<fo:table-row>
|
||||
<fo:table-cell text-align="center">
|
||||
<fo:block>
|
||||
<fo:block font-family="Helvetica" font-size="24pt" padding-before="10mm">
|
||||
<xsl:value-of select="bookinfo/title"/>
|
||||
</fo:block>
|
||||
</fo:block>
|
||||
<fo:block font-family="Helvetica" font-size="22pt" padding-before="10mm">
|
||||
<xsl:value-of select="bookinfo/subtitle"/>
|
||||
</fo:block>
|
||||
<fo:block font-family="Helvetica" font-size="12pt" padding="10mm">
|
||||
<xsl:value-of select="bookinfo/releaseinfo"/>
|
||||
</fo:block>
|
||||
</fo:table-cell>
|
||||
</fo:table-row>
|
||||
<fo:table-row>
|
||||
<fo:table-cell text-align="center">
|
||||
<fo:block font-family="Helvetica" font-size="14pt" padding="10mm">
|
||||
<xsl:value-of select="bookinfo/pubdate"/>
|
||||
</fo:block>
|
||||
</fo:table-cell>
|
||||
</fo:table-row>
|
||||
<fo:table-row>
|
||||
<fo:table-cell text-align="center">
|
||||
<fo:block font-family="Helvetica" font-size="12pt" padding="10mm">
|
||||
<xsl:text>Copyright © 2005-2010 </xsl:text>
|
||||
<xsl:for-each select="bookinfo/authorgroup/author">
|
||||
<xsl:if test="position() > 1">
|
||||
<xsl:text>, </xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="firstname"/>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:value-of select="surname"/>
|
||||
</xsl:for-each>
|
||||
</fo:block>
|
||||
<fo:block font-family="Helvetica" font-size="10pt" padding="1mm">
|
||||
<xsl:value-of select="bookinfo/legalnotice"/>
|
||||
</fo:block>
|
||||
</fo:table-cell>
|
||||
</fo:table-row>
|
||||
</fo:table-body>
|
||||
</fo:table>
|
||||
</fo:block>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Prevent blank pages in output -->
|
||||
<xsl:template name="book.titlepage.before.verso">
|
||||
</xsl:template>
|
||||
<xsl:template name="book.titlepage.verso">
|
||||
</xsl:template>
|
||||
<xsl:template name="book.titlepage.separator">
|
||||
</xsl:template>
|
||||
|
||||
<!--###################################################
|
||||
Header
|
||||
################################################### -->
|
||||
|
||||
<!-- More space in the center header for long text -->
|
||||
<xsl:attribute-set name="header.content.properties">
|
||||
<xsl:attribute name="font-family">
|
||||
<xsl:value-of select="$body.font.family"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="margin-left">-5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-right">-5em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Custom Footer
|
||||
################################################### -->
|
||||
<xsl:template name="footer.content">
|
||||
<xsl:param name="pageclass" select="''"/>
|
||||
<xsl:param name="sequence" select="''"/>
|
||||
<xsl:param name="position" select="''"/>
|
||||
<xsl:param name="gentext-key" select="''"/>
|
||||
<xsl:variable name="Version">
|
||||
<xsl:if test="//releaseinfo">
|
||||
<xsl:text>Spring-Integration (</xsl:text>
|
||||
<xsl:value-of select="//releaseinfo"/>
|
||||
<xsl:text>)</xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$sequence='blank'">
|
||||
<xsl:if test="$position = 'center'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:if>
|
||||
</xsl:when>
|
||||
<!-- for double sided printing, print page numbers on alternating sides (of the page) -->
|
||||
<xsl:when test="$double.sided != 0">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$sequence = 'even' and $position='left'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$sequence = 'odd' and $position='right'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$position='center'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<!-- for single sided printing, print all page numbers on the right (of the page) -->
|
||||
<xsl:when test="$double.sided = 0">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$position='center'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$position='right'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!--###################################################
|
||||
Extensions
|
||||
################################################### -->
|
||||
|
||||
<!-- These extensions are required for table printing and other stuff -->
|
||||
<xsl:param name="use.extensions">1</xsl:param>
|
||||
<xsl:param name="tablecolumns.extension">0</xsl:param>
|
||||
<xsl:param name="callout.extensions">1</xsl:param>
|
||||
<!-- FOP provide only PDF Bookmarks at the moment -->
|
||||
<xsl:param name="fop.extensions">1</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Table Of Contents
|
||||
################################################### -->
|
||||
|
||||
<!-- Generate the TOCs for named components only -->
|
||||
<xsl:param name="generate.toc">
|
||||
book toc
|
||||
</xsl:param>
|
||||
|
||||
<!-- Show only Sections up to level 3 in the TOCs -->
|
||||
<xsl:param name="toc.section.depth">2</xsl:param>
|
||||
|
||||
<!-- Dot and Whitespace as separator in TOC between Label and Title-->
|
||||
<xsl:param name="autotoc.label.separator" select="'. '"/>
|
||||
|
||||
|
||||
<!--###################################################
|
||||
Paper & Page Size
|
||||
################################################### -->
|
||||
|
||||
<!-- Paper type, no headers on blank pages, no double sided printing -->
|
||||
<xsl:param name="paper.type" select="'A4'"/>
|
||||
<xsl:param name="double.sided">0</xsl:param>
|
||||
<xsl:param name="headers.on.blank.pages">0</xsl:param>
|
||||
<xsl:param name="footers.on.blank.pages">0</xsl:param>
|
||||
|
||||
<!-- Space between paper border and content (chaotic stuff, don't touch) -->
|
||||
<xsl:param name="page.margin.top">5mm</xsl:param>
|
||||
<xsl:param name="region.before.extent">10mm</xsl:param>
|
||||
<xsl:param name="body.margin.top">10mm</xsl:param>
|
||||
|
||||
<xsl:param name="body.margin.bottom">15mm</xsl:param>
|
||||
<xsl:param name="region.after.extent">10mm</xsl:param>
|
||||
<xsl:param name="page.margin.bottom">0mm</xsl:param>
|
||||
|
||||
<xsl:param name="page.margin.outer">18mm</xsl:param>
|
||||
<xsl:param name="page.margin.inner">18mm</xsl:param>
|
||||
|
||||
<!-- No intendation of Titles -->
|
||||
<xsl:param name="title.margin.left">0pc</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Fonts & Styles
|
||||
################################################### -->
|
||||
|
||||
<!-- Left aligned text and no hyphenation -->
|
||||
<xsl:param name="alignment">justify</xsl:param>
|
||||
<xsl:param name="hyphenate">false</xsl:param>
|
||||
|
||||
<!-- Default Font size -->
|
||||
<xsl:param name="body.font.master">11</xsl:param>
|
||||
<xsl:param name="body.font.small">8</xsl:param>
|
||||
|
||||
<!-- Line height in body text -->
|
||||
<xsl:param name="line-height">1.4</xsl:param>
|
||||
|
||||
<!-- Monospaced fonts are smaller than regular text -->
|
||||
<xsl:attribute-set name="monospace.properties">
|
||||
<xsl:attribute name="font-family">
|
||||
<xsl:value-of select="$monospace.font.family"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="font-size">0.8em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Tables
|
||||
################################################### -->
|
||||
|
||||
<!-- The table width should be adapted to the paper size -->
|
||||
<xsl:param name="default.table.width">17.4cm</xsl:param>
|
||||
|
||||
<!-- Some padding inside tables -->
|
||||
<xsl:attribute-set name="table.cell.padding">
|
||||
<xsl:attribute name="padding-left">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-right">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-top">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-bottom">4pt</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Only hairlines as frame and cell borders in tables -->
|
||||
<xsl:param name="table.frame.border.thickness">0.1pt</xsl:param>
|
||||
<xsl:param name="table.cell.border.thickness">0.1pt</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Labels
|
||||
################################################### -->
|
||||
|
||||
<!-- Label Chapters and Sections (numbering) -->
|
||||
<xsl:param name="chapter.autolabel">1</xsl:param>
|
||||
<xsl:param name="section.autolabel" select="1"/>
|
||||
<xsl:param name="section.label.includes.component.label" select="1"/>
|
||||
|
||||
<!--###################################################
|
||||
Titles
|
||||
################################################### -->
|
||||
|
||||
<!-- Chapter title size -->
|
||||
<xsl:attribute-set name="chapter.titlepage.recto.style">
|
||||
<xsl:attribute name="text-align">left</xsl:attribute>
|
||||
<xsl:attribute name="font-weight">bold</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.8"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Why is the font-size for chapters hardcoded in the XSL FO templates?
|
||||
Let's remove it, so this sucker can use our attribute-set only... -->
|
||||
<xsl:template match="title" mode="chapter.titlepage.recto.auto.mode">
|
||||
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
xsl:use-attribute-sets="chapter.titlepage.recto.style">
|
||||
<xsl:call-template name="component.title">
|
||||
<xsl:with-param name="node" select="ancestor-or-self::chapter[1]"/>
|
||||
</xsl:call-template>
|
||||
</fo:block>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Sections 1, 2 and 3 titles have a small bump factor and padding -->
|
||||
<xsl:attribute-set name="section.title.level1.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.5"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="section.title.level2.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.25"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="section.title.level3.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.0"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Titles of formal objects (tables, examples, ...) -->
|
||||
<xsl:attribute-set name="formal.title.properties" use-attribute-sets="normal.para.spacing">
|
||||
<xsl:attribute name="font-weight">bold</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="hyphenate">false</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.8em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Programlistings
|
||||
################################################### -->
|
||||
|
||||
<!-- Verbatim text formatting (programlistings) -->
|
||||
<xsl:attribute-set name="monospace.verbatim.properties">
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.small * 1.0"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<xsl:attribute-set name="verbatim.properties">
|
||||
<xsl:attribute name="space-before.minimum">1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.optimum">1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">1em</xsl:attribute>
|
||||
<xsl:attribute name="border-color">#444444</xsl:attribute>
|
||||
<xsl:attribute name="border-style">solid</xsl:attribute>
|
||||
<xsl:attribute name="border-width">0.1pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-top">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-left">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-right">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-bottom">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-left">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-right">0.5em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Shade (background) programlistings -->
|
||||
<xsl:param name="shade.verbatim">1</xsl:param>
|
||||
<xsl:attribute-set name="shade.verbatim.style">
|
||||
<xsl:attribute name="background-color">#F0F0F0</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Callouts
|
||||
################################################### -->
|
||||
|
||||
<!-- Use images for callouts instead of (1) (2) (3) -->
|
||||
<xsl:param name="callout.graphics">0</xsl:param>
|
||||
<xsl:param name="callout.unicode">1</xsl:param>
|
||||
|
||||
<!-- Place callout marks at this column in annotated areas -->
|
||||
<xsl:param name="callout.defaultcolumn">90</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Admonitions
|
||||
################################################### -->
|
||||
|
||||
<!-- Use nice graphics for admonitions -->
|
||||
<xsl:param name="admon.graphics">'1'</xsl:param>
|
||||
<!-- <xsl:param name="admon.graphics.path">&admon_gfx_path;</xsl:param> -->
|
||||
|
||||
<!--###################################################
|
||||
Misc
|
||||
################################################### -->
|
||||
|
||||
<!-- Placement of titles -->
|
||||
<xsl:param name="formal.title.placement">
|
||||
figure after
|
||||
example before
|
||||
equation before
|
||||
table before
|
||||
procedure before
|
||||
</xsl:param>
|
||||
|
||||
<!-- Format Variable Lists as Blocks (prevents horizontal overflow) -->
|
||||
<xsl:param name="variablelist.as.blocks">1</xsl:param>
|
||||
|
||||
<!-- The horrible list spacing problems -->
|
||||
<xsl:attribute-set name="list.block.spacing">
|
||||
<xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
colored and hyphenated links
|
||||
################################################### -->
|
||||
<xsl:template match="ulink">
|
||||
<fo:basic-link external-destination="{@url}"
|
||||
xsl:use-attribute-sets="xref.properties"
|
||||
text-decoration="underline"
|
||||
color="blue">
|
||||
<xsl:choose>
|
||||
<xsl:when test="count(child::node())=0">
|
||||
<xsl:value-of select="@url"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</fo:basic-link>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
@@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This is the XSL HTML configuration file for the Spring
|
||||
Reference Documentation.
|
||||
-->
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
version="1.0">
|
||||
|
||||
<xsl:import href="urn:docbkx:stylesheet"/>
|
||||
|
||||
<!--###################################################
|
||||
HTML Settings
|
||||
################################################### -->
|
||||
|
||||
<xsl:param name="html.stylesheet">html.css</xsl:param>
|
||||
|
||||
<!-- These extensions are required for table printing and other stuff -->
|
||||
<xsl:param name="use.extensions">1</xsl:param>
|
||||
<xsl:param name="tablecolumns.extension">0</xsl:param>
|
||||
<xsl:param name="callout.extensions">1</xsl:param>
|
||||
<xsl:param name="graphicsize.extension">0</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Table Of Contents
|
||||
################################################### -->
|
||||
|
||||
<!-- Generate the TOCs for named components only -->
|
||||
<xsl:param name="generate.toc">
|
||||
book toc
|
||||
</xsl:param>
|
||||
|
||||
<!-- Show only Sections up to level 3 in the TOCs -->
|
||||
<xsl:param name="toc.section.depth">3</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Labels
|
||||
################################################### -->
|
||||
|
||||
<!-- Label Chapters and Sections (numbering) -->
|
||||
<xsl:param name="chapter.autolabel">1</xsl:param>
|
||||
<xsl:param name="section.autolabel" select="1"/>
|
||||
<xsl:param name="section.label.includes.component.label" select="1"/>
|
||||
|
||||
<!--###################################################
|
||||
Callouts
|
||||
################################################### -->
|
||||
|
||||
<!-- Use images for callouts instead of (1) (2) (3) -->
|
||||
<xsl:param name="callout.graphics">0</xsl:param>
|
||||
|
||||
<!-- Place callout marks at this column in annotated areas -->
|
||||
<xsl:param name="callout.defaultcolumn">90</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Admonitions
|
||||
################################################### -->
|
||||
|
||||
<!-- Use nice graphics for admonitions -->
|
||||
<xsl:param name="admon.graphics">0</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Misc
|
||||
################################################### -->
|
||||
<!-- Placement of titles -->
|
||||
<xsl:param name="formal.title.placement">
|
||||
figure after
|
||||
example before
|
||||
equation before
|
||||
table before
|
||||
procedure before
|
||||
</xsl:param>
|
||||
<xsl:template match="author" mode="titlepage.mode">
|
||||
<xsl:if test="name(preceding-sibling::*[1]) = 'author'">
|
||||
<xsl:text>, </xsl:text>
|
||||
</xsl:if>
|
||||
<span class="{name(.)}">
|
||||
<xsl:call-template name="person.name"/>
|
||||
<xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
|
||||
<xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
|
||||
</span>
|
||||
</xsl:template>
|
||||
<xsl:template match="authorgroup" mode="titlepage.mode">
|
||||
<div class="{name(.)}">
|
||||
<h2>Authors</h2>
|
||||
<p/>
|
||||
<xsl:apply-templates mode="titlepage.mode"/>
|
||||
</div>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
@@ -1,136 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:xslthl="http://xslthl.sf.net"
|
||||
exclude-result-prefixes="xslthl"
|
||||
version='1.0'>
|
||||
|
||||
<xsl:param name="chunk.section.depth">'5'</xsl:param>
|
||||
<xsl:param name="use.id.as.filename" select="1"/>
|
||||
|
||||
<!-- Extensions -->
|
||||
<xsl:param name="use.extensions">1</xsl:param>
|
||||
<xsl:param name="tablecolumns.extension">0</xsl:param>
|
||||
<xsl:param name="callout.extensions">1</xsl:param>
|
||||
|
||||
<!-- Activate Graphics -->
|
||||
<xsl:param name="admon.graphics" select="1"/>
|
||||
<xsl:param name="admon.graphics.path">images/</xsl:param>
|
||||
<xsl:param name="admon.graphics.extension">.gif</xsl:param>
|
||||
<xsl:param name="callout.graphics" select="1" />
|
||||
<xsl:param name="callout.defaultcolumn">120</xsl:param>
|
||||
<xsl:param name="callout.graphics.path">images/callouts/</xsl:param>
|
||||
<xsl:param name="callout.graphics.extension">.gif</xsl:param>
|
||||
|
||||
<xsl:param name="table.borders.with.css" select="1"/>
|
||||
<xsl:param name="html.stylesheet">css/stylesheet.css</xsl:param>
|
||||
<xsl:param name="html.stylesheet.type">text/css</xsl:param>
|
||||
<xsl:param name="generate.toc">book toc,title</xsl:param>
|
||||
|
||||
<xsl:param name="admonition.title.properties">text-align: left</xsl:param>
|
||||
|
||||
<!-- Label Chapters and Sections (numbering) -->
|
||||
<xsl:param name="chapter.autolabel" select="1"/>
|
||||
<xsl:param name="section.autolabel" select="1"/>
|
||||
<xsl:param name="section.autolabel.max.depth" select="3"/>
|
||||
|
||||
<xsl:param name="section.label.includes.component.label" select="1"/>
|
||||
<xsl:param name="table.footnote.number.format" select="'1'"/>
|
||||
|
||||
<!-- Show only Sections up to level 3 in the TOCs -->
|
||||
<xsl:param name="toc.section.depth">3</xsl:param>
|
||||
|
||||
<!-- Remove "Chapter" from the Chapter titles... -->
|
||||
<xsl:param name="local.l10n.xml" select="document('')"/>
|
||||
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
|
||||
<l:l10n language="en">
|
||||
<l:context name="title-numbered">
|
||||
<l:template name="chapter" text="%n. %t"/>
|
||||
<l:template name="section" text="%n %t"/>
|
||||
</l:context>
|
||||
</l:l10n>
|
||||
</l:i18n>
|
||||
|
||||
<!-- Use code syntax highlighting -->
|
||||
<xsl:param name="highlight.source" select="1"/>
|
||||
|
||||
<xsl:template match='xslthl:keyword'>
|
||||
<span class="hl-keyword"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:comment'>
|
||||
<span class="hl-comment"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:oneline-comment'>
|
||||
<span class="hl-comment"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:multiline-comment'>
|
||||
<span class="hl-multiline-comment"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:tag'>
|
||||
<span class="hl-tag"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:attribute'>
|
||||
<span class="hl-attribute"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:value'>
|
||||
<span class="hl-value"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:string'>
|
||||
<span class="hl-string"><xsl:value-of select='.'/></span>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Google Analytics -->
|
||||
<xsl:template name="user.head.content">
|
||||
<xsl:comment>Begin Google Analytics code</xsl:comment>
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var pageTracker = _gat._getTracker("UA-2728886-3");
|
||||
pageTracker._setDomainName("none");
|
||||
pageTracker._setAllowLinker(true);
|
||||
pageTracker._trackPageview();
|
||||
</script>
|
||||
<xsl:comment>End Google Analytics code</xsl:comment>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Loopfuse -->
|
||||
<xsl:template name="user.footer.content">
|
||||
<xsl:comment>Begin LoopFuse code</xsl:comment>
|
||||
<script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript">
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
_lf_cid = "LF_48be82fa";
|
||||
_lf_remora();
|
||||
</script>
|
||||
<xsl:comment>End LoopFuse code</xsl:comment>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
@@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
|
||||
xmlns:param="http://nwalsh.com/docbook/xsl/template/1.0/param"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
|
||||
<!-- ==================================================================== -->
|
||||
|
||||
<t:titlepage t:element="book" t:wrapper="div" class="titlepage">
|
||||
<t:titlepage-content t:side="recto">
|
||||
<productname/>
|
||||
<title/>
|
||||
<subtitle/>
|
||||
<!-- <corpauthor/>
|
||||
<authorgroup/>
|
||||
<author/>
|
||||
<mediaobject/> -->
|
||||
<othercredit/>
|
||||
<releaseinfo/>
|
||||
<copyright/>
|
||||
<legalnotice/>
|
||||
<pubdate/>
|
||||
<revision/>
|
||||
<revhistory/>
|
||||
<abstract/>
|
||||
</t:titlepage-content>
|
||||
|
||||
<t:titlepage-content t:side="verso">
|
||||
</t:titlepage-content>
|
||||
|
||||
<t:titlepage-separator>
|
||||
<hr/>
|
||||
</t:titlepage-separator>
|
||||
|
||||
<t:titlepage-before t:side="recto">
|
||||
</t:titlepage-before>
|
||||
|
||||
<t:titlepage-before t:side="verso">
|
||||
</t:titlepage-before>
|
||||
</t:titlepage>
|
||||
|
||||
</t:templates>
|
||||
@@ -1,208 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This is the XSL HTML configuration file for the Spring Reference Documentation.
|
||||
-->
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
version="1.0">
|
||||
|
||||
<xsl:import href="urn:docbkx:stylesheet"/>
|
||||
<!--###################################################
|
||||
HTML Settings
|
||||
################################################### -->
|
||||
<xsl:param name="chunk.section.depth">'5'</xsl:param>
|
||||
<xsl:param name="use.id.as.filename">'1'</xsl:param>
|
||||
<!-- These extensions are required for table printing and other stuff -->
|
||||
<xsl:param name="use.extensions">1</xsl:param>
|
||||
<xsl:param name="tablecolumns.extension">0</xsl:param>
|
||||
<xsl:param name="callout.extensions">1</xsl:param>
|
||||
<xsl:param name="graphicsize.extension">0</xsl:param>
|
||||
<!--###################################################
|
||||
Table Of Contents
|
||||
################################################### -->
|
||||
<!-- Generate the TOCs for named components only -->
|
||||
<xsl:param name="generate.toc">
|
||||
book toc
|
||||
</xsl:param>
|
||||
<!-- Show only Sections up to level 3 in the TOCs -->
|
||||
<xsl:param name="toc.section.depth">3</xsl:param>
|
||||
<!--###################################################
|
||||
Labels
|
||||
################################################### -->
|
||||
<!-- Label Chapters and Sections (numbering) -->
|
||||
<xsl:param name="chapter.autolabel">1</xsl:param>
|
||||
<xsl:param name="section.autolabel" select="1"/>
|
||||
<xsl:param name="section.label.includes.component.label" select="1"/>
|
||||
<!--###################################################
|
||||
Callouts
|
||||
################################################### -->
|
||||
<!-- Place callout marks at this column in annotated areas -->
|
||||
<xsl:param name="callout.graphics">1</xsl:param>
|
||||
<xsl:param name="callout.defaultcolumn">90</xsl:param>
|
||||
<!--###################################################
|
||||
Misc
|
||||
################################################### -->
|
||||
<!-- Placement of titles -->
|
||||
<xsl:param name="formal.title.placement">
|
||||
figure after
|
||||
example before
|
||||
equation before
|
||||
table before
|
||||
procedure before
|
||||
</xsl:param>
|
||||
<xsl:template match="author" mode="titlepage.mode">
|
||||
<xsl:if test="name(preceding-sibling::*[1]) = 'author'">
|
||||
<xsl:text>, </xsl:text>
|
||||
</xsl:if>
|
||||
<span class="{name(.)}">
|
||||
<xsl:call-template name="person.name"/>
|
||||
<xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
|
||||
<xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
|
||||
</span>
|
||||
</xsl:template>
|
||||
<xsl:template match="authorgroup" mode="titlepage.mode">
|
||||
<div class="{name(.)}">
|
||||
<h2>Authors</h2>
|
||||
<p/>
|
||||
<xsl:apply-templates mode="titlepage.mode"/>
|
||||
</div>
|
||||
</xsl:template>
|
||||
<!--###################################################
|
||||
Headers and Footers
|
||||
################################################### -->
|
||||
<!-- let's have a Spring and SpringSource banner across the top of each page -->
|
||||
<xsl:template name="user.header.navigation">
|
||||
<div style="background-color:white;border:none;height:73px;border:1px solid black;">
|
||||
<a style="border:none;" href="http://static.springframework.org/spring-ws/site/"
|
||||
title="The Spring Framework - Spring Web Services">
|
||||
<img style="border:none;" src="images/xdev-spring_logo.jpg"/>
|
||||
</a>
|
||||
<a style="border:none;" href="http://www.springsource.com/" title="SpringSource">
|
||||
<img style="border:none;position:absolute;padding-top:5px;right:42px;" src="images/s2_box_logo.png"/>
|
||||
</a>
|
||||
</div>
|
||||
</xsl:template>
|
||||
<!-- no other header navigation (prev, next, etc.) -->
|
||||
<xsl:template name="header.navigation"/>
|
||||
<xsl:param name="navig.showtitles">1</xsl:param>
|
||||
<!-- let's have a 'Sponsored by SpringSource' strapline (or somesuch) across the bottom of each page -->
|
||||
<xsl:template name="footer.navigation">
|
||||
<xsl:param name="prev" select="/foo"/>
|
||||
<xsl:param name="next" select="/foo"/>
|
||||
<xsl:param name="nav.context"/>
|
||||
<xsl:variable name="home" select="/*[1]"/>
|
||||
<xsl:variable name="up" select="parent::*"/>
|
||||
<xsl:variable name="row1" select="count($prev) > 0
|
||||
or count($up) > 0
|
||||
or count($next) > 0"/>
|
||||
<xsl:variable name="row2" select="($prev and $navig.showtitles != 0)
|
||||
or (generate-id($home) != generate-id(.)
|
||||
or $nav.context = 'toc')
|
||||
or ($chunk.tocs.and.lots != 0
|
||||
and $nav.context != 'toc')
|
||||
or ($next and $navig.showtitles != 0)"/>
|
||||
<xsl:if test="$suppress.navigation = '0' and $suppress.footer.navigation = '0'">
|
||||
<div class="navfooter">
|
||||
<xsl:if test="$footer.rule != 0">
|
||||
<hr/>
|
||||
</xsl:if>
|
||||
<xsl:if test="$row1 or $row2">
|
||||
<table width="100%" summary="Navigation footer">
|
||||
<xsl:if test="$row1">
|
||||
<tr>
|
||||
<td width="40%" align="left">
|
||||
<xsl:if test="count($prev)>0">
|
||||
<a accesskey="p">
|
||||
<xsl:attribute name="href">
|
||||
<xsl:call-template name="href.target">
|
||||
<xsl:with-param name="object" select="$prev"/>
|
||||
</xsl:call-template>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name="navig.content">
|
||||
<xsl:with-param name="direction" select="'prev'"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
</xsl:if>
|
||||
<xsl:text> </xsl:text>
|
||||
</td>
|
||||
|
||||
<td width="20%" align="center">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$home != . or $nav.context = 'toc'">
|
||||
<a accesskey="h">
|
||||
<xsl:attribute name="href">
|
||||
<xsl:call-template name="href.target">
|
||||
<xsl:with-param name="object" select="$home"/>
|
||||
</xsl:call-template>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name="navig.content">
|
||||
<xsl:with-param name="direction" select="'home'"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
<xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
|
||||
<xsl:text> | </xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:when>
|
||||
<xsl:otherwise> </xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
|
||||
<a accesskey="t">
|
||||
<xsl:attribute name="href">
|
||||
<xsl:apply-templates select="/*[1]" mode="recursive-chunk-filename">
|
||||
<xsl:with-param name="recursive" select="true()"/>
|
||||
</xsl:apply-templates>
|
||||
<xsl:text>-toc</xsl:text>
|
||||
<xsl:value-of select="$html.ext"/>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name="gentext">
|
||||
<xsl:with-param name="key" select="'nav-toc'"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
</xsl:if>
|
||||
</td>
|
||||
<td width="40%" align="right">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:if test="count($next)>0">
|
||||
<a accesskey="n">
|
||||
<xsl:attribute name="href">
|
||||
<xsl:call-template name="href.target">
|
||||
<xsl:with-param name="object" select="$next"/>
|
||||
</xsl:call-template>
|
||||
</xsl:attribute>
|
||||
<xsl:call-template name="navig.content">
|
||||
<xsl:with-param name="direction" select="'next'"/>
|
||||
</xsl:call-template>
|
||||
</a>
|
||||
</xsl:if>
|
||||
</td>
|
||||
</tr>
|
||||
</xsl:if>
|
||||
<xsl:if test="$row2">
|
||||
<tr>
|
||||
<td width="40%" align="left" valign="top">
|
||||
<xsl:if test="$navig.showtitles != 0">
|
||||
<xsl:apply-templates select="$prev" mode="object.title.markup"/>
|
||||
</xsl:if>
|
||||
<xsl:text> </xsl:text>
|
||||
</td>
|
||||
<td width="20%" align="center">
|
||||
<span style="color:white;font-size:90%;">
|
||||
<a href="http://www.springsource.com/"
|
||||
title="SpringSource">Sponsored by SpringSource
|
||||
</a>
|
||||
</span>
|
||||
</td>
|
||||
<td width="40%" align="right" valign="top">
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:if test="$navig.showtitles != 0">
|
||||
<xsl:apply-templates select="$next" mode="object.title.markup"/>
|
||||
</xsl:if>
|
||||
</td>
|
||||
</tr>
|
||||
</xsl:if>
|
||||
</table>
|
||||
</xsl:if>
|
||||
</div>
|
||||
</xsl:if>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
@@ -1,518 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
xmlns:xslthl="http://xslthl.sf.net"
|
||||
exclude-result-prefixes="xslthl"
|
||||
version='1.0'>
|
||||
|
||||
<!-- Use nice graphics for admonitions -->
|
||||
<xsl:param name="admon.graphics">'1'</xsl:param>
|
||||
<xsl:param name="admon.graphics.path">@file.prefix@@dbf.xsl@/images/</xsl:param>
|
||||
<xsl:param name="draft.watermark.image" select="'@file.prefix@@dbf.xsl@/images/draft.png'"/>
|
||||
<xsl:param name="paper.type" select="'@paper.type@'"/>
|
||||
|
||||
<xsl:param name="page.margin.top" select="'1cm'"/>
|
||||
<xsl:param name="region.before.extent" select="'1cm'"/>
|
||||
<xsl:param name="body.margin.top" select="'1.5cm'"/>
|
||||
|
||||
<xsl:param name="body.margin.bottom" select="'1.5cm'"/>
|
||||
<xsl:param name="region.after.extent" select="'1cm'"/>
|
||||
<xsl:param name="page.margin.bottom" select="'1cm'"/>
|
||||
<xsl:param name="title.margin.left" select="'0cm'"/>
|
||||
|
||||
<!--###################################################
|
||||
Header
|
||||
################################################### -->
|
||||
|
||||
<!-- More space in the center header for long text -->
|
||||
<xsl:attribute-set name="header.content.properties">
|
||||
<xsl:attribute name="font-family">
|
||||
<xsl:value-of select="$body.font.family"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="margin-left">-5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-right">-5em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Table of Contents
|
||||
################################################### -->
|
||||
|
||||
<xsl:param name="generate.toc">
|
||||
book toc,title
|
||||
</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Custom Header
|
||||
################################################### -->
|
||||
|
||||
<xsl:template name="header.content">
|
||||
<xsl:param name="pageclass" select="''"/>
|
||||
<xsl:param name="sequence" select="''"/>
|
||||
<xsl:param name="position" select="''"/>
|
||||
<xsl:param name="gentext-key" select="''"/>
|
||||
|
||||
<xsl:variable name="Version">
|
||||
<xsl:choose>
|
||||
<xsl:when test="//productname">
|
||||
<xsl:value-of select="//productname"/><xsl:text> </xsl:text>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:text>please define productname in your docbook file!</xsl:text>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$sequence='blank'">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$position='center'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
<!-- nop -->
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$pageclass='titlepage'">
|
||||
<!-- nop: other titlepage sequences have no header -->
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$position='center'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
<!-- nop -->
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!--###################################################
|
||||
Custom Footer
|
||||
################################################### -->
|
||||
|
||||
<xsl:template name="footer.content">
|
||||
<xsl:param name="pageclass" select="''"/>
|
||||
<xsl:param name="sequence" select="''"/>
|
||||
<xsl:param name="position" select="''"/>
|
||||
<xsl:param name="gentext-key" select="''"/>
|
||||
|
||||
<xsl:variable name="Version">
|
||||
<xsl:choose>
|
||||
<xsl:when test="//releaseinfo">
|
||||
<xsl:value-of select="//releaseinfo"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- nop -->
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="Title">
|
||||
<xsl:value-of select="//title"/>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$sequence='blank'">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$double.sided != 0 and $position = 'left'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided = 0 and $position = 'center'">
|
||||
<!-- nop -->
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
<fo:page-number/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$pageclass='titlepage'">
|
||||
<!-- nop: other titlepage sequences have no footer -->
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided != 0 and $sequence = 'even' and $position='left'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided != 0 and $sequence = 'odd' and $position='right'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided = 0 and $position='right'">
|
||||
<fo:page-number/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided != 0 and $sequence = 'odd' and $position='left'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided != 0 and $sequence = 'even' and $position='right'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$double.sided = 0 and $position='left'">
|
||||
<xsl:value-of select="$Version"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="$position='center'">
|
||||
<xsl:value-of select="$Title"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
<!-- nop -->
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="processing-instruction('hard-pagebreak')">
|
||||
<fo:block break-before='page'/>
|
||||
</xsl:template>
|
||||
|
||||
<!--###################################################
|
||||
Extensions
|
||||
################################################### -->
|
||||
|
||||
<!-- These extensions are required for table printing and other stuff -->
|
||||
<xsl:param name="use.extensions">1</xsl:param>
|
||||
<xsl:param name="tablecolumns.extension">0</xsl:param>
|
||||
<xsl:param name="callout.extensions">1</xsl:param>
|
||||
<xsl:param name="fop.extensions">1</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Paper & Page Size
|
||||
################################################### -->
|
||||
|
||||
<!-- Paper type, no headers on blank pages, no double sided printing -->
|
||||
<xsl:param name="double.sided">0</xsl:param>
|
||||
<xsl:param name="headers.on.blank.pages">0</xsl:param>
|
||||
<xsl:param name="footers.on.blank.pages">0</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Fonts & Styles
|
||||
################################################### -->
|
||||
|
||||
<xsl:param name="hyphenate">false</xsl:param>
|
||||
|
||||
<!-- Default Font size -->
|
||||
<xsl:param name="body.font.master">11</xsl:param>
|
||||
<xsl:param name="body.font.small">8</xsl:param>
|
||||
|
||||
<!-- Line height in body text -->
|
||||
<xsl:param name="line-height">1.4</xsl:param>
|
||||
|
||||
<!-- Chapter title size -->
|
||||
<xsl:attribute-set name="chapter.titlepage.recto.style">
|
||||
<xsl:attribute name="text-align">left</xsl:attribute>
|
||||
<xsl:attribute name="font-weight">bold</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.8"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Why is the font-size for chapters hardcoded in the XSL FO templates?
|
||||
Let's remove it, so this sucker can use our attribute-set only... -->
|
||||
<xsl:template match="title" mode="chapter.titlepage.recto.auto.mode">
|
||||
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
xsl:use-attribute-sets="chapter.titlepage.recto.style">
|
||||
<xsl:call-template name="component.title">
|
||||
<xsl:with-param name="node" select="ancestor-or-self::chapter[1]"/>
|
||||
</xsl:call-template>
|
||||
</fo:block>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Sections 1, 2 and 3 titles have a small bump factor and padding -->
|
||||
<xsl:attribute-set name="section.title.level1.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.5"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="section.title.level2.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.6em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.25"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="section.title.level3.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.4em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 1.0"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
<xsl:attribute-set name="section.title.level4.properties">
|
||||
<xsl:attribute name="space-before.optimum">0.3em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.3em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.3em</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master * 0.9"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Use code syntax highlighting -->
|
||||
<xsl:param name="highlight.source" select="1"/>
|
||||
<xsl:param name="highlight.default.language" select="xml" />
|
||||
|
||||
<xsl:template match='xslthl:keyword'>
|
||||
<fo:inline font-weight="bold" color="#7F0055"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:comment'>
|
||||
<fo:inline font-style="italic" color="#3F5F5F"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:oneline-comment'>
|
||||
<fo:inline font-style="italic" color="#3F5F5F"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:multiline-comment'>
|
||||
<fo:inline font-style="italic" color="#3F5FBF"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:tag'>
|
||||
<fo:inline color="#3F7F7F"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:attribute'>
|
||||
<fo:inline color="#7F007F"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:value'>
|
||||
<fo:inline color="#2A00FF"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match='xslthl:string'>
|
||||
<fo:inline color="#2A00FF"><xsl:apply-templates/></fo:inline>
|
||||
</xsl:template>
|
||||
|
||||
<!--###################################################
|
||||
Tables
|
||||
################################################### -->
|
||||
|
||||
<!-- Some padding inside tables -->
|
||||
<xsl:attribute-set name="table.cell.padding">
|
||||
<xsl:attribute name="padding-left">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-right">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-top">4pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-bottom">4pt</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Only hairlines as frame and cell borders in tables -->
|
||||
<xsl:param name="table.frame.border.thickness">0.1pt</xsl:param>
|
||||
<xsl:param name="table.cell.border.thickness">0.1pt</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Labels
|
||||
################################################### -->
|
||||
|
||||
<!-- Label Chapters and Sections (numbering) -->
|
||||
<xsl:param name="chapter.autolabel" select="1"/>
|
||||
<xsl:param name="section.autolabel" select="1"/>
|
||||
<xsl:param name="section.autolabel.max.depth" select="1"/>
|
||||
|
||||
<xsl:param name="section.label.includes.component.label" select="1"/>
|
||||
<xsl:param name="table.footnote.number.format" select="'1'"/>
|
||||
|
||||
<!--###################################################
|
||||
Programlistings
|
||||
################################################### -->
|
||||
|
||||
<!-- Verbatim text formatting (programlistings) -->
|
||||
<xsl:attribute-set name="monospace.verbatim.properties">
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.small * 1.0"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<xsl:attribute-set name="verbatim.properties">
|
||||
<xsl:attribute name="space-before.minimum">1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.optimum">1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
|
||||
<xsl:attribute name="border-color">#444444</xsl:attribute>
|
||||
<xsl:attribute name="border-style">solid</xsl:attribute>
|
||||
<xsl:attribute name="border-width">0.1pt</xsl:attribute>
|
||||
<xsl:attribute name="padding-top">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-left">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-right">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="padding-bottom">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-left">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="margin-right">0.5em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!-- Shade (background) programlistings -->
|
||||
<xsl:param name="shade.verbatim">1</xsl:param>
|
||||
<xsl:attribute-set name="shade.verbatim.style">
|
||||
<xsl:attribute name="background-color">#F0F0F0</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<xsl:attribute-set name="list.block.spacing">
|
||||
<xsl:attribute name="space-before.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<xsl:attribute-set name="example.properties">
|
||||
<xsl:attribute name="space-before.minimum">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.optimum">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.5em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="keep-together.within-column">always</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Title information for Figures, Examples etc.
|
||||
################################################### -->
|
||||
|
||||
<xsl:attribute-set name="formal.title.properties" use-attribute-sets="normal.para.spacing">
|
||||
<xsl:attribute name="font-weight">normal</xsl:attribute>
|
||||
<xsl:attribute name="font-style">italic</xsl:attribute>
|
||||
<xsl:attribute name="font-size">
|
||||
<xsl:value-of select="$body.font.master"/>
|
||||
<xsl:text>pt</xsl:text>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="hyphenate">false</xsl:attribute>
|
||||
<xsl:attribute name="space-before.minimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.optimum">0.1em</xsl:attribute>
|
||||
<xsl:attribute name="space-before.maximum">0.1em</xsl:attribute>
|
||||
</xsl:attribute-set>
|
||||
|
||||
<!--###################################################
|
||||
Callouts
|
||||
################################################### -->
|
||||
|
||||
<!-- don't use images for callouts -->
|
||||
<xsl:param name="callout.graphics">0</xsl:param>
|
||||
<xsl:param name="callout.unicode">1</xsl:param>
|
||||
|
||||
<!-- Place callout marks at this column in annotated areas -->
|
||||
<xsl:param name="callout.defaultcolumn">90</xsl:param>
|
||||
|
||||
<!--###################################################
|
||||
Misc
|
||||
################################################### -->
|
||||
|
||||
<!-- Placement of titles -->
|
||||
<xsl:param name="formal.title.placement">
|
||||
figure after
|
||||
example after
|
||||
equation before
|
||||
table before
|
||||
procedure before
|
||||
</xsl:param>
|
||||
|
||||
<!-- Format Variable Lists as Blocks (prevents horizontal overflow) -->
|
||||
<xsl:param name="variablelist.as.blocks">1</xsl:param>
|
||||
|
||||
<xsl:param name="body.start.indent">0pt</xsl:param>
|
||||
|
||||
<!-- Show only Sections up to level 3 in the TOCs -->
|
||||
<xsl:param name="toc.section.depth">3</xsl:param>
|
||||
|
||||
<!-- Remove "Chapter" from the Chapter titles... -->
|
||||
<xsl:param name="local.l10n.xml" select="document('')"/>
|
||||
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
|
||||
<l:l10n language="en">
|
||||
<l:context name="title-numbered">
|
||||
<l:template name="chapter" text="%n. %t"/>
|
||||
<l:template name="section" text="%n %t"/>
|
||||
</l:context>
|
||||
<l:context name="title">
|
||||
<l:template name="example" text="Example %n %t"/>
|
||||
</l:context>
|
||||
</l:l10n>
|
||||
</l:i18n>
|
||||
|
||||
<!--###################################################
|
||||
colored and hyphenated links
|
||||
################################################### -->
|
||||
|
||||
<xsl:template match="ulink">
|
||||
<fo:basic-link external-destination="{@url}"
|
||||
xsl:use-attribute-sets="xref.properties"
|
||||
text-decoration="underline"
|
||||
color="blue">
|
||||
<xsl:choose>
|
||||
<xsl:when test="count(child::node())=0">
|
||||
<xsl:value-of select="@url"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</fo:basic-link>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="link">
|
||||
<fo:basic-link internal-destination="{@linkend}"
|
||||
xsl:use-attribute-sets="xref.properties"
|
||||
text-decoration="underline"
|
||||
color="blue">
|
||||
<xsl:choose>
|
||||
<xsl:when test="count(child::node())=0">
|
||||
<xsl:value-of select="@linkend"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</fo:basic-link>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE t:templates [
|
||||
<!ENTITY hsize0 "10pt">
|
||||
<!ENTITY hsize1 "12pt">
|
||||
<!ENTITY hsize2 "14.4pt">
|
||||
<!ENTITY hsize3 "17.28pt">
|
||||
<!ENTITY hsize4 "20.736pt">
|
||||
<!ENTITY hsize5 "24.8832pt">
|
||||
<!ENTITY hsize0space "7.5pt"> <!-- 0.75 * hsize0 -->
|
||||
<!ENTITY hsize1space "9pt"> <!-- 0.75 * hsize1 -->
|
||||
<!ENTITY hsize2space "10.8pt"> <!-- 0.75 * hsize2 -->
|
||||
<!ENTITY hsize3space "12.96pt"> <!-- 0.75 * hsize3 -->
|
||||
<!ENTITY hsize4space "15.552pt"> <!-- 0.75 * hsize4 -->
|
||||
<!ENTITY hsize5space "18.6624pt"> <!-- 0.75 * hsize5 -->
|
||||
]>
|
||||
<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
|
||||
xmlns:param="http://nwalsh.com/docbook/xsl/template/1.0/param"
|
||||
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
|
||||
<t:titlepage t:element="book" t:wrapper="fo:block">
|
||||
<t:titlepage-content t:side="recto">
|
||||
<title
|
||||
t:named-template="division.title"
|
||||
param:node="ancestor-or-self::book[1]"
|
||||
text-align="center"
|
||||
font-size="&hsize5;"
|
||||
space-before="&hsize5space;"
|
||||
font-weight="bold"
|
||||
font-family="{$title.fontset}"/>
|
||||
<subtitle
|
||||
text-align="center"
|
||||
font-size="&hsize4;"
|
||||
space-before="&hsize4space;"
|
||||
font-family="{$title.fontset}"/>
|
||||
|
||||
<!-- <corpauthor space-before="0.5em"
|
||||
font-size="&hsize2;"/>
|
||||
<authorgroup space-before="0.5em"
|
||||
font-size="&hsize2;"/>
|
||||
<author space-before="0.5em"
|
||||
font-size="&hsize2;"/> -->
|
||||
|
||||
<mediaobject space-before="2em" space-after="2em"/>
|
||||
<releaseinfo space-before="5em" font-size="&hsize2;"/>
|
||||
<copyright space-before="1.5em"
|
||||
font-weight="normal"
|
||||
font-size="8"/>
|
||||
<legalnotice space-before="5em"
|
||||
font-weight="normal"
|
||||
font-style="italic"
|
||||
font-size="8"/>
|
||||
<othercredit space-before="2em"
|
||||
font-weight="normal"
|
||||
font-size="8"/>
|
||||
<pubdate space-before="0.5em"/>
|
||||
<revision space-before="0.5em"/>
|
||||
<revhistory space-before="0.5em"/>
|
||||
<abstract space-before="0.5em"
|
||||
text-align="start"
|
||||
margin-left="0.5in"
|
||||
margin-right="0.5in"
|
||||
font-family="{$body.fontset}"/>
|
||||
</t:titlepage-content>
|
||||
|
||||
<t:titlepage-content t:side="verso">
|
||||
</t:titlepage-content>
|
||||
|
||||
<t:titlepage-separator>
|
||||
</t:titlepage-separator>
|
||||
|
||||
<t:titlepage-before t:side="recto">
|
||||
</t:titlepage-before>
|
||||
|
||||
<t:titlepage-before t:side="verso">
|
||||
</t:titlepage-before>
|
||||
</t:titlepage>
|
||||
|
||||
<!-- ==================================================================== -->
|
||||
|
||||
</t:templates>
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="rmi">
|
||||
<title>RMI Support</title>
|
||||
|
||||
<section id="rmi-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
This Chapter explains how to use RMI specific channel adapters to distribute a system over multiple JVMs. The first section will deal with sending messages over RMI. The second section shows how to receive messages over RMI. The last section shows how to define rmi channel adapters through the namespace support.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="rmi-outbound">
|
||||
<title>Outbound RMI</title>
|
||||
<para>
|
||||
To send messages from a channel over RMI, simply define an <classname>RmiOutboundGateway</classname>. This gateway will use Spring's RmiProxyFactoryBean internally to create a proxy for a remote gateway. Note that to invoke a remote interface that doesn't use Spring Integration you should use a service activator in combination with Spring's RmiProxyFactoryBean.
|
||||
</para>
|
||||
<para>
|
||||
To configure the outbound gateway write a bean definition like this:
|
||||
<programlisting language="xml"><![CDATA[ <bean id="rmiOutGateway" class=org.spf.integration.rmi.RmiOutboundGateway>
|
||||
<constructor-arg value="rmi://host"/>
|
||||
<property name="replyChannel" value="replies"/>
|
||||
</bean>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="rmi-inbound">
|
||||
<title>Inbound RMI</title>
|
||||
<para>
|
||||
To receive messages over RMI you need to use a <classname>RmiInboundGateway</classname>. This gateway can be configured like this
|
||||
<programlisting language="xml"><![CDATA[ <bean id="rmiOutGateway" class=org.spf.integration.rmi.RmiInboundGateway>
|
||||
<property name="requestChannel" value="requests"/>
|
||||
</bean>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="rmi-namespace">
|
||||
<title>RMI namespace support</title>
|
||||
<para>
|
||||
To configure the inbound gateway you can choose to use the namespace support for it. The following code snippet shows the different configuration options that are supported.
|
||||
<programlisting language="xml"><![CDATA[ <rmi:inbound-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
|
||||
expect-reply="false" request-timeout="123" reply-timeout="456"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithHost" request-channel="testChannel"
|
||||
registry-host="localhost"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithPort" request-channel="testChannel"
|
||||
registry-port="1234"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithExecutorRef" request-channel="testChannel"
|
||||
remote-invocation-executor="invocationExecutor"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure the outbound gateway you can use the namespace support as well. The following code snippet shows the different configuration for an outbound rmi gateway.
|
||||
<programlisting language="xml"><![CDATA[ <rmi:outbound-gateway id="gateway"
|
||||
request-channel="localChannel"
|
||||
remote-channel="testChannel"
|
||||
host="localhost"/>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,406 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="router">
|
||||
<title>Router</title>
|
||||
|
||||
<section id="router-implementations">
|
||||
<title>Router Implementations</title>
|
||||
<para>
|
||||
Since content-based routing often requires some domain-specific logic, most use-cases will require
|
||||
Spring Integration's options for delegating to POJOs using the XML namespace support and/or Annotations.
|
||||
Both of these are discussed below, but first we present a couple implementations that are available
|
||||
out-of-the-box since they fulfill generic, but common, requirements.
|
||||
</para>
|
||||
<section id="router-implementations-payloadtyperouter">
|
||||
<title>PayloadTypeRouter</title>
|
||||
<para>
|
||||
A <classname>PayloadTypeRouter</classname> will send Messages to the channel as defined by payload-type
|
||||
mappings.
|
||||
<programlisting language="xml"><![CDATA[<bean id="payloadTypeRouter" class="org.springframework.integration.router.PayloadTypeRouter">
|
||||
<property name="payloadTypeChannelMap">
|
||||
<map>
|
||||
<entry key="java.lang.String" value-ref="stringChannel"/>
|
||||
<entry key="java.lang.Integer" value-ref="integerChannel"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Configuration of <classname>PayloadTypeRouter</classname> is also supported via the namespace provided by Spring Integration (see <xref linkend="configuration-namespace"/>),
|
||||
which essentially simplifies configuration by combining <code><router/></code> configuration and its corresponding implementation defined using <code><bean/></code> element
|
||||
into a single and more concise configuration element.
|
||||
The example below demonstrates <classname>PayloadTypeRouter</classname> configuration which is equivalent to the one above using Spring Integration's namespace support:
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<payload-type-router input-channel="routingChannel">
|
||||
<mapping type="java.lang.String" channel="stringChannel" />
|
||||
<mapping type="java.lang.Integer" channel="integerChannel" />
|
||||
</payload-type-router>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="router-implementations-headervaluerouter">
|
||||
<title>HeaderValueRouter</title>
|
||||
<para>
|
||||
A <classname>HeaderValueRouter</classname> will send Messages to the channel based on the individual header value mappings.
|
||||
When <code>HeaderValueRouter</code> is created it is initialized with the <emphasis>name</emphasis> of the header to be evaluated, using <code>constructor-arg</code>.
|
||||
The <emphasis>value</emphasis> of the header could be one of two things:</para>
|
||||
<para>
|
||||
1. Arbitrary value
|
||||
</para>
|
||||
<para>
|
||||
2. Channel name
|
||||
</para>
|
||||
<para>
|
||||
If arbitrary value, then a <code>channelResolver</code> should be provided to map <emphasis>header values</emphasis> to <emphasis>channel names</emphasis>.
|
||||
The example below uses <code>MapBasedChannelResolver</code> to set up a map of header values to channel names.
|
||||
<programlisting language="xml"><![CDATA[ <bean id="myHeaderValueRouter"
|
||||
class="org.springframework.integration.router.HeaderValueRouter">
|
||||
<constructor-arg value="someHeaderName" />
|
||||
<property name="channelResolver">
|
||||
<bean class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="someHeaderValue" value-ref="channelA" />
|
||||
<entry key="someOtherHeaderValue" value-ref="channelB" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
]]></programlisting>
|
||||
If <code>channelResolver</code> is not specified, then the <emphasis>header value</emphasis> will be treated as a <emphasis>channel name</emphasis>
|
||||
making configuration much simpler, where no <code>channelResolver</code> needs to be specified.
|
||||
<programlisting language="xml"><![CDATA[
|
||||
<bean id="myHeaderValueRouter"
|
||||
class="org.springframework.integration.router.HeaderValueRouter">
|
||||
<constructor-arg value="someHeaderName" />
|
||||
</bean>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Similar to the <classname>PayloadTypeRouter</classname>, configuration of <classname>HeaderValueRouter</classname> is also supported via namespace support provided by Spring Integration (see <xref linkend="configuration-namespace"/>).
|
||||
The example below demonstrates two types of namespace-based configuration of <classname>HeaderValueRouter</classname> which are equivalent to the ones above using Spring Integration namespace support:
|
||||
</para>
|
||||
<para>1. Configuration where mapping of header values to channels is required</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<header-value-router input-channel="routingChannel" header-name="testHeader">
|
||||
<mapping value="someHeaderValue" channel="channelA" />
|
||||
<mapping value="someOtherHeaderValue" channel="channelB" />
|
||||
</header-value-router>]]></programlisting>
|
||||
</para>
|
||||
<para>2. Configuration where mapping of header values is not required if header values themselves represent the channel names</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<header-value-router input-channel="routingChannel" header-name="testHeader"/>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
The two router implementations shown above share some common properties, such as "defaultOutputChannel" and "resolutionRequired".
|
||||
If "resolutionRequired" is set to "true", and the router is unable to determine a target channel (e.g. there is
|
||||
no matching payload for a PayloadTypeRouter and no "defaultOutputChannel" has been specified), then an Exception
|
||||
will be thrown.
|
||||
</note>
|
||||
</section>
|
||||
<section id="router-implementations-recipientlistrouter">
|
||||
<title>RecipientListRouter</title>
|
||||
<para>
|
||||
A <classname>RecipientListRouter</classname> will send each received Message to a statically-defined
|
||||
list of Message Channels:
|
||||
<programlisting language="xml"><![CDATA[<bean id="recipientListRouter" class="org.springframework.integration.router.RecipientListRouter">
|
||||
<property name="channels">
|
||||
<list>
|
||||
<ref bean="channel1"/>
|
||||
<ref bean="channel2"/>
|
||||
<ref bean="channel3"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<para>
|
||||
Configuration for <classname>RecipientListRouter</classname> is also supported via namespace support provided by Spring Integration (see <xref linkend="configuration-namespace"/>).
|
||||
The example below demonstrates namespace-based configuration of <classname>RecipientListRouter</classname> and all the supported attributes using Spring Integration namespace support:
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<recipient-list-router id="customRouter" input-channel="routingChannel"
|
||||
timeout="1234"
|
||||
ignore-send-failures="true"
|
||||
apply-sequence="true">
|
||||
<recipient channel="channel1"/>
|
||||
<recipient channel="channel2"/>
|
||||
</recipient-list-router>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
The 'apply-sequence' flag here has the same affect as it does for a publish-subscribe-channel,
|
||||
and like publish-subscribe-channel it is disabled by default on the recipient-list-router. Refer to
|
||||
<xref linkend="channel-configuration-pubsubchannel"/> for more information.
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="router-namespace">
|
||||
<title>The <router> element</title>
|
||||
<para>
|
||||
The "router" element provides a simple way to connect a router to an input channel, and also accepts the
|
||||
optional default output channel. The "ref" may provide the bean name of a custom Router implementation
|
||||
(extending AbstractMessageRouter):
|
||||
<programlisting language="xml"><![CDATA[<router ref="payloadTypeRouter" input-channel="input1" default-output-channel="defaultOutput1"/>
|
||||
|
||||
<router ref="recipientListRouter" input-channel="input2" default-output-channel="defaultOutput2"/>
|
||||
|
||||
<router ref="customRouter" input-channel="input3" default-output-channel="defaultOutput3"/>
|
||||
|
||||
<beans:bean id="customRouterBean class="org.foo.MyCustomRouter"/>]]></programlisting>
|
||||
|
||||
Alternatively, the "ref" may point to a simple Object that contains the @Router annotation (see below), or the
|
||||
"ref" may be combined with an explicit "method" name. When specifying a "method", the same behavior applies as
|
||||
described in the @Router annotation section below.
|
||||
<programlisting language="xml"><![CDATA[<router input-channel="input" ref="somePojo" method="someMethod"/>]]></programlisting>
|
||||
Using a "ref" attribute is generally recommended if the custom router implementation can be reused in other
|
||||
<code><router></code> definitions. However if the custom router implementation should be scoped to a
|
||||
concrete definition of the <code><router></code>, you can provide an inner bean definition:
|
||||
<programlisting language="xml"><![CDATA[<router method="someMethod" input-channel="input3" default-output-channel="defaultOutput3">
|
||||
<beans:bean class="org.foo.MyCustomRouter"/>
|
||||
</router>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both the "ref" attribute and an inner handler definition in the same <code><router></code> configuration
|
||||
is not allowed, as it creates an ambiguous condition and will result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="router-annotation">
|
||||
<title>The @Router Annotation</title>
|
||||
<para>
|
||||
When using the <interfacename>@Router</interfacename> annotation, the annotated method can return either the
|
||||
<interfacename>MessageChannel</interfacename> or <classname>String</classname> type. In the case of the latter,
|
||||
the endpoint will resolve the channel name as it does for the default output. Additionally, the method can return
|
||||
either a single value or a collection. When a collection is returned, the reply message will be sent to multiple
|
||||
channels. To summarize, the following method signatures are all valid.
|
||||
<programlisting language="java">@Router
|
||||
public MessageChannel route(Message message) {...}
|
||||
|
||||
@Router
|
||||
public List<MessageChannel> route(Message message) {...}
|
||||
|
||||
@Router
|
||||
public String route(Foo payload) {...}
|
||||
|
||||
@Router
|
||||
public List<String> route(Foo payload) {...}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In addition to payload-based routing, a common requirement is to route based on metadata available within the
|
||||
message header as either a property or attribute. Rather than requiring use of the
|
||||
<interfacename>Message</interfacename> type as the method parameter, the <interfacename>@Router</interfacename>
|
||||
annotation may also use the @Header parameter annotation that is documented in <xref linkend="annotations"/>.
|
||||
<programlisting language="java">@Router
|
||||
public List<String> route(@Header("orderStatus") OrderStatus status)</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<note>
|
||||
For routing of XML-based Messages, including XPath support, see <xref linkend="xml"/>.
|
||||
</note>
|
||||
|
||||
<section id="dynamic-routers">
|
||||
<title>Dynamic Routers</title>
|
||||
<para>
|
||||
So as you can see, Spring Integration provides quite a few different router configurations for most common
|
||||
<emphasis>content-based routing</emphasis> use cases as well as the option of implementing custom routers as POJOs.
|
||||
For example; <emphasis>Payload Type Router</emphasis> provides a simple way to configure a router which computes <code>channels</code>
|
||||
based on the <code>payload type</code> of the incoming Message while <emphasis>Header Value Router</emphasis> provides the
|
||||
same convenience in configuring a router which computes <code>channels</code> based on evaluating the value
|
||||
of a particular Message Header. There is also an <emphasis>expression-based</emphasis> (SpEL) routers where the <code>channel</code>
|
||||
is determined based on evaluating an expression which gives these type of routers some dynamic characteristics.
|
||||
</para>
|
||||
<para>
|
||||
However these routers share one common attribute - <emphasis>static configuration</emphasis>. Even in the case of
|
||||
expression-based routers, the expression itself is defined as part of the router configuration which means that
|
||||
<quote>the same expression operating on the same value will always result in the computation of the same channel</quote>.
|
||||
This is good in most cases since such routes are well defined and therefore predictable. But there are times when we
|
||||
need to change router configurations dynamically so message flows could be routed to a different channel.
|
||||
</para>
|
||||
<para> <emphasis>For example:</emphasis> </para>
|
||||
<para>
|
||||
You might want to bring down some part of your system for maintenance. So, temporarily you want to re-reroute
|
||||
messages to a different message flow. Or you may want to introduce more granularity to your message flow by adding another
|
||||
route to handle a more concrete type of java.lang.Number (in cases of Payload Type Router).
|
||||
</para>
|
||||
<para>
|
||||
Unfortunately with static router configuration to accomplish this you'd have to bring down your entire application,
|
||||
change the configuration of the router (change routes) and bring it back up. This is obviously not the solution.
|
||||
</para>
|
||||
<para>
|
||||
<ulink url="http://www.eaipatterns.com/DynamicRouter.html">
|
||||
Dynamic Router
|
||||
</ulink>
|
||||
pattern describes the mechanisms by which one can change/configure routers dynamically without
|
||||
bringing down your system or individual routers.
|
||||
</para>
|
||||
<para>
|
||||
Before we get into the specifics of how it is accomplished in Spring Integration lets quickly summarize the
|
||||
typical flow of the router, which consists of 3 simple steps:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>Step 1</emphasis> - Compute <code>channel identifier</code> which is a value calculated by the
|
||||
router once it receives the Message. Typically it is a <classname>String</classname> or and instance of the actual
|
||||
<classname>MessageChannel</classname>.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 2</emphasis> - Resolve <code>channel identifier</code> to <code>channel name</code>. We'll describe
|
||||
specifics of this process in a moment.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 3</emphasis> - Resolve <code>channel name</code> to the actual <classname>MessageChannel</classname> </para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
There is not much that could be done with regard to router dynamics if Step 1 results in the actual instance of the
|
||||
<classname>MessageChannel</classname> simply because <classname>MessageChannel</classname> is the <emphasis>final product</emphasis> of any
|
||||
router's job. However, if Step 1 results in <code>channel identifier</code> that is not and instance of <classname>MessageChannel</classname>,
|
||||
then there are quite a few possibilities to influence the process of calculating what will be the final instance of the <classname>Message Channel</classname>.
|
||||
Lets look at couple of the examples in the context of the 3 steps mentioned above:
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Payload Type Router</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<payload-type-router input-channel="routingChannel">
|
||||
<mapping type="java.lang.String" channel="channel1" />
|
||||
<mapping type="java.lang.Integer" channel="channel2" />
|
||||
</payload-type-router>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Within the context of the Payload Type Router the 3 steps mentioned above would be realized as:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>Step 1</emphasis> - Compute <code>channel identifier</code> which is the fully qualified name of the payload type
|
||||
(e.g., java.lang.String).</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 2</emphasis> - Resolve <code>channel identifier</code> to <code>channel name</code> where
|
||||
the result of the previous step is used to select the appropriate value from the <emphasis>payload type mapping</emphasis>
|
||||
defined via <code>mapping</code> element.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 3</emphasis> - Resolve <code>channel name</code> to the actual instance of the
|
||||
<classname>MessageChannel</classname> where using <classname>ChannelResolver</classname> router will obtain a
|
||||
reference to a bean (which is hopefully a <classname>MessageChannel</classname>) identified by the result of the
|
||||
previous step.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
In other words each step feeds the next step until thr process completes.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Header Value Router</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
<programlisting language="xml"><![CDATA[<header-value-router input-channel="inputChannel" header-name="testHeader">
|
||||
<mapping value="foo" channel="fooChannel" />
|
||||
<mapping value="bar" channel="barChannel" />
|
||||
</header-value-router>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Similar to the PayloadTypeRouter:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>Step 1</emphasis> - Compute <code>channel identifier</code> which is the value of the header identified by the
|
||||
<code>header-name</code> attribute.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 2</emphasis> - Resolve <code>channel identifier</code> to <code>channel name</code> where
|
||||
the result of the previous step is used to select the appropriate value from the <emphasis>general mapping</emphasis>
|
||||
defined via <code>mapping</code> element.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Step 3</emphasis> - Resolve <code>channel name</code> to the actual instance of the
|
||||
<classname>MessageChannel</classname> where using <classname>ChannelResolver</classname> router will obtain a
|
||||
reference to a bean (which is hopefully a <classname>MessageChannel</classname>) identified by the result of the
|
||||
previous step.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
The above two configurations of two different router types look almost identical.
|
||||
However if we look at the different configuration of the <classname>HeaderValueRouter</classname> we clearly see that
|
||||
there is no <code>mapping</code> sub element:
|
||||
<programlisting language="xml"><![CDATA[<header-value-router input-channel="inputChannel" header-name="testHeader">]]></programlisting>
|
||||
But configuration is still perfectly valid. So the natural question is what about the maping in the Step 2?
|
||||
</para>
|
||||
<para>
|
||||
What this means is that Step 2 is now an optional step. If mapping is not defined then the <code>channel identifier</code>
|
||||
value computed in Step 1 will automatically be treated as the <code>channel name</code> which will now be resolved to the
|
||||
actual <classname>MessageChannel</classname> in the Step 3. What it also means is that Step 2 is one of the key steps to
|
||||
provide dynamic characteristics to the routers, since it introduces a process which
|
||||
<emphasis>allows you to change the way 'channel identifier' resolves to 'channel name'</emphasis>,
|
||||
thus influencing the process of determining the final instance of the <classname>MessageChannel</classname> from the initial
|
||||
<code>channel identifier</code>.
|
||||
</para>
|
||||
<para><emphasis>For Example:</emphasis> </para>
|
||||
<para>
|
||||
In the above configuration lets assume that the <code>testHeader</code> value is 'kermit' which is now a <code>channel identifier</code>
|
||||
(Step 1). Since there is no mapping in this router, resolving this <code>channel identifier</code> to a <code>channel name</code>
|
||||
(Step 2) is impossible and this <code>channel identifier</code> is now treated as <code>channel name</code>. However what if
|
||||
there was mapping but for a different value, the end result would still be the same and that is:
|
||||
<emphasis>if new value can not be determined through the process of resolving 'channel identifier' to a 'channel name',
|
||||
such 'channel identifier' becomes 'channel name'</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
So all that is left is for Step 3 to resolve <code>channel name</code> ('kermit') to an actual instance of the
|
||||
<classname>MessageChannel</classname> identified by this name. That will be done via default
|
||||
<interface>ChannelResolver</interface> implementation which is <classname>BeanFactoryChannelResolver</classname> which
|
||||
basically does a bean lookup by the name provided. So now all messages which contain the header/value pair as <code>testHeader=kermit</code>
|
||||
are going to be routed to a 'kermit' <classname>MessageChannel</classname>.
|
||||
</para>
|
||||
<para>
|
||||
But what if you want to route these messages to 'simpson' channel? Obviously changing static configuration would work,
|
||||
but would also require bringing your system down. However if you had access to <code>channel identifier</code> map, then you
|
||||
could just introduce a new mapping where header/value pair is now <code>kermit=simpson</code>, thus allowing Step 2 to treat
|
||||
'kermit' as <code>channel identifier</code> while resolving it to 'simpson' as <code>channel name</code> .
|
||||
</para>
|
||||
<para>
|
||||
The same obviously applies for <classname>PayloadTypeRouter</classname> where you can now remap or remove a particular <emphasis>payload type
|
||||
mapping</emphasis>, and every other router including <emphasis>expression-based</emphasis> routers since their computed value
|
||||
will now have a chance to go through Step 2 to be aditionally resolved to the actual <code>channel name</code>.
|
||||
</para>
|
||||
<para>
|
||||
In Spring Integration 2.0 routers hierarchy underwent major refactoring and now any router that is a subclass of the
|
||||
<classname>AbstractMessageRouter</classname> (all framework defined routers) is a Dynamic Router simply because
|
||||
<code>channelIdentiferMap</code> is defined at the <classname>AbstractMessageRouter</classname> with convenient accessors
|
||||
and modifiers exposed as public methods allowing you to change/add/remove router mapping at runtime via JMX (see section section 29) or
|
||||
ControlBus (see section section 29.7) functionality.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<emphasis>Control Bus</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
One of the way to manage the router mappings is through the <ulink url="http://www.eaipatterns.com/ControlBus.html">Control Bus</ulink>
|
||||
which exposes a Control Channel where you can send
|
||||
control messages to manage and monitor Spring Integration components which includes routers.
|
||||
For more information about the Control Bus see section 29.7. Typically you would send a control message asking to invoke a
|
||||
particular JMX operation on a particular managed component (e.g., router). The two managed operations (methods) that are
|
||||
specific to changing router resolution process are:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>public void setChannelMapping(String channelIdentifier, String channelName)</emphasis> -
|
||||
will allow you to add new or modify existing mapping of <code>channel identifier</code> to <code>channel name</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>public void removeChannelMapping(String channelIdentifier)</emphasis> -
|
||||
will allow you to remove a particular channel mapping, thus disconnecting the relationship between
|
||||
<code>channel identifier</code> and <code>channel name</code> </para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
There are obviously other managed operations, so please refer to an <classname>AbstractMessageRouter</classname> for more detail
|
||||
</para>
|
||||
<para>
|
||||
You can also use your favorite JMX client (e.g., JConsole) and use those operations (methods) to change
|
||||
router configuration. For more information on Spring Integration management and monitoring please visit
|
||||
section 29 of this manual.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,663 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<appendix id="samples">
|
||||
|
||||
<title>Spring Integration Samples</title>
|
||||
|
||||
<section id="samples-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Starting with the current release of Spring Integration the <emphasis>samples</emphasis> are no longer included with
|
||||
Spring Integration distribution. Instead we've switched to a much simpler collaborative model that should promote
|
||||
better community participation and community contributions. Samples now have a dedicated Git SCM repository and a
|
||||
dedicated JIRA Issue Tracking system. Sample development will also have its own lifecycle which is not dependent on the
|
||||
lifecycle of the framework releases although the repository will still be tagged with each major release for compatibility
|
||||
reasons.
|
||||
</para>
|
||||
<para>
|
||||
The great benefit to the community is that we can now add more samples and make them available to you right away
|
||||
without waiting for the release to get them out to you. Having its own JIRA that is not tied up to the the actual
|
||||
framework is also a great benefit. You now have a dedicated place to suggest samples as well as report issues with existing
|
||||
samples. <emphasis>Or you may want to submit a sample to us</emphasis> as an attachment through the JIRA and if we believe your sample adds value we
|
||||
would be more then glad to add it to a samples repository properly crediting the author.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="samples-get">
|
||||
<title>Where to get Samples</title>
|
||||
<para>
|
||||
To monitor samples development and to get more information on the repository you can visit the following
|
||||
URL: <link linkend="http://git.springsource.org/spring-integration/samples">http://git.springsource.org/spring-integration/samples</link>
|
||||
Since we are using Git SCM we should use the proper terminology as well when it comes to the tasks you need to perform to make
|
||||
<emphasis>samples</emphasis> available locally on your machine. For more information on Git SCM please visit their
|
||||
website: <link linkend="http://git-scm.com/">http://git-scm.com/</link>
|
||||
</para>
|
||||
<para>
|
||||
CLONE <emphasis>samples</emphasis> repository. (For those unfamiliar with Git, this is somewhat the equivalent of a checkout.)
|
||||
</para>
|
||||
<para>
|
||||
This is the first step you should go through. You must have Git installed on your machine. There are many GUI-based products
|
||||
available for many platforms. Simple Google search will let you find them.
|
||||
To clone samples repository from command line:
|
||||
<programlisting language="xml"><![CDATA[> mkdir spring-itegration-samples
|
||||
> cd spring-itegration-samples
|
||||
> git clone git://git.springsource.org/spring-integration/samples.git]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
That is all you need to do. Now you have cloned the entire samples repository. Since samples repository is a live
|
||||
repository, you might want to perform periodic updates to get new samples as well as updates to the existing samples.
|
||||
To get the updates use git PULL command:
|
||||
<programlisting language="xml"><![CDATA[> git pull]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Submit samples or sample requests
|
||||
</para>
|
||||
<para>
|
||||
As mentioned earlier, Spring Integration <emphasis>samples</emphasis> have a dedicated JIRA Issue tracking system.
|
||||
To submit new sample request or to submit the actual sample (as an attachment) please visit our JIRA Issue Tracking system:
|
||||
<link linkend="https://jira.springframework.org/browse/INTSAMPLES">https://jira.springframework.org/browse/INTSAMPLES</link>
|
||||
</para>
|
||||
</section>
|
||||
<section id="samples-structure">
|
||||
<title>Samples structure</title>
|
||||
<para>
|
||||
The structure of the <emphasis>samples</emphasis> changed as well. With plans for more samples we realized that some
|
||||
samples have different goals then others. While they all share the common goal of showing you how to apply and work with
|
||||
Spring Integration framework, they also defer in areas where some samples were meant to concentrate on a technical
|
||||
use case while others on the business use case and some samples are all about showcasing various techniques that
|
||||
could be applied to address certain scenarios (both technical and business). Categorization of samples will allow us
|
||||
better organize them based on the problem each sample addresses while giving you a simpler way of finding the right sample
|
||||
</para>
|
||||
<para>
|
||||
Currently there are 4 categories. Within the samples repository each category has its own directory which is named after the
|
||||
category name:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<emphasis>BASIC (samples/basic)</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
This is a good place to get started. The samples here are technically motivated and demonstrate the bare
|
||||
minimum with regard to configuration and code, to help you to get started quickly by introducing you to the basic concepts,
|
||||
API and configuration of Spring Integration as well as Enterprise Integration Patterns (EIP). For example; If your are
|
||||
looking for an answer on how to implement and wire <emphasis>Service Activator</emphasis> to a <emphasis>Channel</emphasis>
|
||||
or how to use <emphasis>Messaging Gateway</emphasis> to your message exchange or how to get started with using MAIL or
|
||||
TCP/UDP modules etc., this would be the right place to find a good sample. The bottom line is this is a good place
|
||||
to get started.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<emphasis>INTERMEDIATE (samples/intermediate)</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
This category targets developers who are already familiar with Spring Integration framework (past getting started),
|
||||
but need some more guidance while resolving a more advanced technical problems one might deal with
|
||||
once switch to a Messaging architecture.
|
||||
For example; If you are looking for an answer on how to handle errors in various message exchange
|
||||
scenarios or how to properly configure the <emphasis>Aggregator</emphasis> for the situations where some messages
|
||||
might not ever arrive for aggregation etc,. and any other issue that goes beyond a basic implementation and configuration
|
||||
of a particular component and addresses <emphasis>"what else you can do with it"</emphasis> type of problem this
|
||||
would be the right place to find these type of samples.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<emphasis>ADVANCED (samples/advanced)</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
This category targets develoopers who are very familiar with Spring Integration framework but looking to
|
||||
extend it to address a specific custom need by using Spring Integration public API.
|
||||
For example; if you are looking for samples showing you how to implement a custom <emphasis>Channel</emphasis> or
|
||||
<emphasis>Consumer</emphasis> (event-based or polling-based), or you trying to figure out what is the most appropriate
|
||||
way to implement custom Bean parser on top of Spring Integration Bean parsers hierarchy when implementing custom name space
|
||||
for a custom component, this would be the right place to look.
|
||||
Here you can also find samples that will help you with <emphasis>Adapter</emphasis> development. Spring Integration comes
|
||||
with an extensive library of adapters to allow you to connect remote systems with Spring Integration messaging framework.
|
||||
However you might have a need to integrate with system for which the core framework does not provide an adapter.
|
||||
So you have to implement your own. This category would include samples showing you how to do it.
|
||||
</para>
|
||||
|
||||
|
||||
<para>
|
||||
<emphasis>APPLICATIONS (samples/applications)</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
This category targets developers and architects who have a good understanding of the Messaging architecture,
|
||||
EIP and above average understanding of Spring and Spring Integration frameworks and are looking for samples that
|
||||
address a particular <emphasis>business problem</emphasis>. In other words the emphasis of samples in this category
|
||||
is <emphasis>business use cases</emphasis> and how it could be solved via Messaging Architecture and Spring Integration
|
||||
in particular.
|
||||
For example; If you are interested to see how a <emphasis>Loan Broker</emphasis> or <emphasis>Travel Agent</emphasis>
|
||||
process could be implemented and automated via Spring Integration this would be the right place to find these types of samples.
|
||||
</para>
|
||||
|
||||
<important>
|
||||
<remark>
|
||||
Remember! Spring Integration is a community driven framework, therefore community participation is IMPORTANT.
|
||||
That includes Samples, so if you can't find what you are looking for let us know.
|
||||
</remark>
|
||||
</important>
|
||||
</section>
|
||||
|
||||
<section id="samples-impl">
|
||||
<title>Samples</title>
|
||||
<para>
|
||||
Currently Spring Integration comes with quite a few samples and you can only expect more.
|
||||
To help you better navigate through them, each sample comes with its own <code>readme.txt</code> file which coveres
|
||||
sevaral details about the sample (e.g., what EIP patterns it addresses, what problem it is trying to solve, how to run sample etc.).
|
||||
However, certain samples require a more detailed and some times graphical explanation. In these section you'll
|
||||
find details on samples that we believe require special attention.
|
||||
</para>
|
||||
<section id="samples-loan-broker">
|
||||
<title>Loan Broker</title>
|
||||
<para>
|
||||
In this section, we will review a <emphasis>Loan Broker</emphasis> sample application that is included in the
|
||||
Spring Integration samples. This sample is inspired by one of the samples featured in Gregor
|
||||
Hohpe's <ulink url="http://www.eaipatterns.com/ramblings.html">Ramblings</ulink>.
|
||||
</para>
|
||||
<para>The diagram below represents the entire process</para>
|
||||
<para>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/loan-broker-eip.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/loan-broker-eip.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>Now lets look at this process in more details</para>
|
||||
<para>
|
||||
At the core of EIP architecture are the very simple yet powerful concepts of Pipes and Filters and Message. Endpoints (Filters) are
|
||||
connected with one another via Channels (Pipes). The producing endpoint sends Message to the Channel and the Message is retrieved
|
||||
by the Consuming endpoint. This architecture is meant to define various mechanisms that describe How information is exchanged between
|
||||
the endpoints, without any awareness of What those endpoints are or What information they are exchanging, thus providing for a very loosely
|
||||
coupled and flexible collaboration model while also, decoupling Integration concerns from Business concerns. EIP extends this architecture
|
||||
by further defining:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>The types of pipes (Point-to-Point Channel, Publish-Subscribe Channel, Channel Adapter, etc.)</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>The core filters and patterns around how filters collaborate with pipes
|
||||
(Message Router, Splitters and Aggregators, various Message Transformation patterns, etc.)</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
The details and variations of this use case are very nicely described in Chapter 9 of the EIP Book, but here is the brief summary;
|
||||
A Consumer while shopping for the best Loan Quote(s) subscribes to the services of a Loan Broker, which handles details such as:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Consumer pre-screening (e.g., obtain and review the consumer's Credit history)</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>Determine the most appropriate Banks (e.g., based on consumer's credit history/score)</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>Send a Loan quote request to each selected Bank</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Collect responses from each Bank</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Filter responses and determine the best quote(s), based on consumer's requirements.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Pass the Loan quote(s) back to the consumer.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Obviously the real process of obtaining a loan quote is a bit more complex, but since our goal here is to demonstrate how
|
||||
Enterprise Integration Patterns are realized and implemented within SI, the use case has been simplified to concentrate only on
|
||||
the Integration aspects of the process. It is not an attempt to give you an advice in consumer finances.
|
||||
</para>
|
||||
<para>
|
||||
As you can see, by hiring a Loan Broker, the consumer is isolated from the details of the Loan Broker's operations, and each Loan Broker's
|
||||
operations may defer from one another to maintain competitive advantage, so whatever we assemble/implement must be flexible so any changes
|
||||
could be introduced quickly and painlessly.
|
||||
Speaking of change, the Loan Broker sample does not actually talk to any 'imaginary' Banks or Credit bureaus. Those services are stubbed out.
|
||||
Our goal here is to assemble, orchestrate and test the integration aspect of the process as a whole. Only then can we start thinking about
|
||||
wiring such process to the real services. At that time the assembled process and its configuration will not change regardless of the number
|
||||
of Banks a particular Loan Broker is dealing with, or the type of communication media (or protocols) used (JMS, WS, TCP, etc.)
|
||||
to communicate with these Banks.
|
||||
</para>
|
||||
<para> <emphasis>DESIGN</emphasis> </para>
|
||||
<para>
|
||||
As you analyze the 6 requirements above you'll quickly see that they all fall into the category of Integration concerns.
|
||||
For example, in the consumer pre-screening step we need to gather additional information about the consumer and the consumer's desires
|
||||
and enrich the loan request with additional meta information. We then have to filter such information to select the most appropriate list of
|
||||
Banks, and so on. Enrich, filter, select – these are all integration concerns for which EIP defines a solution in the form of patterns.
|
||||
SI provides an implementation of these patterns.
|
||||
</para>
|
||||
<para><emphasis>Messaging Gateway</emphasis>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/gateway.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/gateway.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>
|
||||
The <emphasis>Messaging Gateway</emphasis> pattern provides a simple mechanism to access messaging systems, including our Loan Broker.
|
||||
In SI you define the <emphasis>Gateway</emphasis> as a Plain Old Java Interface (no need to provide an implementation), configure it via the
|
||||
XML <emphasis><gateway&gr;</emphasis> element or via annotation and use it as any other Spring bean. SI will take care of
|
||||
delegating and mapping method invocations to the Messaging infrastructure by generating a <emphasis>Message</emphasis> (payload is mapped to an
|
||||
input parameter of the method) and sending it to the designated channel.
|
||||
<programlisting language="xml"><![CDATA[<gateway id="loanBrokerGateway"
|
||||
default-request-channel="loanBrokerPreProcessingChannel"
|
||||
service-interface="org.springframework.integration.samples.loanbroker.LoanBrokerGateway">
|
||||
<method name="getBestLoanQuote">
|
||||
<header name="RESPONSE_TYPE" value="BEST"/>
|
||||
</method>
|
||||
</gateway>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Our current <emphasis>Gateway</emphasis> provides two methods that could be invoked. One that will return the best single quote and another one that
|
||||
will return all quotes. Somehow downstream we need to know what type of reply the caller is looking for. The best way to achieve
|
||||
this in Messaging architecture is to enrich the content of the message with some meta-data describing your intentions.
|
||||
<emphasis>Content Enricher</emphasis> is one of the patterns that addresses this and although Spring Integration does provide a
|
||||
separate configuration element to enrich Message Headers with arbitrary data (we'll see it later), as a convenience, since
|
||||
<emphasis>Gateway</emphasis> element is responsible to construct the initial <emphasis>Message</emphasis> it provides embedded
|
||||
capability to enrich the newly created <emphasis>Message</emphasis> with arbitrary <emphasis>Message Headers</emphasis>. In our
|
||||
example we are adding header RESPONSE_TYPE with value 'BEST'' whenever the getBestQuote() method is invoked. For other method
|
||||
we are not adding any header. Now we can check downstream for an existence of this header and based on its presence and its value
|
||||
we can determine what type of reply the caller is looking for.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Based on the use case we also know there are some pre-screening steps that needs to be performed such as getting and evaluating the consumer's
|
||||
credit score, simply because some premiere Banks will only typically accept quote requests from consumers that meet a minimum credit
|
||||
score requirement. So it would be nice if the <emphasis>Message</emphasis> would be enriched with such information before it is forwarded
|
||||
to the Banks. It would also be nice if when several processes needs to be completed to provide such meta-information, those
|
||||
processes could be grouped in a single unit. In our use case we need to determine credit score and based on the credit score and some
|
||||
rule select a list of <emphasis>Message Channels</emphasis> (Bank Channels) we will sent quote request to.
|
||||
</para>
|
||||
<para><emphasis>Composed Message Processor</emphasis> </para>
|
||||
<para>
|
||||
The <emphasis>Composed Message Processor</emphasis> pattern describes rules around building endpoints that maintain control over message flow which
|
||||
consists of multiple message processors. In Sprig Integration <emphasis>Composed Message Processor</emphasis> pattern is implemented via
|
||||
<emphasis><chain></emphasis> element.
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/chain.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/chain.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>
|
||||
As you can see from the above configuration we have a chain with inner header-enricher element which will further enrich the
|
||||
content of the <emphasis>Message</emphasis> with the header CREDIT_SCORE and value that will be determined by the call to a
|
||||
credit service (simple POJO spring bean identified by 'creditBureau' name) and then it will delegate to the <emphasis>Message Router</emphasis>
|
||||
</para>
|
||||
<para><emphasis>Message Router</emphasis>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/bank-router.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/bank-router.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>
|
||||
There are several implementation of <emphasis>Message Routing</emphasis> pattern available in Spring Integration. Here we are using
|
||||
router that will determine a list of channels based on evaluating an expression (Spring Expression Language) which will look at
|
||||
the credit score that was determined is the previous step and will select the list of channels from the Map bean with id 'banks'
|
||||
whose values are 'premier' or 'secondary' based o the value of credit score. Once the list of <emphasis>Channels</emphasis> is selected, the
|
||||
<emphasis>Message</emphasis> will be routed to those <emphasis>Channels</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
Now, one last thing the Loan Broker needs to to is to receive the loan quotes form the banks, aggregate them by consumer
|
||||
(we don't want to show quotes from one consumer to another), assemble the response based on the consumer's selection criteria
|
||||
(single best quote or all quotes) and reply back to the consumer.
|
||||
</para>
|
||||
<para><emphasis>Message Aggregator</emphasis>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/quotes-aggregator.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/quotes-aggregator.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
An <emphasis>Aggregator</emphasis> pattern describes an endpoint which groups related <emphasis>Messages</emphasis> into a single
|
||||
<emphasis>Message</emphasis>. Criteria and rules can be provided to determine an aggregation and correlation strategy.
|
||||
SI provides several implementations of the <emphasis>Aggregator</emphasis> pattern as well as a convenient name-space based configuration.
|
||||
<programlisting language="xml"><![CDATA[<aggregator id="quotesAggregator"
|
||||
input-channel="quotesAggregationChannel"
|
||||
method="aggregateQuotes">
|
||||
<beans:bean class="org.springframework.integration.samples.loanbroker.LoanQuoteAggregator"/>
|
||||
</aggregator>]]></programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Our Loan Broker defines a 'quotesAggregator' bean via the <emphasis><aggregator></emphasis> element which provides a default
|
||||
aggregation and correlation strategy. The default correlation strategy correlates messages based on the <code>$corelationId</code> header
|
||||
(see <emphasis>Correlation Identifier</emphasis> pattern). What's interesting is that we never provided the value for this header.
|
||||
It was set earlier by the router automatically, when it generated a separate <emphasis>Message</emphasis> for each Bank channel.
|
||||
</para>
|
||||
<para>
|
||||
Once the <emphasis>Messages</emphasis> are correlated they are released to the actual <emphasis>Aggregator</emphasis> implementation.
|
||||
Although default <emphasis>Aggregator</emphasis> is provided by SI, its strategy (gather the list of payloads from all
|
||||
<emphasis>Messages</emphasis> and construct a new <emphasis>Message</emphasis> with this List as payload) does not satisfy our
|
||||
requirement. The reason is that our consumer might require a single best quote or all quotes. To communicate the consumer's
|
||||
intention, earlier in the process we set the RESPONSE_TYPE header. Now we have to evaluate this header and return either
|
||||
all the quotes (the default aggregation strategy would work) or the best quote (the default aggregation strategy will not work
|
||||
because we have to determine which loan quote is the best).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Obviously selecting the best quote could be based on complex criteria and would influence the complexity of the aggregator implementation and
|
||||
configuration, but for now we are making it simple. If consumer wants the best quote we will select a quote with the lowest interest
|
||||
rate. To accomplish that the LoanQuoteAggregator.java will sort all the quotes and return the first one.
|
||||
The <classname>LoanQuote.java</classname> implements <interfacename>Comparable</interfacename> which compares quotes based on the rate attribute.
|
||||
Once the response <emphasis>Message</emphasis> is created it is sent to the default-reply-channel of the <emphasis>Messaging Gateway</emphasis>
|
||||
(thus the consumer) which started the process. Our consumer got the Loan Quote!
|
||||
</para>
|
||||
<para>Conclusion</para>
|
||||
<para>
|
||||
As you can see a rather complex process was assembled based on POJO (read existing, legacy), light weight, embeddable messaging
|
||||
framework (Sprig Integration) with a loosely coupled programming model intended to simplify integration of heterogeneous systems
|
||||
without requiring a heavy-weight ESB-like engine or proprietary development and deployment environment, becouse as a developer you
|
||||
should not be porting your Swing or console-based application to an ESB-like server or implementing proprietary interfaces just
|
||||
because you have an integration concern.
|
||||
</para>
|
||||
<para>
|
||||
This and other samples in this section are build on top of Enterprise Integration Patterns that meant to describe "building blocks"
|
||||
for YOUR solution but not to be solutions in of themselves. Integration concerns exist in all types of applications (server based and not)
|
||||
and should not require change in design, testing and deployment strategy if such applications need to integrate with one another.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="samples-cafe">
|
||||
<title>The Cafe Sample</title>
|
||||
<para>
|
||||
In this section, we will review a <emphasis>Cafe</emphasis> sample application that is included in the
|
||||
Spring Integration samples. This sample is inspired by another sample featured in Gregor
|
||||
Hohpe's <ulink url="http://www.eaipatterns.com/ramblings.html">Ramblings</ulink>.
|
||||
</para>
|
||||
<para>
|
||||
The domain is that of a Cafe, and the basic flow is depicted in the following diagram:
|
||||
</para>
|
||||
<para>
|
||||
<mediaobject>
|
||||
<imageobject role="fo">
|
||||
<imagedata fileref="src/docbkx/resources/images/cafe-eip.png"
|
||||
format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
<imageobject role="html">
|
||||
<imagedata fileref="images/cafe-eip.png" format="PNG" align="center"/>
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</para>
|
||||
<para>
|
||||
The <classname>Order</classname> object may contain multiple <classname>OrderItems</classname>. Once the order
|
||||
is placed, a <emphasis>Splitter</emphasis> will break the composite order message into a single message per
|
||||
drink. Each of these is then processed by a <emphasis>Router</emphasis> that determines whether the drink is hot
|
||||
or cold (checking the <classname>OrderItem</classname> object's 'isIced' property). The
|
||||
<classname>Barista</classname> prepares each drink, but hot and cold drink preparation are handled by two
|
||||
distinct methods: 'prepareHotDrink' and 'prepareColdDrink'. The prepared drinks are then sent to the Waiter where
|
||||
they are aggregated into a <classname>Delivery</classname> object.
|
||||
</para>
|
||||
<para>
|
||||
Here is the XML configuration:
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:stream="http://www.springframework.org/schema/integration/stream"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd">
|
||||
|
||||
<gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>
|
||||
|
||||
<channel id="orders"/>
|
||||
<splitter input-channel="orders" ref="orderSplitter" method="split" output-channel="drinks"/>
|
||||
|
||||
<channel id="drinks"/>
|
||||
<router input-channel="drinks" ref="drinkRouter" method="resolveOrderItemChannel"/>
|
||||
|
||||
<channel id="coldDrinks">
|
||||
<queue capacity="10"/>
|
||||
</channel>
|
||||
<service-activator input-channel="coldDrinks" ref="barista"
|
||||
method="prepareColdDrink" output-channel="preparedDrinks"/>
|
||||
|
||||
<channel id="hotDrinks">
|
||||
<queue capacity="10"/>
|
||||
</channel>
|
||||
<service-activator input-channel="hotDrinks" ref="barista"
|
||||
method="prepareHotDrink" output-channel="preparedDrinks"/>
|
||||
|
||||
<channel id="preparedDrinks"/>
|
||||
<aggregator input-channel="preparedDrinks" ref="waiter"
|
||||
method="prepareDelivery" output-channel="deliveries"/>
|
||||
|
||||
<stream:stdout-channel-adapter id="deliveries"/>
|
||||
|
||||
<beans:bean id="orderSplitter"
|
||||
class="org.springframework.integration.samples.cafe.xml.OrderSplitter"/>
|
||||
|
||||
<beans:bean id="drinkRouter"
|
||||
class="org.springframework.integration.samples.cafe.xml.DrinkRouter"/>
|
||||
|
||||
<beans:bean id="barista" class="org.springframework.integration.samples.cafe.xml.Barista"/>
|
||||
|
||||
<beans:bean id="waiter" class="org.springframework.integration.samples.cafe.xml.Waiter"/>
|
||||
|
||||
<poller id="poller" default="true" fixed-rate="1000"/>
|
||||
|
||||
</beans:beans>]]></programlisting>
|
||||
As you can see, each Message Endpoint is connected to input and/or output channels. Each endpoint will manage
|
||||
its own Lifecycle (by default endpoints start automatically upon initialization - to prevent that add the
|
||||
"auto-startup" attribute with a value of "false"). Most importantly, notice that the objects are simple POJOs
|
||||
with strongly typed method arguments. For example, here is the Splitter:
|
||||
<programlisting language="java"><![CDATA[public class OrderSplitter {
|
||||
|
||||
public List<OrderItem> split(Order order) {
|
||||
return order.getItems();
|
||||
}
|
||||
}]]></programlisting>
|
||||
In the case of the Router, the return value does not have to be a <interfacename>MessageChannel</interfacename>
|
||||
instance (although it can be). As you see in this example, a String-value representing the channel name is
|
||||
returned instead.
|
||||
<programlisting language="java"><![CDATA[public class DrinkRouter {
|
||||
|
||||
public String resolveOrderItemChannel(OrderItem orderItem) {
|
||||
return (orderItem.isIced()) ? "coldDrinks" : "hotDrinks";
|
||||
}
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Now turning back to the XML, you see that there are two <service-activator> elements. Each of these
|
||||
is delegating to the same <classname>Barista</classname> instance but different methods: 'prepareHotDrink'
|
||||
or 'prepareColdDrink' corresponding to the two channels where order items have been routed.
|
||||
<programlisting language="java"><![CDATA[public class Barista {
|
||||
|
||||
private long hotDrinkDelay = 5000;
|
||||
private long coldDrinkDelay = 1000;
|
||||
|
||||
private AtomicInteger hotDrinkCounter = new AtomicInteger();
|
||||
private AtomicInteger coldDrinkCounter = new AtomicInteger();
|
||||
|
||||
public void setHotDrinkDelay(long hotDrinkDelay) {
|
||||
this.hotDrinkDelay = hotDrinkDelay;
|
||||
}
|
||||
|
||||
public void setColdDrinkDelay(long coldDrinkDelay) {
|
||||
this.coldDrinkDelay = coldDrinkDelay;
|
||||
}
|
||||
|
||||
public Drink prepareHotDrink(OrderItem orderItem) {
|
||||
try {
|
||||
Thread.sleep(this.hotDrinkDelay);
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ " prepared hot drink #" + hotDrinkCounter.incrementAndGet()
|
||||
+ " for order #" + orderItem.getOrder().getNumber() + ": " + orderItem);
|
||||
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(),
|
||||
orderItem.isIced(), orderItem.getShots());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Drink prepareColdDrink(OrderItem orderItem) {
|
||||
try {
|
||||
Thread.sleep(this.coldDrinkDelay);
|
||||
System.out.println(Thread.currentThread().getName()
|
||||
+ " prepared cold drink #" + coldDrinkCounter.incrementAndGet()
|
||||
+ " for order #" + orderItem.getOrder().getNumber() + ": " + orderItem);
|
||||
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(),
|
||||
orderItem.isIced(), orderItem.getShots());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
As you can see from the code excerpt above, the barista methods have different delays (the hot drinks take 5
|
||||
times as long to prepare). This simulates work being completed at different rates. When the
|
||||
<classname>CafeDemo</classname> 'main' method runs, it will loop 100 times sending a single hot drink and a
|
||||
single cold drink each time. It actually sends the messages by invoking the 'placeOrder' method on the Cafe
|
||||
interface. Above, you will see that the <gateway> element is specified in the configuration file. This
|
||||
triggers the creation of a proxy that implements the given 'service-interface' and connects it to a channel.
|
||||
The channel name is provided on the @Gateway annotation of the <interfacename>Cafe</interfacename> interface.
|
||||
<programlisting language="java">public interface Cafe {
|
||||
|
||||
@Gateway(requestChannel="orders")
|
||||
void placeOrder(Order order);
|
||||
|
||||
}</programlisting>
|
||||
Finally, have a look at the <methodname>main()</methodname> method of the <classname>CafeDemo</classname> itself.
|
||||
<programlisting language="java"><![CDATA[public static void main(String[] args) {
|
||||
AbstractApplicationContext context = null;
|
||||
if (args.length > 0) {
|
||||
context = new FileSystemXmlApplicationContext(args);
|
||||
}
|
||||
else {
|
||||
context = new ClassPathXmlApplicationContext("cafeDemo.xml", CafeDemo.class);
|
||||
}
|
||||
Cafe cafe = (Cafe) context.getBean("cafe");
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
Order order = new Order(i);
|
||||
order.addItem(DrinkType.LATTE, 2, false);
|
||||
order.addItem(DrinkType.MOCHA, 3, true);
|
||||
cafe.placeOrder(order);
|
||||
}
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<tip>
|
||||
To run this sample as well as 8 others, refer to the <code>README.txt</code> within the "samples" directory
|
||||
of the main distribution as described at the beginning of this chapter.
|
||||
</tip>
|
||||
<para>
|
||||
When you run cafeDemo, you will see that the cold drinks are initially prepared more quickly than the hot drinks.
|
||||
Because there is an aggregator, the cold drinks are effectively limited by the rate of the hot drink preparation.
|
||||
This is to be expected based on their respective delays of 1000 and 5000 milliseconds. However, by configuring a
|
||||
poller with a concurrent task executor, you can dramatically change the results. For example, you could use a
|
||||
thread pool executor with 5 workers for the hot drink barista while keeping the cold drink barista as it is:
|
||||
<programlisting language="xml"><![CDATA[<service-activator input-channel="hotDrinks"
|
||||
ref="barista"
|
||||
method="prepareHotDrink"
|
||||
output-channel="preparedDrinks"/>
|
||||
|
||||
<service-activator input-channel="hotDrinks"
|
||||
ref="barista"
|
||||
method="prepareHotDrink"
|
||||
output-channel="preparedDrinks">
|
||||
]]><emphasis><![CDATA[<poller task-executor="pool" fixed-rate="1000"/>
|
||||
]]></emphasis><![CDATA[
|
||||
</service-activator>
|
||||
|
||||
]]><emphasis><![CDATA[<task:executor id="pool" pool-size="5"/>]]></emphasis></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Also, notice that the worker thread name is displayed with each invocation. You will see that the hot drinks are
|
||||
prepared by the task-executor threads. If you provide a much shorter poller interval (such as 100 milliseconds),
|
||||
then you will notice that occasionally it throttles the input by forcing the task-scheduler (the caller) to invoke
|
||||
the operation.
|
||||
</para>
|
||||
<note>
|
||||
In addition to experimenting with the poller's concurrency settings, you can also add the 'transactional'
|
||||
sub-element and then refer to any PlatformTransactionManager instance within the context.
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="samples-xml-messaging">
|
||||
<title>The XML Messaging Sample</title>
|
||||
<para>
|
||||
The xml messaging sample in the <package>org.springframework.integration.samples.xml</package> illustrates how to use
|
||||
some of the provided components which deal with xml payloads. The sample uses the idea of processing an order for books
|
||||
represented as xml.
|
||||
</para>
|
||||
<para>
|
||||
First the order is split into a number of messages, each one representing a single order item using
|
||||
the XPath splitter component.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xpath-splitter id="orderItemSplitter" input-channel="ordersChannel"
|
||||
output-channel="stockCheckerChannel" create-documents="true">
|
||||
<si-xml:xpath-expression expression="/orderNs:order/orderNs:orderItem" namespace-map="orderNamespaceMap" />
|
||||
</si-xml:xpath-splitter>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
A service activator is then used to pass the message into a stock checker POJO. The order item document is enriched with information
|
||||
from the stock checker about order item stock level. This enriched order item message is then used to route the message. In the
|
||||
case where the order item is in stock the message is routed to the warehouse. The XPath router makes use of a
|
||||
<classname>MapBasedChannelResolver</classname> which maps the XPath evaluation result to a channel reference.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xpath-router id="instockRouter" channel-resolver="mapChannelResolver"
|
||||
input-channel="orderRoutingChannel" resolution-required="true">
|
||||
<si-xml:xpath-expression expression="/orderNs:orderItem/@in-stock" namespace-map="orderNamespaceMap" />
|
||||
</si-xml:xpath-router>
|
||||
|
||||
<bean id="mapChannelResolver"
|
||||
class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="true" value-ref="warehouseDispatchChannel" />
|
||||
<entry key="false" value-ref="outOfStockChannel" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Where the order item is not in stock the message is transformed using
|
||||
xslt into a format suitable for sending to the supplier.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xslt-transformer input-channel="outOfStockChannel" output-channel="resupplyOrderChannel"
|
||||
xsl-resource="classpath:org/springframework/integration/samples/xml/bigBooksSupplierTransformer.xsl"/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</appendix>
|
||||
@@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="security">
|
||||
<title>Security in Spring Integration</title>
|
||||
|
||||
<section id="security-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Spring Integration provides integration with the
|
||||
<ulink url="http://static.springframework.org/spring-security/site/">Spring Security project</ulink>
|
||||
to allow role based security checks to be applied to channel send and receive invocations.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="securing-channels">
|
||||
<title>Securing channels</title>
|
||||
<para>
|
||||
Spring Integration provides the interceptor <classname>ChannelSecurityInterceptor</classname>, which extends
|
||||
<classname>AbstractSecurityInterceptor</classname> and intercepts send and receive calls on the channel. Access decisions
|
||||
are then made with reference to <classname>ChannelInvocationDefinitionSource</classname> which provides the definition of
|
||||
the send and receive security constraints. The interceptor requires that a valid <interfacename>SecurityContext</interfacename>
|
||||
has been established by authenticating with Spring Security, see the Spring Security reference documentation for details.
|
||||
</para>
|
||||
<para>
|
||||
Namespace support is provided to allow easy configuration of security constraints. This consists of the secured channels tag which allows
|
||||
definition of one or more channel name patterns in conjunction with a definition of the security configuration for send and receive. The pattern
|
||||
is a <interfacename>java.util.regexp.Pattern</interfacename>.
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:si-security="http://www.springframework.org/schema/integration/security"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:security="http://www.springframework.org/schema/security"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/security
|
||||
http://www.springframework.org/schema/security/spring-security-2.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/security
|
||||
http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd">
|
||||
|
||||
<si-security:secured-channels>
|
||||
<si-security:access-policy pattern="admin.*" send-access="ROLE_ADMIN"/>
|
||||
<si-security:access-policy pattern="user.*" receive-access="ROLE_USER"/>
|
||||
</si-security:secured-channels>]]>
|
||||
</programlisting>
|
||||
|
||||
By default the secured-channels namespace element expects a bean named <emphasis>authenticationManager</emphasis> which implements
|
||||
<interfacename>AuthenticationManager</interfacename> and a bean named <emphasis>accessDecisionManager</emphasis> which implements
|
||||
<interfacename>AccessDecisionManager</interfacename>. Where this is not the case references to the appropriate beans can be configured
|
||||
as attributes of the <emphasis>secured-channels</emphasis> element as below.
|
||||
<programlisting language="xml"><![CDATA[<si-security:secured-channels access-decision-manager="customAccessDecisionManager"
|
||||
authentication-manager="customAuthenticationManager">
|
||||
<si-security:access-policy pattern="admin.*" send-access="ROLE_ADMIN"/>
|
||||
<si-security:access-policy pattern="user.*" receive-access="ROLE_USER"/>
|
||||
</si-security:secured-channels>]]>
|
||||
</programlisting>
|
||||
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
</chapter>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="service-activator">
|
||||
<title>Service Activator</title>
|
||||
|
||||
<section id="service-activator-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
The Service Activator is the endpoint type for connecting any Spring-managed Object to an input channel so that
|
||||
it may play the role of a service. If the service produces output, it may also be connected to an output channel.
|
||||
Alternatively, an output producing service may be located at the end of a processing pipeline or message flow in
|
||||
which case, the inbound Message's "replyChannel" header can be used. This is the default behavior if no output
|
||||
channel is defined, and as with most of the configuration options you'll see here, the same behavior actually
|
||||
applies for most of the other components we have seen.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="service-activator-namespace">
|
||||
<title>The <service-activator/> Element</title>
|
||||
<para>
|
||||
To create a Service Activator, use the 'service-activator' element with the 'input-channel' and 'ref' attributes:
|
||||
<programlisting language="xml"><service-activator input-channel="exampleChannel" ref="exampleHandler"/></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The configuration above assumes that "exampleHandler" either contains a single method annotated with the
|
||||
@ServiceActivator annotation or that it contains only one public method at all. To delegate to an explicitly
|
||||
defined method of any object, simply add the "method" attribute.
|
||||
<programlisting language="xml"><service-activator input-channel="exampleChannel" ref="somePojo" method="someMethod"/></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
In either case, when the service method returns a non-null value, the endpoint will attempt to send the reply
|
||||
message to an appropriate reply channel. To determine the reply channel, it will first check if an
|
||||
"output-channel" was provided in the endpoint configuration:
|
||||
<programlisting language="xml"><service-activator input-channel="exampleChannel" output-channel="replyChannel"
|
||||
ref="somePojo" method="someMethod"/></programlisting>
|
||||
If no "output-channel" is available, it will then check the Message's <literal>REPLY_CHANNEL</literal> header
|
||||
value. If that value is available, it will then check its type. If it is a
|
||||
<interfacename>MessageChannel</interfacename>, the reply message will be sent to that channel. If it is a
|
||||
<classname>String</classname>, then the endpoint will attempt to resolve the channel name to a channel instance.
|
||||
If the channel cannot be resolved, then a <classname>ChannelResolutionException</classname> will be thrown.
|
||||
</para>
|
||||
<para>
|
||||
The argument in the service method could be either a Message or an arbitrary type. If the latter, then it will
|
||||
be assumed that it is a Message payload, which will be extracted from the message and injected into such service
|
||||
method. This is generally the recommended approach as it follows and promotes a POJO model when working with Spring
|
||||
Integration. Arguments may also have @Header, @Headers annotations as described in <xref linkend="annotations"/>
|
||||
</para>
|
||||
<note>
|
||||
Since v1.0.3 of Spring Integration, the service method is not required to have an argument at all, which means you
|
||||
can now implement event-style Service Activators, where all you care about is an invocation of the service method,
|
||||
not worrying about the contents of the message. Think of it as a NULL JMS message. An example use-case for such an
|
||||
implementation could be a simple counter/monitor of messages deposited on the input channel.
|
||||
</note>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the custom Service Activator handler implementation can be reused
|
||||
in other <code><service-activator></code> definitions. However if the custom Service Activator handler implementation
|
||||
should be scoped to a single definition of the <code><service-activator></code>, you can use an inner bean definition:
|
||||
<programlisting language="xml"><![CDATA[<service-activator id="exampleServiceActivator" input-channel="inChannel"
|
||||
output-channel = "outChannel" method="foo">
|
||||
<beans:bean class="org.foo.ExampleServiceActivator"/>
|
||||
</service-activator>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both the "ref" attribute and an inner handler definition in the same <code><service-activator></code>
|
||||
configuration is not allowed, as it creates an ambiguous condition and will result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,158 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="splitter">
|
||||
<title>Splitter</title>
|
||||
|
||||
<section id="splitter-annotation">
|
||||
<title>Introduction</title>
|
||||
|
||||
<para>The Splitter is a component whose role is to partition a message in
|
||||
several parts, and send the resulting messages to be processed
|
||||
independently. Very often, they are upstream producers in a pipeline that
|
||||
includes an Aggregator.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Programming model</title>
|
||||
|
||||
<para>The API for performing splitting consists from one base class,
|
||||
AbstractMessageSplitter, which is a MessageHandler implementation,
|
||||
encapsulating features which are common to splitters, such as filling in
|
||||
the appropriate message headers CORRELATION_ID, SEQUENCE_SIZE, and
|
||||
SEQUENCE_NUMBER on the messages that are produced. This allows to track
|
||||
down the messages and the results of their processing (in a typical
|
||||
scenario, these headers would be copied over to the messages that are
|
||||
produced by the various transforming endpoints), and use them, for
|
||||
example, in a Composed Message Processor scenario.</para>
|
||||
|
||||
<para>An excerpt from AbstractMessageSplitter can be seen below:</para>
|
||||
|
||||
<programlisting lang="java">public abstract class AbstractMessageSplitter
|
||||
extends AbstractReplyProducingMessageConsumer {
|
||||
...
|
||||
protected abstract Object splitMessage(Message<?> message);
|
||||
|
||||
}</programlisting>
|
||||
|
||||
<para>For implementing a specific Splitter in an application, a developer
|
||||
can extend AbstractMessageSplitter and implement the splitMessage method,
|
||||
thus defining the actual logic for splitting the messages. The return
|
||||
value can be one of the following:</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>a Collection (or subclass thereof) or an array of Message
|
||||
objects - in this case the messages will be sent as such (after the
|
||||
CORRELATION_ID, SEQUENCE_SIZE and SEQUENCE_NUMBER are populated).
|
||||
Using this approach gives more control to the developer, for example
|
||||
for populating custom message headers as part of the splitting
|
||||
process.</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>a Collection (or subclass thereof) or an array of non-Message
|
||||
objects - works like the prior case, except that each collection
|
||||
element will be used as a Message payload. Using this approach allows
|
||||
developers to focus on the domain objects without having to consider
|
||||
the Messaging system and produces code that is easier to test.</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>a Message or non-Message object (but not a Collection or an
|
||||
Array) - it works like the previous cases, except that there is a
|
||||
single message to be sent out.</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para>In Spring Integration, any POJO can implement the splitting
|
||||
algorithm, provided that it defines a method that accepts a single
|
||||
argument and has a return value. In this case, the return value of the
|
||||
method will be interpreted as described above. The input argument might
|
||||
either be a Message or a simple POJO. In the latter case, the splitter
|
||||
will receive the payload of the incoming message. Since this decouples
|
||||
the code from the Spring Integration API and will typically be easier
|
||||
to test, it is the recommended approach.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Configuring a Splitter using XML</title>
|
||||
|
||||
<para>A splitter can be configured through XML as follows:<programlisting><channel id="inputChannel"/>
|
||||
|
||||
<splitter id="splitter" <co id="split1" />
|
||||
ref="splitterBean" <co id="split2" />
|
||||
method="split" <co id="split3" />
|
||||
input-channel="inputChannel" <co id="split4" />
|
||||
output-channel="outputChannel" <co id="split5" />/>
|
||||
|
||||
<channel id="outputChannel"/>
|
||||
|
||||
<beans:bean id="splitterBean" class="sample.PojoSplitter"/></programlisting><calloutlist>
|
||||
<callout arearefs="split1">
|
||||
<para>The id of the splitter is
|
||||
<emphasis>optional</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="split2">
|
||||
<para>A reference to a bean defined in the application context. The
|
||||
bean must implement the splitting logic as described in the section
|
||||
above. <emphasis>Optional</emphasis>.
|
||||
If reference to a bean is not provided, then it is assumed that the <emphasis>payload</emphasis> of the Message that arrived on the <code>input-channel</code> is
|
||||
an implementation of <emphasis>java.util.Collection</emphasis> and the default splitting logic will be applied on such Collection,
|
||||
incorporating each individual element into a Message and depositing it on the <code>output-channel</code>.
|
||||
</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="split3">
|
||||
<para>The method (defined on the bean specified above) that
|
||||
implements the splitting logic.
|
||||
<emphasis>Optional</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="split4">
|
||||
<para>The input channel of the splitter.
|
||||
<emphasis>Required</emphasis>.</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs="split5">
|
||||
<para>The channel where the splitter will send the results of
|
||||
splitting the incoming message. <emphasis>Optional (because incoming
|
||||
messages can specify a reply channel themselves)</emphasis>.</para>
|
||||
</callout>
|
||||
</calloutlist></para>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the custom splitter handler implementation can be reused in other
|
||||
<code><splitter></code> definitions. However if the custom splitter handler implementation should be scoped to a
|
||||
single definition of the <code><splitter></code>, you can configure an inner bean definition:
|
||||
<programlisting language="xml"><![CDATA[<splitter id="testSplitter" input-channel="inChannel" method="split"
|
||||
output-channel="outChannel">
|
||||
<beans:bean class="org.foo.TestSplitter"/>
|
||||
</spliter>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both a "ref" attribute and an inner handler definition in the same <code><splitter></code>
|
||||
configuration is not allowed, as it creates an ambiguous condition and will result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Configuring a Splitter with Annotations</title>
|
||||
|
||||
<para>The <interfacename>@Splitter</interfacename> annotation is
|
||||
applicable to methods that expect either the
|
||||
<interfacename>Message</interfacename> type or the message payload type,
|
||||
and the return values of the method should be a collection of any type. If
|
||||
the returned values are not actual <interfacename>Message</interfacename>
|
||||
objects, then each of them will be sent as the payload of a message. Those
|
||||
messages will be sent to the output channel as designated for the endpoint
|
||||
on which the <interfacename>@Splitter</interfacename> is defined.
|
||||
<programlisting language="java">@Splitter
|
||||
List<LineItem> extractItems(Order order) {
|
||||
return order.getItems()
|
||||
}</programlisting></para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,91 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="stream">
|
||||
<title>Stream Support</title>
|
||||
|
||||
<section id="stream-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
In many cases application data is obtained from a stream. It is <emphasis>not</emphasis> recommended to send a reference to a Stream as a message payload to a consumer. Instead messages are created from data that is read from an input stream and message payloads are written to an output stream one by one.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="stream-reading">
|
||||
<title>Reading from streams</title>
|
||||
<para>
|
||||
Spring Integration provides two adapters for streams. Both <classname>ByteStreamReadingMessageSource</classname> and
|
||||
<classname>CharacterStreamReadingMessageSource</classname> implement <interfacename>MessageSource</interfacename>.
|
||||
By configuring one of these within a channel-adapter element, the polling period can be configured,
|
||||
and the Message Bus can automatically detect and schedule them. The byte stream version requires an
|
||||
<classname>InputStream</classname>, and the character stream version requires a <classname>Reader</classname> as
|
||||
the single constructor argument. The <classname>ByteStreamReadingMessageSource</classname> also accepts the 'bytesPerMessage'
|
||||
property to determine how many bytes it will attempt to read into each <interfacename>Message</interfacename>. The
|
||||
default value is 1024
|
||||
<programlisting language="xml"><![CDATA[<bean class="org.springframework.integration.stream.ByteStreamReadingMessageSource">
|
||||
<constructor-arg ref="someInputStream"/>
|
||||
<property name="bytesPerMessage" value="2048"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.integration.stream.CharacterStreamReadingMessageSource">
|
||||
<constructor-arg ref="someReader"/>
|
||||
</bean>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="stream-writing">
|
||||
<title>Writing to streams</title>
|
||||
<para>
|
||||
For target streams, there are also two implementations: <classname>ByteStreamWritingMessageHandler</classname> and
|
||||
<classname>CharacterStreamWritingMessageHandler</classname>. Each requires a single constructor argument -
|
||||
<classname>OutputStream</classname> for byte streams or <classname>Writer</classname> for character streams,
|
||||
and each provides a second constructor that adds the optional 'bufferSize'. Since both of these
|
||||
ultimately implement the <interfacename>MessageHandler</interfacename> interface, they can be referenced from a
|
||||
<emphasis>channel-adapter</emphasis> configuration as described in more detail in
|
||||
<xref linkend="channel-adapter"/>.
|
||||
<programlisting language="xml"><![CDATA[<bean class="org.springframework.integration.stream.ByteStreamWritingMessageHandler">
|
||||
<constructor-arg ref="someOutputStream"/>
|
||||
<constructor-arg value="1024"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.integration.stream.CharacterStreamWritingMessageHandler">
|
||||
<constructor-arg ref="someWriter"/>
|
||||
</bean>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section id="stream-namespace">
|
||||
<title>Stream namespace support</title>
|
||||
<para>
|
||||
To reduce the configuration needed for stream related channel adapters there is a namespace defined. The following schema locations are needed to use it.
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration/stream"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd">]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure the inbound channel adapter the following code snippet shows the different configuration options that are supported.
|
||||
<programlisting language="xml"><![CDATA[<stdin-channel-adapter id="adapterWithDefaultCharset"/>
|
||||
|
||||
<stdin-channel-adapter id="adapterWithProvidedCharset" charset="UTF-8"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure the outbound channel adapter you can use the namespace support as well. The following code snippet shows the different configuration for an outbound channel adapters.
|
||||
<programlisting language="xml"><![CDATA[<stdout-channel-adapter id="stdoutAdapterWithDefaultCharset" channel="testChannel"/>
|
||||
|
||||
<stdout-channel-adapter id="stdoutAdapterWithProvidedCharset" charset="UTF-8" channel="testChannel"/>
|
||||
|
||||
<stderr-channel-adapter id="stderrAdapter" channel="testChannel"/>
|
||||
|
||||
<stdout-channel-adapter id="newlineAdapter" append-newline="true" channel="testChannel"/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,175 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="transactions">
|
||||
<title>Transaction Support</title>
|
||||
|
||||
<section id="transaction-support">
|
||||
<title>Understanding Transactions in Message flows</title>
|
||||
<para>
|
||||
Spring Integration exposes several hooks to address transactional needs of you message flows.
|
||||
But to better understand these hooks and how you can benefit from them we must first revisit the 6 mechanisms
|
||||
that could be used to initiate Message flows and see how transactional needs of these flows
|
||||
could be addressed within each of these mechanisms.
|
||||
</para>
|
||||
<para>
|
||||
Here are the 6 mechanisms to initiate a Message flow and their short summary (details for each are provided throughout this manual):
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>Gateway Proxy</emphasis> - Your basic Messaging Gateway</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>MessageChannel</emphasis> - Direct interactions with MessageChannel methods (e.g., channel.send(message))</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Message Publisher</emphasis> - the way to initiate message flow as a bi-product of method invocations on Spring beans</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Inbound Channel Adapters/Gateways</emphasis> - the way to initiate message flow based on connecting third-party
|
||||
system with Spring Integration messaging system(e.g., [JmsMessage] -> Jms Inbound Adapter[SI Message] -> SI Channel)</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Scheduler</emphasis> - the way to initiate message flow based on scheduling events distributed
|
||||
by a pre-configured Scheduler</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Poller</emphasis> - similar to the Scheduler and is the way to initiate message flow based on scheduling
|
||||
or interval-based events distributed by a pre-configured Poller</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
These 6 cold be split in 2 general categories:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>Message flows initiated by a USER process</emphasis> - Example scenarios in this category
|
||||
would be invoking a Gateway method or explicitly sending a Message to a MessageChannel. In other words these message flows depend on third
|
||||
party process (e.g., some code that we wrote) to be initiated</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Message flows initiated by the DAEMON process</emphasis> - Example scenarios in this category would be a Poller
|
||||
polling for a Message queue to initiate a new Message flow with the polled Message or a Scheduler scheduling the
|
||||
process, by creating a new Message and initiating a message flow at a predefined time</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Clearly the <emphasis>Gateway Proxy</emphasis>, <emphasis>MessageChannel.send(..)</emphasis> and <emphasis>MessagePublisher</emphasis> are
|
||||
all belong to the 1st category and <emphasis>Inbound Adapters/Gateways</emphasis>, <emphasis>Scheduler</emphasis> and <emphasis>Poller</emphasis> belong to the 2nd.
|
||||
</para>
|
||||
<para>
|
||||
So, how do we address transactional needs in various scenarios within each category and is there a need for Spring Integration
|
||||
to provide something explicitly with regard to transaction for a particular scenario or Spring's Transaction Support could be leveraged instead?.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
First of all, the first and obvious goal is NOT to re-invent something that has already been invented unless you can provide a beter solution.
|
||||
In our case Spring itself provides a first class support for transaction management. So our goal here is not to provide something new but rather
|
||||
delegate/use Spring to benefit from the existing support for transactions. In other words as a framework we must expose hooks to the Transaction management functionality
|
||||
provided by Spring. But since Spring Integration configuration is based on Spring Configuration it is not always neccessery to expose these hooks as they already
|
||||
expposed via Spring natively. Remeber every Spring Integration component is a Spring Bean after all.
|
||||
</para>
|
||||
<para>
|
||||
With this goal in mind let's look at the two scenarios.
|
||||
</para>
|
||||
<para>
|
||||
If you think about it, Message flows that are initiated by the <emphasis>USER process</emphasis> (Category 1) and obviously configured in Spring Application Context,
|
||||
are subject to transactional configuration of such process and therefore don't need to be explicitly configured by Spring Integration to support transactions.
|
||||
The transaction could and should be initiated by such process through standard Transaction support provided by Spring and Spring Integration message flow will honor
|
||||
transactional semantics of the components naturally because it is Spring configured. For example; A Gateway or ServiceActivator methods could
|
||||
be annotated with <classname>@Transactional</classname> or <classname>TransactionInterceptor</classname> could be configured in XML configuration
|
||||
with point-cut expression pointing to specific methods that should be transactional.
|
||||
The bottom line you have full control over transaction configuration and boundaries in these scenarios.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
However, things are a bit different when it comes to Message flows initiated by the <emphasis>DAEMON process</emphasis> (Category 2).
|
||||
Although configured by the developer these flows do not directly involve human or some other process to be initiated. These are trigger-based flows
|
||||
that are initiated by a trigger process (DAEMON process) based on the configuration of such process. For example, we could have a Scheduler
|
||||
initiating a message flow every Friday night of every week. We can also configure a trigger that initiates a Message flow every second, etc.
|
||||
So, we obviously need the same way to let these trigger-based processes know of our intention to make these Message flows transactional so
|
||||
Transaction context could be created whenever a new Message flow is initiated. In other words we need to expose some Transaction configuration, but ONLY enough
|
||||
to delegate to Transaction support already provided by Spring (as we do in other scenarios).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Spring Integration provides transactional support for Pollers. Pollers are a special case comoponents becouse
|
||||
we can call receive() within that poller task against a resource that is itself transactional thus including <emphasis>receive()</emphasis>
|
||||
call in the the boundaries of the Transaction allowing it to be rolled back in case of a task failure. If we were to add the same support
|
||||
for channels, the added transactions would affect all downstream components starting with that <emphasis>send()</emphasis> call. That is
|
||||
providing a rather wide scope for transaction demarcation without any strong reason especially when Spring already provides several way to
|
||||
address transactional needs of any component downstream. However the <emphasis>receive()</emphasis> method being included in a transaction
|
||||
boundary is the "strong reason" for pollers.
|
||||
|
||||
|
||||
</para>
|
||||
|
||||
<section id="transaction-poller">
|
||||
<title>Poller Transaction Support</title>
|
||||
<para>
|
||||
Any time you configure a Poller you can provide transactional configuration via <emphasis>transactional</emphasis> element and its attributes:
|
||||
<programlisting language="xml"><![CDATA[<poller max-messages-per-poll="1" fixed-rate="1000">
|
||||
<transactional transaction-manager="txManager"
|
||||
isolation="DEFAULT"
|
||||
propagation="REQUIRED"
|
||||
read-only="true"
|
||||
timeout="1000"/>
|
||||
</poller>]]></programlisting>
|
||||
As you can see this configuration looks evry similar to native Spring transaction configuration. You must still provide reference to Transaction manager and specify
|
||||
transaction attributes or rely on defauls (e.g., if 'transaction-manager'' attribute is not specified then it will default to the bean with the name 'transactionManager').
|
||||
Internally the process would be wrapped in the Spring's native Transaction where <classname>TransactionInterceptor</classname> is responsible to handle transactions.
|
||||
For more information on how to configure Transaction Manager, the types of Transaction Managers (e.g., JTA, Datasource etc.) and other details related to
|
||||
transaction configuration please refer to Spring's Reference manual (Chapter 10 - Transaction Management).
|
||||
</para>
|
||||
<para>
|
||||
With the above configuration all Message flows initiated by this poller will be transactional. For more information and details on
|
||||
Poller's transactional configuration please refer to section - <emphasis>21.1.1. Polling and Transactions</emphasis>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
There times when besides transaction several more cross cutting concerns needs to be addressed when running Poller. To help with that,
|
||||
Poller element defines <emphasis><advice-chain> </emphasis> sub-element which allows you to define a custom chain of Advices
|
||||
to be applied on the Poller. (see section 4.4 for more details)
|
||||
In Spring Integration 2.0 Poller went through the major refactoring effort and is now using proxy mechanism to address transactional
|
||||
concerns as well as other cross cutting concerns, one of the significant changes evolving from this effort is that we
|
||||
made <emphasis><transactional></emphasis> and <emphasis><advice-chain></emphasis> elements mutually exclusive.
|
||||
The rational behind this is; If you need more then one advice, and one of them is Transaction advice, then you can simply
|
||||
include it in the <emphasis><advice-chain></emphasis> with the same convenience as before but with much more control
|
||||
since you now have an option to position any advice in the desired order.
|
||||
<programlisting language="xml"><![CDATA[<poller max-messages-per-poll="1" fixed-rate="10000">
|
||||
<advice-chain>
|
||||
<ref bean="txAdvise"/>
|
||||
<ref bean="someAotherAdviceBean" />
|
||||
<beans:bean class="foo.bar.SampleAdvice"/>
|
||||
</advice-chain>
|
||||
</poller>
|
||||
|
||||
<tx:advice id="txAdvice" transaction-manager="txManager">
|
||||
<tx:attributes>
|
||||
<tx:method name="get*" read-only="true"/>
|
||||
<tx:method name="*"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
]]></programlisting>
|
||||
|
||||
As yo can see from the example above, we have provided a very basic XML-based configuration of Spring Transaction advice - "txAdvice" and
|
||||
included it within the <emphasis><advice-chain></emphasis> defined by the Poller.
|
||||
|
||||
And if you only need to address transactional concerns of the Poller, then you can still use <emphasis><transactional></emphasis> element
|
||||
as a convinience.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
<section id="transaction-boundaries">
|
||||
<title>Transaction Boundaries</title>
|
||||
<para>
|
||||
Another important factor that needs to be understood is the boundaries of the Transactions within the Message flow.
|
||||
When transaction is started, transaction context is bound to the current thread. So regardless of how many endpoints and channels you have in your
|
||||
Message flow you transaction context will be preserved as long as you are ensuring that the flow continues on the same thread.
|
||||
As soon as you break it by introducing a <emphasis>Pollable Channel</emphasis> or <emphasis>Executor Channel</emphasis> or initiate a new thread manually in some
|
||||
service, the Transactional boundary will be broken as well. Essentially the Transaction will END right there and if
|
||||
successfull hand of happened between the threads, the flow would be considered a success and COMMIT signal would be sent
|
||||
even though the flow might still result in the exception somewhere downstream. If such flow was synchronous the exception would be thrown back to the
|
||||
initiator of the Message flow who is also the initiator of the transactional context and transaction would result in a ROLLBACK.
|
||||
</para>
|
||||
</section>
|
||||
</chapter>
|
||||
@@ -1,184 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="transformer">
|
||||
<title>Transformer</title>
|
||||
|
||||
<section id="transformer-introduction">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Message Transformers play a very important role in enabling the loose-coupling of Message Producers and Message
|
||||
Consumers. Rather than requiring every Message-producing component to know what type is expected by the next
|
||||
consumer, Transformers can be added between those components. Generic transformers, such as one that converts a
|
||||
String to an XML Document, are also highly reusable.
|
||||
</para>
|
||||
<para>
|
||||
For some systems, it may be best to provide a
|
||||
<ulink url="http://www.eaipatterns.com/CanonicalDataModel.html">Canonical Data Model</ulink>, but Spring
|
||||
Integration's general philosophy is not to require any particular format. Rather, for maximum flexibility, Spring
|
||||
Integration aims to provide the simplest possible model for extension. As with the other endpoint types, the use
|
||||
of declarative configuration in XML and/or Annotations enables simple POJOs to be adapted for the role of Message
|
||||
Transformers. These configuration options will be described below.
|
||||
<note>
|
||||
For the same reason of maximizing flexibility, Spring does not require XML-based Message payloads.
|
||||
Nevertheless, the framework does provide some convenient Transformers for dealing with XML-based payloads if
|
||||
that is indeed the right choice for your application. For more information on those transformers, see
|
||||
<xref linkend="xml"/>.
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="transformer-namespace">
|
||||
<title>The <transformer> Element</title>
|
||||
<para>
|
||||
The <transformer> element is used to create a Message-transforming endpoint. In addition to "input-channel"
|
||||
and "output-channel" attributes, it requires a "ref". The "ref" may either point to an Object that contains the
|
||||
@Transformer annotation on a single method (see below) or it may be combined with an explicit method name value
|
||||
provided via the "method" attribute.
|
||||
<programlisting language="xml"><![CDATA[<transformer id="testTransformer" ref="testTransformerBean" input-channel="inChannel"
|
||||
method="transform" output-channel="outChannel"/>
|
||||
<beans:bean id="testTransformerBean" class="org.foo.TestTransformer" />]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Using a "ref" attribute is generally recommended if the custom transformer handler implementation can be reused in
|
||||
other <code><transformer></code> definitions. However if the custom transformer handler implementation should
|
||||
be scoped to a single definition of the <code><transformer></code>, you can define an inner bean definition:
|
||||
<programlisting language="xml"><![CDATA[<transformer id="testTransformer" input-channel="inChannel" method="transform"
|
||||
output-channel="outChannel">
|
||||
<beans:bean class="org.foo.TestTransformer"/>
|
||||
</transformer>]]></programlisting>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Using both the "ref" attribute and an inner handler definition in the same <code><transformer></code>
|
||||
configuration is not allowed, as it creates an ambiguous condition and will result in an Exception being thrown.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
The method that is used for transformation may expect either the <interfacename>Message</interfacename> type or
|
||||
the payload type of inbound Messages. It may also accept Message header values either individually or as a full
|
||||
map by using the @Header and @Headers parameter annotations respectively. The return value of the method can be
|
||||
any type. If the return value is itself a <interfacename>Message</interfacename>, that will be passed along to
|
||||
the transformer's output channel. If the return type is a Map, and the original Message payload was
|
||||
<emphasis>not</emphasis> a Map, the entries in that Map will be added to the Message headers of the original
|
||||
Message (the keys must be Strings). If the return value is <emphasis>null</emphasis>, then no reply Message will
|
||||
be sent (effectively the same behavior as a Message Filter returning false). Otherwise, the return value will be
|
||||
sent as the payload of an outbound reply Message.
|
||||
</para>
|
||||
<para>
|
||||
There are a also a few Transformer implementations available out of the box. Because, it is fairly common
|
||||
to use the <methodname>toString()</methodname> representation of an Object, Spring Integration provides an
|
||||
<classname>ObjectToStringTransformer</classname> whose output is a Message with a String payload. That String
|
||||
is the result of invoking the toString operation on the inbound Message's payload.
|
||||
<programlisting language="xml"><![CDATA[ <object-to-string-transformer input-channel="in" output-channel="out"/>]]></programlisting>
|
||||
A potential example for this would be sending some arbitrary object to the 'outbound-channel-adapter' in the
|
||||
<emphasis>file</emphasis> namespace. Whereas that Channel Adapter only supports String, byte-array, or
|
||||
<classname>java.io.File</classname> payloads by default, adding this transformer immediately before the
|
||||
adapter will handle the necessary conversion. Of course, that works fine as long as the result of the
|
||||
<methodname>toString()</methodname> call is what you want to be written to the File. Otherwise, you can
|
||||
just provide a custom POJO-based Transformer via the generic 'transformer' element shown previously.
|
||||
<tip>
|
||||
When debugging, this transformer is not typically necessary since the 'logging-channel-adapter' is capable
|
||||
of logging the Message payload. Refer to <xref linkend="channel-wiretap"/> for more detail.
|
||||
</tip>
|
||||
</para>
|
||||
<para>
|
||||
If you need to serialize an Object to a byte array or deserialize a byte array back into an Object,
|
||||
Spring Integration provides symmetrical serialization transformers.
|
||||
<programlisting language="xml"><![CDATA[ <payload-serializing-transformer input-channel="objectsIn" output-channel="bytesOut"/>
|
||||
|
||||
<payload-deserializing-transformer input-channel="bytesIn" output-channel="objectsOut"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
If you only need to add headers to a Message, and they are not dynamically determined by Message content,
|
||||
then referencing a custom implementation may be overkill. For that reason, Spring Integration provides the
|
||||
'header-enricher' element. <programlisting language="xml"><![CDATA[ <header-enricher input-channel="in" output-channel="out">
|
||||
<header name="foo" value="123"/>
|
||||
<header name="bar" ref="someBean"/>
|
||||
</header-enricher>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
As added convenience, Spring Integration also provides <emphasis>Object-to-Map</emphasis> and <emphasis>Map-to-Object</emphasis> transformers which
|
||||
utilize Spring Expression Language (SpEL) to serialize and de-serialize the object graphs. Object hierarchy is introspected
|
||||
to the most primitive types (e.g., String, int etc.). The path to this type is described via SpEL, which becomes the <emphasis>key</emphasis>key in the
|
||||
transformed Map with primitive type being the value.
|
||||
</para>
|
||||
<para>
|
||||
For example:
|
||||
<programlisting language="java"><![CDATA[public class Parent{
|
||||
private Child child;
|
||||
private String name;
|
||||
// setters and getters are omitted
|
||||
}
|
||||
|
||||
public class Child{
|
||||
private String name;
|
||||
private List<String> nickNames;
|
||||
// setters and getters are omitted
|
||||
}]]></programlisting>
|
||||
... will be transformed to a Map which looks like this:
|
||||
<code>{person.name=George, person.child.name=Jenna, person.child.nickNames[0]=Bimbo . . . etc}</code>
|
||||
</para>
|
||||
<para>
|
||||
SpEL-based Map allows you to describe the object structure without sharing the actual types allowing
|
||||
you to restore/rebuild the object graph into a differently typed Object graph as long as you maintain the structure.
|
||||
</para>
|
||||
<para>
|
||||
For example:
|
||||
The above structure could be easily restored back to the following Object graph via Map-to-Object transformer:
|
||||
<programlisting language="java"><![CDATA[public class Father{
|
||||
private Kid child;
|
||||
private String name;
|
||||
// setters and getters are omitted
|
||||
}
|
||||
|
||||
public class Kid{
|
||||
private String name;
|
||||
private List<String> nickNames;
|
||||
// setters and getters are omitted
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
To configure these transformers, Spring Integration provides namespace support
|
||||
Object-to-Map:
|
||||
<programlisting language="xml"><![CDATA[<object-to-map-transformer input-channel="directInput" output-channel="output"/>]]></programlisting>
|
||||
Map-to-Object
|
||||
<programlisting language="xml"><![CDATA[<int:map-to-object-transformer input-channel="input"
|
||||
output-channel="output"
|
||||
type="org.foo.Person"/>]]></programlisting>
|
||||
or
|
||||
<programlisting language="xml"><![CDATA[<int:map-to-object-transformer input-channel="inputA"
|
||||
output-channel="outputA"
|
||||
ref="person"/>
|
||||
<bean id="person" class="org.foo.Person" scope="prototype"/>
|
||||
]]></programlisting>
|
||||
|
||||
</para>
|
||||
<note>
|
||||
NOTE: 'ref' and 'type' attributes are mutually exclusive. You can only use either one.
|
||||
Also, if using 'ref' attribute you must point to a 'prototype' scoped bean, otherwise
|
||||
BeanCreationException will be thrown.
|
||||
</note>
|
||||
</section>
|
||||
|
||||
<section id="transformer-annotation">
|
||||
<title>The @Transformer Annotation</title>
|
||||
<para>
|
||||
The <interfacename>@Transformer</interfacename> annotation can also be added to methods that expect either the
|
||||
<interfacename>Message</interfacename> type or the message payload type. The return value will be handled in the
|
||||
exact same way as described above in the section describing the <transformer> element.
|
||||
<programlisting language="java">@Transformer
|
||||
Order generateOrder(String productId) {
|
||||
return new Order(productId);
|
||||
}</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Transformer methods may also accept the @Header and @Headers annotations that is documented in <xref linkend="annotations"/>
|
||||
<programlisting language="java">@Transformer
|
||||
Order generateOrder(String productId, @Header("customerName") String customer) {
|
||||
return new Order(productId, customer);
|
||||
}</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,134 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="ws">
|
||||
<title>Web Services Support</title>
|
||||
|
||||
<section id="webservices-outbound">
|
||||
<title>Outbound Web Service Gateways</title>
|
||||
<para>
|
||||
To invoke a Web Service upon sending a message to a channel, there are two options - both of which build
|
||||
upon the <ulink url="http://static.springframework.org/spring-ws/sites/1.5/">Spring Web Services</ulink>
|
||||
project: <classname>SimpleWebServiceOutboundGateway</classname> and
|
||||
<classname>MarshallingWebServiceOutboundGateway</classname>. The former will accept either a
|
||||
<classname>String</classname> or <interfacename>javax.xml.transform.Source</interfacename> as the message
|
||||
payload. The latter provides support for any implementation of the <interfacename>Marshaller</interfacename>
|
||||
and <interfacename>Unmarshaller</interfacename> interfaces. Both require a Spring Web Services
|
||||
<interfacename>DestinationProvider</interfacename> for determining the URI of the Web Service to be
|
||||
called.<programlisting language="java"> simpleGateway = new SimpleWebServiceOutboundGateway(destinationProvider);
|
||||
|
||||
marshallingGateway = new MarshallingWebServiceOutboundGateway(destinationProvider, marshaller);
|
||||
</programlisting>
|
||||
<note>
|
||||
When using the namespace support described below, you will only need to set a URI. Internally, the parser
|
||||
will configure a fixed URI DestinationProvider implementation. If you do need dynamic resolution of the
|
||||
URI at runtime, however, then the DestinationProvider can provide such behavior as looking up the URI from
|
||||
a registry. See the Spring Web Services
|
||||
<ulink url="http://static.springsource.org/spring-ws/sites/1.5/apidocs/index.html">javadoc</ulink> for
|
||||
more information about the DestinationProvider strategy.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
For more detail on the inner workings, see the Spring Web Services reference guide's chapter covering
|
||||
<ulink url="http://static.springframework.org/spring-ws/site/reference/html/client.html">client access</ulink>
|
||||
as well as the chapter covering
|
||||
<ulink url="http://static.springframework.org/spring-ws/site/reference/html/oxm.html">Object/XML mapping</ulink>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="webservices-inbound">
|
||||
<title>Inbound Web Service Gateways</title>
|
||||
<para>
|
||||
To send a message to a channel upon receiving a Web Service invocation, there are two options again: <classname>SimpleWebServiceInboundGateway</classname> and
|
||||
<classname>MarshallingWebServiceInboundGateway</classname>. The former will extract a <interfacename>javax.xml.transform.Source</interfacename>
|
||||
from the <classname>WebServiceMessage</classname> and set it as the message
|
||||
payload. The latter provides support for implementation of the <interfacename>Marshaller</interfacename>
|
||||
and <interfacename>Unmarshaller</interfacename> interfaces.
|
||||
If the incoming web service message is a SOAP message the SOAP Action header will be added to the headers of the
|
||||
<classname>Message</classname> that is forwarded onto the request channel.
|
||||
|
||||
<programlisting language="java"> simpleGateway = new SimpleWebServiceInboundGateway();
|
||||
simpleGateway.setRequestChannel(forwardOntoThisChannel);
|
||||
simpleGateway.setReplyChannel(listenForResponseHere); //Optional
|
||||
|
||||
marshallingGateway = new MarshallingWebServiceInboundGateway(marshaller);
|
||||
//set request and optionally reply channel
|
||||
</programlisting>
|
||||
Both gateways implement the Spring Web Services <interfacename>MessageEndpoint</interfacename>
|
||||
interface, so they can be configured with a <classname>MessageDispatcherServlet</classname>
|
||||
as per standard Spring Web Services configuration.
|
||||
</para>
|
||||
<para>
|
||||
For more detail on how to use these components, see the Spring Web Services reference guide's chapter covering
|
||||
<ulink url="http://static.springframework.org/spring-ws/sites/1.5/reference/html/server.html">creating a Web Service</ulink>.
|
||||
The chapter covering
|
||||
<ulink url="http://static.springframework.org/spring-ws/site/reference/html/oxm.html">Object/XML mapping</ulink> is also applicable again.
|
||||
</para>
|
||||
</section>
|
||||
<section id="webservices-namespace">
|
||||
<title>Web Service Namespace Support</title>
|
||||
<para>
|
||||
To configure an outbound Web Service Gateway, use the "outbound-gateway" element from the "ws" namespace:
|
||||
<programlisting language="xml"><![CDATA[<ws:outbound-gateway id="simpleGateway"
|
||||
request-channel="inputChannel"
|
||||
uri="http://example.org"/>]]></programlisting>
|
||||
<note>
|
||||
Notice that this example does not provide a 'reply-channel'. If the Web Service were to
|
||||
return a non-empty response, the Message containing that response would be sent to the
|
||||
reply channel provided in the request Message's REPLY_CHANNEL header, and if that were
|
||||
not available a channel resolution Exception would be thrown. If you want to send the
|
||||
reply to another channel instead, then provide a 'reply-channel' attribute on the
|
||||
'outbound-gateway' element.
|
||||
</note>
|
||||
<tip>
|
||||
When invoking a Web Service that returns an empty response after using a String payload
|
||||
for the request Message, <emphasis>no reply Message will be sent by default</emphasis>.
|
||||
Therefore you don't need to set a 'reply-channel' or have a REPLY_CHANNEL header in the
|
||||
request Message. If for any reason you actually <emphasis>do</emphasis> want to receive
|
||||
the empty response as a Message, then provide the 'ignore-empty-responses' attribute with
|
||||
a value of <emphasis>false</emphasis> (this only applies for Strings, because using a
|
||||
Source or Document object simply leads to a NULL response and will therefore
|
||||
<emphasis>never</emphasis> generate a reply Message).
|
||||
</tip>
|
||||
|
||||
To set up an inbound Web Service Gateway, use the "inbound-gateway":
|
||||
<programlisting language="xml"><![CDATA[<ws:inbound-gateway id="simpleGateway"
|
||||
request-channel="inputChannel"/>]]></programlisting>
|
||||
|
||||
To use Spring OXM Marshallers and/or Unmarshallers, provide bean references. For outbound:
|
||||
<programlisting language="xml"><![CDATA[<ws:outbound-gateway id="marshallingGateway"
|
||||
request-channel="requestChannel"
|
||||
uri="http://example.org"
|
||||
marshaller="someMarshaller"
|
||||
unmarshaller="someUnmarshaller"/>]]></programlisting>
|
||||
And for inbound:
|
||||
<programlisting language="xml"><![CDATA[<ws:inbound-gateway id="marshallingGateway"
|
||||
request-channel="requestChannel"
|
||||
marshaller="someMarshaller"
|
||||
unmarshaller="someUnmarshaller"/>]]></programlisting>
|
||||
|
||||
<note>
|
||||
Most <interfacename>Marshaller</interfacename> implementations also implement the
|
||||
<interfacename>Unmarshaller</interfacename> interface. When using such a
|
||||
<interfacename>Marshaller</interfacename>, only the "marshaller"
|
||||
attribute is necessary. Even when using a <interfacename>Marshaller</interfacename>,
|
||||
you may also provide a reference for the "request-callback" on the outbound gateways.
|
||||
</note>
|
||||
</para>
|
||||
<para>
|
||||
For either outbound gateway type, a "destination-provider" attribute can be specified instead of the "uri"
|
||||
(exactly one of them is required). You can then reference any Spring Web Services DestinationProvider
|
||||
implementation (e.g. to lookup the URI at runtime from a registry).
|
||||
</para>
|
||||
<para>
|
||||
For either outbound gateway type, the "message-factory" attribute can also be configured with a reference to any
|
||||
Spring Web Services <interfacename>WebServiceMessageFactory</interfacename> implementation.
|
||||
</para>
|
||||
<para>
|
||||
For the simple inbound gateway type, the "extract-payload" attribute can be set to false to forward
|
||||
the entire <interfacename>WebServiceMessage</interfacename> instead of just its payload as a
|
||||
<interfacename>Message</interfacename> to the request channel. This might be useful, for example,
|
||||
when a custom Transformer works against the <interfacename>WebServiceMessage</interfacename> directly.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,505 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="xml">
|
||||
<title>XML Support - Dealing with XML Payloads</title>
|
||||
|
||||
<section id="xml-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Spring Integration's XML support extends the Spring Integration Core with
|
||||
implementations of splitter, transformer, selector and router designed
|
||||
to make working with xml messages in Spring Integration simple. The provided messaging
|
||||
components are designed to work with xml represented in a range of formats including
|
||||
instances of
|
||||
<classname>java.lang.String</classname>, <interfacename>org.w3c.dom.Document</interfacename>
|
||||
and <interfacename>javax.xml.transform.Source</interfacename>. It should be noted however that
|
||||
where a DOM representation is required, for example in order to evaluate an XPath expression,
|
||||
the <classname>String</classname> payload will be converted into the required type and then
|
||||
converted back again to <classname>String</classname>. Components that require an instance of
|
||||
<interfacename>DocumentBuilder</interfacename> will create a namespace aware instance if one is
|
||||
not provided. Where greater control of the document being created is required an appropriately
|
||||
configured instance of <interfacename>DocumentBuilder</interfacename> should be provided.
|
||||
</para>
|
||||
</section>
|
||||
<section id="xml-transformation">
|
||||
<title>Transforming xml payloads</title>
|
||||
<para>
|
||||
This section will explain the workings of
|
||||
<classname>UnmarshallingTransformer</classname>,
|
||||
<classname>MarshallingTransformer</classname>,
|
||||
<classname>XsltPayloadTransformer</classname>
|
||||
and how to configure them as
|
||||
<emphasis>beans</emphasis>. All of the provided xml transformers extend
|
||||
<classname>AbstractTransformer</classname> or <classname>AbstractPayloadTransformer</classname>
|
||||
and therefore implement <interfacename>Transformer</interfacename>. When configuring xml
|
||||
transformers as beans in Spring Integration you would normally configure the transformer
|
||||
in conjunction with either a <classname>MessageTransformingChannelInterceptor</classname> or a
|
||||
<classname>MessageTransformingHandler</classname>. This allows the transformer to be used as either an interceptor,
|
||||
which transforms the message as it is sent or received to the channel, or as an endpoint. Finally the
|
||||
namespace support will be discussed which allows for the simple configuration of the transformers as
|
||||
elements in XML.
|
||||
</para>
|
||||
<para>
|
||||
<classname>UnmarshallingTransformer</classname> allows an xml <interfacename>Source</interfacename>
|
||||
to be unmarshalled using implementations of Spring OXM <interfacename>Unmarshaller</interfacename>.
|
||||
Spring OXM provides several implementations supporting marshalling and unmarshalling using JAXB,
|
||||
Castor and JiBX amongst others. Since the unmarshaller requires an instance of
|
||||
<interfacename>Source</interfacename> where the message payload is not currently an instance of
|
||||
<interfacename>Source</interfacename>, conversion will be attempted. Currently <classname>String</classname>
|
||||
and <interfacename>org.w3c.dom.Document</interfacename> payloads are supported. Custom conversion to a
|
||||
<interfacename>Source</interfacename> is also supported by injecting an implementation of
|
||||
<interfacename>SourceFactory</interfacename>.
|
||||
<programlisting language="xml"><![CDATA[<bean id="unmarshallingTransformer"
|
||||
class="org.springframework.integration.xml.transformer.UnmarshallingTransformer">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.oxm.jaxb.Jaxb1Marshaller">
|
||||
<property name="contextPath" value="org.example" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The <classname>MarshallingTransformer</classname> allows an object graph to be converted
|
||||
into xml using a Spring OXM <interfacename>Marshaller</interfacename>. By default the
|
||||
<classname>MarshallingTransformer</classname> will return a <classname>DomResult</classname>.
|
||||
However the type of result can be controlled by configuring an alternative <interfacename>ResultFactory</interfacename>
|
||||
such as <classname>StringResultFactory</classname>. In many cases it will be more convenient to transform
|
||||
the payload into an alternative xml format. To achieve this configure a
|
||||
<interfacename>ResultTransformer</interfacename>. Two implementations are provided, one which converts to
|
||||
<classname>String</classname> and another which converts to <interfacename>Document</interfacename>.
|
||||
<programlisting language="xml"><![CDATA[<bean id="marshallingTransformer"
|
||||
class="org.springframework.integration.xml.transformer.MarshallingTransformer">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.oxm.jaxb.Jaxb1Marshaller">
|
||||
<property name="contextPath" value="org.example" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer" />
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
By default, the <classname>MarshallingTransformer</classname> will pass the payload Object
|
||||
to the <interfacename>Marshaller</interfacename>, but if its boolean "extractPayload" property
|
||||
is set to "false", the entire <interfacename>Message</interfacename> instance will be passed
|
||||
to the <interfacename>Marshaller</interfacename> instead. That may be useful for certain custom
|
||||
implementations of the <interfacename>Marshaller</interfacename> interface, but typically the
|
||||
payload is the appropriate source Object for marshalling when delegating to any of the various
|
||||
out-of-the-box <interfacename>Marshaller</interfacename> implementations.
|
||||
</para>
|
||||
<para>
|
||||
<classname>XsltPayloadTransformer</classname> transforms xml payloads using xsl.
|
||||
The transformer requires an instance of either <interfacename>Resource</interfacename> or
|
||||
<interfacename>Templates</interfacename>. Passing in a <interfacename>Templates</interfacename> instance
|
||||
allows for greater configuration of the <interfacename>TransformerFactory</interfacename> used to create
|
||||
the template instance. As in the case of <classname>XmlPayloadMarshallingTransformer</classname>
|
||||
by default <classname>XsltPayloadTransformer</classname> will create a message with a
|
||||
<interfacename>Result</interfacename> payload. This can be customised by providing a
|
||||
<interfacename>ResultFactory</interfacename> and/or a <interfacename>ResultTransformer</interfacename>.
|
||||
<programlisting language="xml"><![CDATA[<bean id="xsltPayloadTransformer"
|
||||
class="org.springframework.integration.xml.transformer.XsltPayloadTransformer">
|
||||
<constructor-arg value="classpath:org/example/xsl/transform.xsl" />
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.transformer.ResultToDocumentTransformer" />
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section id="xml-transformer-namespace">
|
||||
|
||||
<title>Namespace support for xml transformers</title>
|
||||
<para>
|
||||
Namespace support for all xml transformers is provided in the Spring Integration xml namespace,
|
||||
a template for which can be seen below. The namespace support for transformers creates an instance of either
|
||||
<classname>EventDrivenConsumer</classname> or <classname>PollingConsumer</classname>
|
||||
according to the type of the provided input channel. The namespace support is designed
|
||||
to reduce the amount of xml configuration by allowing the creation of an endpoint and transformer
|
||||
using one element.
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/xml
|
||||
http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd">
|
||||
</beans>]]></programlisting>
|
||||
The namespace support for <classname>UnmarshallingTransformer</classname> is shown below.
|
||||
Since the namespace is now creating an endpoint instance rather than a transformer,
|
||||
a poller can also be nested within the element to control the polling of the input channel.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:unmarshalling-transformer id="defaultUnmarshaller"
|
||||
input-channel="input"
|
||||
output-channel="output"
|
||||
unmarshaller="unmarshaller"/>
|
||||
|
||||
<si-xml:unmarshalling-transformer id="unmarshallerWithPoller"
|
||||
input-channel="input"
|
||||
output-channel="output"
|
||||
unmarshaller="unmarshaller">
|
||||
<si:poller fixed-rate="2000"/>
|
||||
<si-xml:unmarshalling-transformer/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The namespace support for the marshalling transformer requires an input channel, output channel and a
|
||||
reference to a marshaller. The optional result-type attribute can be used to control the type of result created,
|
||||
valid values are StringResult or DomResult (the default). Where the provided result types are not sufficient a
|
||||
reference to a custom implementation of <interfacename>ResultFactory</interfacename> can be provided as an alternative
|
||||
to setting the result-type attribute using the result-factory attribute. An optional result-transformer can also be
|
||||
specified in order to convert the created <interfacename>Result</interfacename> after marshalling.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:marshalling-transformer
|
||||
input-channel="marshallingTransformerStringResultFactory"
|
||||
output-channel="output"
|
||||
marshaller="marshaller"
|
||||
result-type="StringResult" />
|
||||
|
||||
<si-xml:marshalling-transformer
|
||||
input-channel="marshallingTransformerWithResultTransformer"
|
||||
output-channel="output"
|
||||
marshaller="marshaller"
|
||||
result-transformer="resultTransformer" />
|
||||
|
||||
<bean id="resultTransformer"
|
||||
class="org.springframework.integration.xml.transformer.ResultToStringTransformer"/>]]></programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Namespace support for the <classname>XsltPayloadTransformer</classname> allows either a resource to be passed in in order to create the
|
||||
<interfacename>Templates</interfacename> instance or alternatively a precreated <interfacename>Templates</interfacename>
|
||||
instance can be passed in as a reference. In common with the marshalling transformer the type of the result output can
|
||||
be controlled by specifying either the result-factory or result-type attribute. A result-transfomer attribute can also
|
||||
be used to reference an implementation of <interfacename>ResultTransfomer</interfacename> where conversion of the result
|
||||
is required before sending.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xslt-transformer id="xsltTransformerWithResource"
|
||||
input-channel="withResourceIn"
|
||||
output-channel="output"
|
||||
xsl-resource="org/springframework/integration/xml/config/test.xsl"/>
|
||||
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultTransformer"
|
||||
input-channel="withTemplatesAndResultTransformerIn"
|
||||
output-channel="output"
|
||||
xsl-templates="templates"
|
||||
result-transformer="resultTransformer"/>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
Very often to assist with transformation you may need to have access to Message data (e.g., Message Headers). For example; you may need to get access to certain Message Headers
|
||||
and pass them on as parameters to a transformer (e.g., transformer.setParameter(..)).
|
||||
Spring Integration provides two convenient ways to accomplish this. Just look at the following XML snippet.
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xslt-transformer id="paramHeadersCombo"
|
||||
input-channel="paramHeadersComboChannel"
|
||||
output-channel="output"
|
||||
xsl-resource="classpath:transformer.xslt"
|
||||
xslt-param-headers="testP*, *foo, bar, baz">
|
||||
|
||||
<int-xml:xslt-param name="helloParameter" value="hello"/>
|
||||
<int-xml:xslt-param name="firstName" expression="headers.fname"/>
|
||||
</int-xml:xslt-transformer>]]></programlisting>
|
||||
If message header names match 1:1 to parameter names, you can simply use <emphasis>xslt-param-headers attribute</emphasis>. There you can also use wildcards for
|
||||
simple pattern matching which supports the following simple pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy".
|
||||
</para>
|
||||
<para>
|
||||
You can also configure individual xslt parameters via <emphasis>xslt-param</emphasis> sub element. There you can use <code>expression</code> or <code>value</code> attribute.
|
||||
The <code>expression</code> attribute should be any valid SpEL expression with Message being the root object of the expression evaluation context.
|
||||
The <code>value</code> attribute just like any <code>value</code> in Spring beans allows you to specify simple scalar vallue. YOu can also use property placeholders (e.g., ${some.value})
|
||||
So as you can see, with the <code>expression</code> and <code>value</code> attribute xslt parameters could now be mapped to any accessible part of the Message as well as any literal value.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="xpath-splitting">
|
||||
<title>Splitting xml messages</title>
|
||||
<para>
|
||||
<classname>XPathMessageSplitter</classname> supports messages with either
|
||||
<classname>String</classname> or <interfacename>Document</interfacename> payloads.
|
||||
The splitter uses the provided XPath expression to split the payload into a number of
|
||||
nodes. By default this will result in each <interfacename>Node</interfacename> instance
|
||||
becoming the payload of a new message. Where it is preferred that each message be a Document
|
||||
the <methodname>createDocuments</methodname> flag can be set. Where a <classname>String</classname> payload is passed
|
||||
in the payload will be converted then split before being converted back to a number of String
|
||||
messages. The XPath splitter implements <interfacename>MessageHandler</interfacename> and should
|
||||
therefore be configured in conjunction with an appropriate endpoint (see the namespace support below
|
||||
for a simpler configuration alternative).
|
||||
<programlisting language="xml"><![CDATA[<bean id="splittingEndpoint"
|
||||
class="org.springframework.integration.endpoint.EventDrivenConsumer">
|
||||
<constructor-arg ref="orderChannel" />
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.splitter.XPathMessageSplitter">
|
||||
<constructor-arg value="/order/items" />
|
||||
<property name="documentBuilder" ref="customisedDocumentBuilder" />
|
||||
<property name="outputChannel" ref="orderItemsChannel" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="xpath-routing">
|
||||
<title>Routing xml messages using XPath</title>
|
||||
<para>
|
||||
Two Router implementations based on XPath are provided <classname>XPathSingleChannelRouter</classname> and
|
||||
<classname>XPathMultiChannelRouter</classname>. The implementations differ in respect to how many channels
|
||||
any given message may be routed to, exactly one in the case of the single channel version
|
||||
or zero or more in the case of the multichannel router. Both evaluate an XPath
|
||||
expression against the xml payload of the message, supported payload types by default
|
||||
are <interfacename>Node</interfacename>, <interfacename>Document</interfacename> and
|
||||
<interfacename>String</interfacename>. For other payload types a custom implementation
|
||||
of <interfacename>XmlPayloadConverter</interfacename> can be provided. The router
|
||||
implementations use <interfacename>ChannelResolver</interfacename> to convert the
|
||||
result(s) of the XPath expression to a channel name. By default a
|
||||
<classname>BeanFactoryChannelResolver</classname> strategy will be used, this means that the string returned by the XPath
|
||||
evaluation should correspond directly to the name of a channel. Where this is not the case
|
||||
an alternative implementation of <interfacename>ChannelResolver</interfacename> can
|
||||
be used. Where there is a simple mapping from Xpath result to channel name
|
||||
the provided <classname>MapBasedChannelResolver</classname> can be used.
|
||||
<programlisting language="xml"><![CDATA[<!-- Expects a channel for each value of order type to exist -->
|
||||
<bean id="singleChannelRoutingEndpoint"
|
||||
class="org.springframework.integration.endpoint.EventDrivenConsumer">
|
||||
<constructor-arg ref="orderChannel" />
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.router.XPathSingleChannelRouter">
|
||||
<constructor-arg value="/order/@type" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- Multi channel router which uses a map channel resolver to resolve the channel name
|
||||
based on the XPath evaluation result Since the router is multi channel it may deliver
|
||||
message to one or both of the configured channels -->
|
||||
<bean id="multiChannelRoutingEndpoint"
|
||||
class="org.springframework.integration.endpoint.EventDrivenConsumer">
|
||||
<constructor-arg ref="orderChannel" />
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.router.XPathMultiChannelRouter">
|
||||
<constructor-arg value="/order/recipient" />
|
||||
<property name="channelResolver">
|
||||
<bean class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<constructor-arg>
|
||||
<map>
|
||||
<entry key="accounts"
|
||||
value-ref="accountConfirmationChannel" />
|
||||
<entry key="humanResources"
|
||||
value-ref="humanResourcesConfirmationChannel" />
|
||||
</map>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="xpath-selector">
|
||||
<title>Selecting xml messages using XPath</title>
|
||||
<para>
|
||||
Two <interfacename>MessageSelector</interfacename> implementations are provided,
|
||||
<classname>BooleanTestXPathMessageSelector</classname> and <classname>StringValueTestXPathMessageSelector</classname>.
|
||||
<classname>BooleanTestXPathMessageSelector</classname> requires an XPathExpression which evaluates to a boolean,
|
||||
for example <emphasis>boolean(/one/two)</emphasis> which will only select messages which have an element named
|
||||
two which is a child of a root element named one. <classname>StringValueTestXPathMessageSelector</classname>
|
||||
evaluates any XPath expression as a <classname>String</classname> and compares the result with the provided value.
|
||||
</para>
|
||||
|
||||
|
||||
<programlisting language="xml"><![CDATA[<!-- Interceptor which rejects messages that do not have a root element order -->
|
||||
<bean id="orderSelectingInterceptor"
|
||||
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.selector.BooleanTestXPathMessageSelector">
|
||||
<constructor-arg value="boolean(/order)" />
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<!-- Interceptor which rejects messages that are not version one orders -->
|
||||
<bean id="versionOneOrderSelectingInterceptor"
|
||||
class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.xml.selector.StringValueTestXPathMessageSelector">
|
||||
<constructor-arg value="/order/@version" index="0"/>
|
||||
<constructor-arg value="1" index="1"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>]]></programlisting>
|
||||
</section>
|
||||
|
||||
<section id="xpath-transformer">
|
||||
<title>Transforming xml messages using XPath</title>
|
||||
<para>
|
||||
When it comes to message transformation XPath is a great way to transform Messages that have XML
|
||||
payloads by defining XPath transformers via <emphasis>xpath-transformer</emphasis> element.
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Simple XPath transformation</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
Let's look at the following transformer configuration:
|
||||
<programlisting language="xml"><![CDATA[<xpath-transformer input-channel="inputChannel" output-channel="outputChannel"
|
||||
xpath-expression="/person/@name" />]]></programlisting>
|
||||
|
||||
. . . and Message
|
||||
<programlisting language="java"><![CDATA[Message<?> message =
|
||||
MessageBuilder.withPayload("<person name='John Doe' age='42' married='true'/>").build();]]></programlisting>
|
||||
After sending this message to the 'inputChannel' the XPath transformer configured above will transform
|
||||
this XML Message to a simple Message with payload of 'John Doe' all based on
|
||||
the simple XPath Expression specified in the <emphasis>xpath-expression</emphasis> attribute.
|
||||
</para>
|
||||
<para>
|
||||
XPath also has capability to perform simple conversion of extracted elements
|
||||
to a desired type. Valid return types are defined in <classname>XPathConstants</classname> and follows
|
||||
the conversion rules specified by the <classname>XPath</classname>.
|
||||
</para>
|
||||
<para>
|
||||
The following constants are defined by the <classname>XPathConstants</classname>: <emphasis>BOOLEAN, DOM_OBJECT_MODEL, NODE, NODESET, NUMBER, STRING</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
You can configure the desired type by simply using <emphasis>evaluation-type</emphasis>
|
||||
attribute of the <emphasis>xpath-transformer</emphasis> element.
|
||||
<programlisting language="xml"><![CDATA[<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age"
|
||||
evaluation-type="NUMBER_RESULT" output-channel="output"/>
|
||||
|
||||
<xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'"
|
||||
evaluation-type="BOOLEAN_RESULT" output-channel="output"/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Node Mappers</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
If you need to provide custom mapping for the node extracted by the XPath expression simply provide a reference to the
|
||||
implementation of the <classname>org.springframework.xml.xpath.NodeMapper</classname> - an interface used by
|
||||
<classname>XPathOperations</classname> implementations for mapping Node objects on a per-node basis. To provide a
|
||||
reference to a <classname>NodeMapper</classname> simply use <emphasis>node-mapper</emphasis> attribute:
|
||||
<programlisting language="xml"><![CDATA[<xpath-transformer input-channel="nodeMapperInput" xpath-expression="/person/@age"
|
||||
node-mapper="testNodeMapper" output-channel="output"/>
|
||||
]]></programlisting>
|
||||
. . . and Sample NodeMapper implementation:
|
||||
<programlisting language="java"><![CDATA[class TestNodeMapper implements NodeMapper {
|
||||
public Object mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getTextContent() + "-mapped";
|
||||
}
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>XML Payload Converter</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
You can also use implementation of the <classname>org.springframework.integration.xml.XmlPayloadConverter</classname> to
|
||||
provide more granular transformation:
|
||||
<programlisting language="xml"><![CDATA[<xpath-transformer input-channel="customConverterInput" xpath-expression="/test/@type"
|
||||
converter="testXmlPayloadConverter" output-channel="output"/>
|
||||
]]></programlisting>
|
||||
. . . and Sample XmlPayloadConverter implementation:
|
||||
<programlisting language="java"><![CDATA[class TestXmlPayloadConverter implements XmlPayloadConverter {
|
||||
public Source convertToSource(Object object) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
//
|
||||
public Node convertToNode(Object object) {
|
||||
try {
|
||||
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
|
||||
new InputSource(new StringReader("<test type='custom'/>")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
//
|
||||
public Document convertToDocument(Object object) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
<emphasis>Combination of SpEL and XPath expressions</emphasis>
|
||||
</para>
|
||||
<para>
|
||||
You can also combine Spring Expression Language (SpEL) expressions with XPath expression and configure
|
||||
them using <emphasis>expression</emphasis> attribute:
|
||||
<programlisting language="xml"><![CDATA[xpath-expression id="testExpression" expression="/person/@age * 2"/>]]></programlisting>
|
||||
In the above case the overall result of the expression will be the result of the XPathe expression multiplied by 2.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
|
||||
<section id="xpath-namespace-support">
|
||||
<title>XPath components namespace support</title>
|
||||
<para>All XPath based components have namespace support allowing them to be configured as
|
||||
Message Endpoints with the exception of the XPath selectors which are not designed to act as
|
||||
endpoints. Each component allows the XPath to either be referenced at the top level or configured via a nested
|
||||
xpath-expression element. So the following configurations of an xpath-selector are all valid and represent the general
|
||||
form of XPath namespace support. All forms of XPath expression result in the creation of an
|
||||
<interfacename>XPathExpression</interfacename> using the Spring <classname>XPathExpressionFactory</classname>
|
||||
<programlisting language="xml"><![CDATA[<si-xml:xpath-selector id="xpathRefSelector"
|
||||
xpath-expression="refToXpathExpression"
|
||||
evaluation-result-type="boolean" />
|
||||
|
||||
<si-xml:xpath-selector id="selectorWithNoNS" evaluation-result-type="boolean" >
|
||||
<si-xml:xpath-expression expression="/name"/>
|
||||
</si-xml:xpath-selector>
|
||||
|
||||
<si-xml:xpath-selector id="selectorWithOneNS" evaluation-result-type="boolean" >
|
||||
<si-xml:xpath-expression expression="/ns1:name"
|
||||
ns-prefix="ns1" ns-uri="www.example.org" />
|
||||
</si-xml:xpath-selector>
|
||||
|
||||
<si-xml:xpath-selector id="selectorWithTwoNS" evaluation-result-type="boolean" >
|
||||
<si-xml:xpath-expression expression="/ns1:name/ns2:type">
|
||||
<map>
|
||||
<entry key="ns1" value="www.example.org/one" />
|
||||
<entry key="ns2" value="www.example.org/two" />
|
||||
</map>
|
||||
</si-xml:xpath-expression>
|
||||
</si-xml:xpath-selector>
|
||||
|
||||
<si-xml:xpath-selector id="selectorWithNamespaceMapRef" evaluation-result-type="boolean" >
|
||||
<si-xml:xpath-expression expression="/ns1:name/ns2:type"
|
||||
namespace-map="defaultNamespaces"/>
|
||||
</si-xml:xpath-selector>
|
||||
|
||||
<util:map id="defaultNamespaces">
|
||||
<util:entry key="ns1" value="www.example.org/one" />
|
||||
<util:entry key="ns2" value="www.example.org/two" />
|
||||
</util:map>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
XPath splitter namespace support allows the creation of a Message Endpoint with an input channel and output channel.
|
||||
<programlisting language="xml"><![CDATA[<!-- Split the order into items creating a new message for each item node -->
|
||||
<si-xml:xpath-splitter id="orderItemSplitter"
|
||||
input-channel="orderChannel"
|
||||
output-channel="orderItemsChannel">
|
||||
<si-xml:xpath-expression expression="/order/items"/>
|
||||
</si-xml:xpath-splitter>
|
||||
|
||||
<!-- Split the order into items creating a new document for each item-->
|
||||
<si-xml:xpath-splitter id="orderItemDocumentSplitter"
|
||||
input-channel="orderChannel"
|
||||
output-channel="orderItemsChannel"
|
||||
create-documents="true">
|
||||
<si-xml:xpath-expression expression="/order/items"/>
|
||||
<si:poller fixed-rate="2000"/>
|
||||
</si-xml:xpath-splitter>]]></programlisting>
|
||||
</para>
|
||||
<para>
|
||||
XPath router namespace support allows for the creation of a Message Endpoint with an input channel but no output channel
|
||||
since the output channel is determined dynamically. The multi-channel attribute causes the creation of a multi channel router capable of
|
||||
routing a single message to many channels when true and a single channel router when false.
|
||||
<programlisting language="xml"><![CDATA[<!-- route the message according to exactly one order type channel -->
|
||||
<si-xml:xpath-router id="orderTypeRouter" input-channel="orderChannel" multi-channel="false">
|
||||
<si-xml:xpath-expression expression="/order/type"/>
|
||||
</si-xml:xpath-router>
|
||||
|
||||
<!-- route the order to all responders-->
|
||||
<si-xml:xpath-router id="responderRouter" input-channel="orderChannel" multi-channel="true">
|
||||
<si-xml:xpath-expression expression="/request/responders"/>
|
||||
<si:poller fixed-rate="2000"/>
|
||||
</si-xml:xpath-router>]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
@@ -1,446 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<chapter id="xmpp">
|
||||
<title>XMPP Support</title>
|
||||
<para>
|
||||
Spring Integration provides Channel Adapters for <ulink url="http://www.xmpp.org">XMPP</ulink>.
|
||||
</para>
|
||||
<section id="xmpp-intro">
|
||||
<title>Introduction</title>
|
||||
<para>
|
||||
Spring Integration provides adapters for sending and receiving both XMPP messages and status changes from other
|
||||
entries in your roster as well as XMPP.
|
||||
</para>
|
||||
<para>
|
||||
XMPP describes a way for multiple agents to communicate with each other in a distributed system.
|
||||
The canonical use case is to send and receive instant messages, though XMPP can be, and is, used for far more
|
||||
applications.
|
||||
XMPP is used to describe a network of actors. Within that network, actors may address each other directly, as well
|
||||
as broadcast status changes.
|
||||
</para>
|
||||
<para>
|
||||
<!--
|
||||
todo do we have to include TM for 'Facebook', 'GMail', and 'Gtalk'?
|
||||
-->
|
||||
XMPP provides the messaging fabric that underlies some of the biggest Instant Messaging networks in the world,
|
||||
including Google Talk (GTalk)
|
||||
- which is also available from within GMail - and Facebook Chat.
|
||||
There are many good open-source XMPP servers available. Two popular implementations are
|
||||
<ulink url="http://www.igniterealtime.org/projects/openfire/">
|
||||
<citetitle>Openfire</citetitle>
|
||||
</ulink>
|
||||
and
|
||||
<ulink url="http://www.ejabberd.im">
|
||||
<citetitle>ejabberd</citetitle>
|
||||
</ulink>
|
||||
.
|
||||
</para>
|
||||
<para>
|
||||
In XMPP,
|
||||
<emphasis>rosters</emphasis>
|
||||
(the roster corresponds to the notion of a "buddy list" in your typical IM client) are used to manage a list of
|
||||
other agents ("contacts", or "buddies", in an IM client)
|
||||
in the system, called<emphasis>roster items</emphasis>.
|
||||
The roster item contains - at a minimum - the roster item's JID which is its unique ID on the network.
|
||||
An actor may subscribe to the state changes of another actor in the system. The subscription can be bidirectional,
|
||||
as well.
|
||||
The subscription settings determine whose status updates are broadcast, and to whom.
|
||||
These subscriptions are stored on the XMPP server, and are thus durable.
|
||||
|
||||
</para>
|
||||
|
||||
|
||||
</section>
|
||||
<section id="xmpp-config">
|
||||
<title>Using The Spring Integration XMPP Namespace
|
||||
</title>
|
||||
<para>
|
||||
Using the Spring Integration XMPP namespace support is simple.
|
||||
|
||||
Its use is like any other module in the Spring framework: import the XML schema, and use it to define elements.
|
||||
|
||||
A prototypical XMPP-based integration might feature the following header. We won't repeat this in subsequent
|
||||
examples, because it is uninteresting.
|
||||
|
||||
|
||||
<programlisting lang="xml"><![CDATA[
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans:beans
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/integration/xmpp
|
||||
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
">
|
||||
...
|
||||
|
||||
</beans:beans>
|
||||
]]></programlisting>
|
||||
|
||||
</para>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section id="xmpp-connection">
|
||||
<title>XMPP Connection</title>
|
||||
<para>
|
||||
To participate in the network, an actor must connect to an XMPP server. Typically this requires - at a minimum - a
|
||||
<code>user</code>, a<code>password</code>, a<code>host</code>, and a<code>port</code>.
|
||||
|
||||
To create an XMPP connection, you may use the XML namespace.
|
||||
|
||||
<programlisting lang="xml"><![CDATA[<xmpp:xmpp-connection
|
||||
id="myConnection"
|
||||
user="user"
|
||||
password="password"
|
||||
host="host"
|
||||
port="port"
|
||||
resource="theNameOfTheResource"
|
||||
subscription-mode="accept_all"
|
||||
/>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="xmpp-messages">
|
||||
<title>XMPP Messages</title>
|
||||
<section id="xmpp-message-inbound-channel-adapter">
|
||||
<title>Inbound Message Adapter</title>
|
||||
<para>The Spring Integration adapters support receiving messages from other users in the system. To do this, the
|
||||
adapter "logs in" as a user on your behalf and receives the messages sent to that user. Those messages are then
|
||||
forwarded to your Spring Integration client.
|
||||
The payload of the inbound Spring Integration message may be of the raw type<classname>
|
||||
org.jivesoftware.smack.packet.Message</classname>, or of the type
|
||||
<classname>java.lang.String</classname>
|
||||
- which is the type of the raw<code>
|
||||
Message</code>'s
|
||||
<code>body</code>
|
||||
property -
|
||||
depending on whether you specify
|
||||
<code>extract-payload</code>
|
||||
on the adapter's configuration or not.
|
||||
Inbound Messages are typically small and are text-oriented. Messages received using the adapter have
|
||||
a pretty standard layout, with known headers (all headers have keys defined on<classname>
|
||||
org.springframework.integration.xmpp.XmppHeaders</classname>):
|
||||
</para>
|
||||
|
||||
<table>
|
||||
<title>Header Values</title>
|
||||
|
||||
<tgroup cols="2">
|
||||
|
||||
<colspec colname="c1"/>
|
||||
<colspec colname="c2"/>
|
||||
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Header Name</entry>
|
||||
<entry>What It Describes</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>XmppHeaders.TYPE</entry>
|
||||
<entry>The value of the
|
||||
the
|
||||
<code>
|
||||
org.jivesoftware.smack.packet.Message.Type
|
||||
</code>
|
||||
enum that describes the inbound message. Possible values are:
|
||||
<code>normal</code>,
|
||||
<code>chat</code>,
|
||||
<code>groupchat</code>,
|
||||
<code>headline</code>,
|
||||
<code>error</code>.
|
||||
</entry>
|
||||
|
||||
</row>
|
||||
<row>
|
||||
<entry>XmppHeaders.CHAT</entry>
|
||||
<entry>A reference to the
|
||||
<code>org.jivesoftware.smack.Chat</code>
|
||||
class which represents the
|
||||
threaded conversation containing the message.
|
||||
</entry>
|
||||
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
<para>
|
||||
This adapter requires a reference to an XMPP Connection. You may
|
||||
use the
|
||||
<link linkend="xmpp-connection">xmpp-connection</link>
|
||||
element to define one.
|
||||
|
||||
An example might look as follows:
|
||||
|
||||
<programlisting lang="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans:beans ... >
|
||||
|
||||
<context:component-scan
|
||||
base-package="com.myxmppclient.inbound"/>
|
||||
|
||||
<context:property-placeholder
|
||||
location="#{ systemProperties['user.home'] }/xmpp/xmppclient.properties"/>
|
||||
|
||||
<channel id="xmppInbound"/>
|
||||
|
||||
<xmpp:xmpp-connection
|
||||
id="testConnection"
|
||||
...
|
||||
/> ]]>
|
||||
|
||||
<emphasis><![CDATA[<xmpp:message-inbound-channel-adapter
|
||||
channel="xmppInbound"
|
||||
xmpp-connection="testConnection"/>
|
||||
]]></emphasis><![CDATA[
|
||||
<service-activator input-channel="xmppInbound"
|
||||
ref="xmppMessageConsumer"/>
|
||||
|
||||
</beans:beans>]]></programlisting>
|
||||
|
||||
|
||||
</para>
|
||||
<para>
|
||||
In this example, the message is received from the XMPP adapter and passed to a
|
||||
<code>service-activator</code>
|
||||
component. Here's the declaration of the<code>service-activator</code>.
|
||||
<programlisting lang="java"><![CDATA[package com.myxmppclient.inbound ;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class XmppMessageConsumer {
|
||||
|
||||
@ServiceActivator
|
||||
public void consume(Message input) throws Throwable {
|
||||
String text = input.getBody();
|
||||
System.out.println( "Received message: " + text ) ;
|
||||
}
|
||||
|
||||
}
|
||||
]]></programlisting>
|
||||
</para>
|
||||
|
||||
</section>
|
||||
<section id="xmpp-message-outbound-channel-adapter">
|
||||
<title>Outbound Message Adapter</title>
|
||||
<para>
|
||||
You may also send messages to other users on XMPP using the
|
||||
<code>outbound-message-channel-adapter</code>
|
||||
adapter. The is configured like the
|
||||
|
||||
<link linkend="xmpp-message-inbound-channel-adapter">xmpp-message-inbound-channel-adapter</link>. The
|
||||
adapter takes an
|
||||
<code>xmpp-connection</code>
|
||||
reference.
|
||||
|
||||
|
||||
Here is a (necessarily) contrived example solution using the outbound adapter.
|
||||
|
||||
<programlisting lang="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans:beans ... >
|
||||
|
||||
<context:component-scan
|
||||
base-package="com.myxmppproducer.outbound"/>
|
||||
|
||||
<context:property-placeholder
|
||||
location="#{ systemProperties['user.home'] }/xmpp/xmppclient.properties"/>
|
||||
|
||||
<beans:bean id="xmppProducer"
|
||||
class="com.myxmppproducer.outbound.XmppMessageProducer"
|
||||
p:recipient="${user.2.login}"/>
|
||||
|
||||
<poller default="true" fixed-rate="10000"/>
|
||||
|
||||
<xmpp:xmpp-connection
|
||||
id="testConnection"
|
||||
...
|
||||
/>
|
||||
|
||||
<inbound-channel-adapter ref="xmppProducer"
|
||||
channel="outboundChannel"/>
|
||||
|
||||
<channel id="outboundChannel"/>
|
||||
|
||||
<xmpp:message-outbound-channel-adapter
|
||||
channel="outboundChannel"
|
||||
xmpp-connection="testConnection"/>
|
||||
|
||||
</beans:beans>]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
|
||||
The adapter expects as its input - at a minimum - a payload of type <classname>java.lang.String</classname>, and
|
||||
a header value
|
||||
for
|
||||
<code>XmppHeaders.CHAT_TO_USER</code>
|
||||
that specifies to which the user the payload body should be sent to.
|
||||
To create a message destined for the<code>outbound-message-channel-adapter</code>, you might use the following
|
||||
Java code:
|
||||
|
||||
<programlisting lang="java">
|
||||
<![CDATA[
|
||||
Message<String> xmppOutboundMsg = MessageBuilder.withPayload("Hello, world!" )
|
||||
.setHeader(XmppHeaders.CHAT_TO_USER, "userhandle")
|
||||
.build();
|
||||
]]></programlisting>
|
||||
|
||||
</para>
|
||||
<para>
|
||||
It's easy enough to use Java to update the <code>XmppHeaders.CHAT_TO_USER</code> header, and this has the advantage of dynamically updating the header at runtime in Java code.
|
||||
If, however, the target is more static in nature, you can
|
||||
configure it using the
|
||||
XMPP enricher support. Here is an example using the enricher. The enricher enriches the Spring Integration
|
||||
message
|
||||
to support the header values that the outbound XMPP adapters expect.
|
||||
<programlisting lang="xml">
|
||||
<![CDATA[
|
||||
<channel id="input"/>
|
||||
<channel id="output"/>
|
||||
|
||||
<xmpp:header-enricher input-channel="input" output-channel="output">
|
||||
<xmpp:message-to value="test1@example.org"/>
|
||||
</xmpp:header-enricher>
|
||||
]]></programlisting>
|
||||
</para>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
<section id="xmpp-presence">
|
||||
<title>XMPP Presence</title>
|
||||
|
||||
<para>
|
||||
|
||||
XMPP also supports broadcasting state. You can use this capability to
|
||||
let people who have you on their roster see your state changes. This happens all the time with your IM clients - you
|
||||
change your away status, and then set an away message, and everybody who has you on their roster sees your icon or username change to reflect this new state, and
|
||||
additionally might see your new "away" message.
|
||||
|
||||
|
||||
If you would like to receive notification, or notify others, of state changes, you can use Spring Integration's "presence" adapters.
|
||||
|
||||
</para> <para>
|
||||
The most important data for these adapters resides in the headers. The header keys are enumerated on
|
||||
the <code>org.springframework.integration.xmpp.XmppHeaders</code> class.
|
||||
|
||||
The header keys specific to these "presence" adapters start with the token "PRESENCE_".
|
||||
|
||||
Not all headers are available for both inbound and outbound.
|
||||
|
||||
|
||||
|
||||
|
||||
</para> <table>
|
||||
<title>Header Values</title>
|
||||
|
||||
<tgroup cols="2">
|
||||
|
||||
<colspec colname="c1"/>
|
||||
<colspec colname="c2"/>
|
||||
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Header Name</entry>
|
||||
<entry>What It Describes</entry>
|
||||
</row>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>XmppHeaders.PRESENCE_LANGUAGE</entry>
|
||||
<entry> The <code>java.lang.String</code> language in which the message was written.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>XmppHeaders.PRESENCE_PRIORITY</entry>
|
||||
<entry>
|
||||
The priority (int) of the message. Arbitrary, but it can be used to help assign relevance to a message which
|
||||
in turn might be used in its handling.
|
||||
</entry>
|
||||
|
||||
</row><row>
|
||||
<entry>XmppHeaders.PRESENCE_MODE</entry>
|
||||
<entry>
|
||||
An instance of the enum <code>org.jivesoftware.smack.packet.Presence.Mode</code> that has one of the following values:
|
||||
<code>chat,</code> <code>available,</code> <code>away,</code>
|
||||
<code>xa,</code> <code>dnd</code>
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>XmppHeaders.PRESENCE_TYPE</entry>
|
||||
<entry>
|
||||
An instance of the enum <code>org.jivesoftware.smack.packet.Presence.Type</code>
|
||||
that has one of the following values:
|
||||
<code>available,</code> <code>unavailable,</code> <code>subscribe,</code> <code>subscribed,</code>
|
||||
<code>unsubscribe,</code> <code>unsubscribed,</code> and <code>error</code>.
|
||||
|
||||
|
||||
</entry>
|
||||
</row> <row>
|
||||
<entry>XmppHeaders.PRESENCE_STATUS</entry>
|
||||
<entry>
|
||||
A <code>java.lang.String</code> string representing the status of the agent. This corresponds to an agents "away" message.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>XmppHeaders.PRESENCE_FROM</entry>
|
||||
<entry>
|
||||
A <code>java.lang.String</code> string representing the handle of the user whose state is being received.
|
||||
</entry>
|
||||
</row>
|
||||
|
||||
|
||||
</tbody>
|
||||
</tgroup>
|
||||
|
||||
</table>
|
||||
<section id="xmpp-presence-inbound-channel-adapter">
|
||||
<title>Inbound Presence Adapter</title>
|
||||
<para>
|
||||
The first adapter supports receiving messages whenever an agent on your roster has updated its
|
||||
state. Most of the important data comes in through the headers.
|
||||
|
||||
</para>
|
||||
</section>
|
||||
<section id="xmpp-presence-outbound-channel-adapter">
|
||||
<title>Outbound Presence Adapter</title>
|
||||
<para>TBD</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<!--<section id="xmpp-samples">
|
||||
<title>XMPP Samples</title>
|
||||
<para>
|
||||
We really should have some samples...
|
||||
</para>
|
||||
</section>
|
||||
-->
|
||||
</chapter>
|
||||
|
Before Width: | Height: | Size: 2.8 KiB |
@@ -1,21 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This document is the API specification for Spring Integration
|
||||
<hr/>
|
||||
<div id="overviewBody">
|
||||
<p>
|
||||
For further API reference and developer documentation, see the
|
||||
<a href="http://static.springsource.org/spring-integration/reference" target="_top">Spring
|
||||
Integration reference documentation</a>.
|
||||
That documentation contains more detailed, developer-targeted
|
||||
descriptions, with conceptual overviews, definitions of terms,
|
||||
workarounds, and working code examples.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you are interested in commercial training, consultancy, and
|
||||
support for Spring Integration, please visit <a href="http://www.springsource.com/" target="_top"/>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,178 +0,0 @@
|
||||
/* stylesheet.css 2008/04/22 nicolekonicki */
|
||||
|
||||
/*
|
||||
*
|
||||
* Spring-specific Javadoc style sheet
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
.code
|
||||
{
|
||||
border: 1px solid black;
|
||||
background-color: #F4F4F4;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
font: 12px Verdana, Arial, Helvetica, "Bitstream Vera Sans", sans-serif;
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
|
||||
/* Link colors */
|
||||
a
|
||||
{
|
||||
color:#2c7b14;
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
a:hover
|
||||
{
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
/* Headings */
|
||||
h1
|
||||
{
|
||||
font-size:28px;
|
||||
color:#007c00;
|
||||
}
|
||||
|
||||
/* Table colors */
|
||||
|
||||
table
|
||||
{
|
||||
border:none;
|
||||
}
|
||||
|
||||
td
|
||||
{
|
||||
border:none;
|
||||
border-bottom:1px dotted #ddd;
|
||||
}
|
||||
|
||||
th
|
||||
{
|
||||
border:none;
|
||||
}
|
||||
|
||||
.TableHeadingColor th
|
||||
{
|
||||
background-color: #efffcb;
|
||||
background-image: url(doc-files/th-background.png);
|
||||
background-repeat: repeat-x;
|
||||
color:#fff;
|
||||
font-size:14px;
|
||||
height:26px;
|
||||
}
|
||||
|
||||
.TableSubHeadingColor
|
||||
{
|
||||
background: #f7ffee;
|
||||
|
||||
}
|
||||
.TableRowColor
|
||||
{
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.TableRowColor a
|
||||
{
|
||||
border-bottom:none;
|
||||
color:#2c7b14;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
tr.TableRowColor:hover
|
||||
{
|
||||
background:#eef2e1;
|
||||
}
|
||||
|
||||
|
||||
/* Font used in left-hand frame lists */
|
||||
.FrameTitleFont
|
||||
{
|
||||
font-size: 120%;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.FrameTitleFont a
|
||||
{
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.FrameHeadingFont
|
||||
{
|
||||
font-weight: bold;
|
||||
font-size:95%;
|
||||
}
|
||||
|
||||
.FrameItemFont
|
||||
{
|
||||
line-height:130%;
|
||||
font-size: 95%;
|
||||
}
|
||||
|
||||
.FrameItemFont a
|
||||
{
|
||||
color:#333;
|
||||
}
|
||||
|
||||
.FrameItemFont a:hover
|
||||
{
|
||||
color:#249901;
|
||||
border-bottom:none;
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
/* Navigation bar fonts and colors */
|
||||
.NavBarCell1
|
||||
{
|
||||
background-color:#fff;
|
||||
border:none;
|
||||
}
|
||||
|
||||
.NavBarCell1Rev
|
||||
{
|
||||
background-color:#e3faa5;
|
||||
border:1px solid #9ad00c;
|
||||
padding:0;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.NavBarCell1 a
|
||||
{
|
||||
color:#333;
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
.NavBarFont1Rev
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
.NavBarCell2
|
||||
{
|
||||
border:none;
|
||||
}
|
||||
|
||||
.NavBarCell2 a
|
||||
{
|
||||
color:#249901;
|
||||
font-size:90%;
|
||||
}
|
||||
|
||||
.NavBarCell3
|
||||
{
|
||||
border:none;
|
||||
}
|
||||
|
||||
/* Override sizes in font tags */
|
||||
font
|
||||
{
|
||||
font: inherit !important;
|
||||
}
|
||||
@@ -1,417 +0,0 @@
|
||||
SPRING INTEGRATION CHANGELOG
|
||||
============================
|
||||
|
||||
For the full detailed changelog, see:
|
||||
https://fisheye.springsource.org/changelog/spring-integration
|
||||
|
||||
|
||||
Changes in version 2.0.0 Milestone 7 (Sept 03, 2010)
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11311
|
||||
|
||||
Changes in version 2.0.0 Milestone 6 (July 28, 2010)
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11536
|
||||
|
||||
Changes in version 2.0.0 Milestone 5 (June 25, 2010)
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11446
|
||||
|
||||
Changes in version 2.0.0 Milestone 4 (May 8, 2010)
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11389
|
||||
|
||||
Changes in version 2.0.0 Milestone 3 (Mar 12, 2010)
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11307
|
||||
|
||||
Changes in version 2.0.0 Milestone 2 (Dec 24, 2009)
|
||||
---------------------------------------------------
|
||||
http://jira.springsource.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11306
|
||||
|
||||
Changes in version 2.0.0 Milestone 1 (Oct 12, 2009)
|
||||
---------------------------------------------------
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11178
|
||||
|
||||
Changes in version 1.0.3 (Jul 18, 2009)
|
||||
---------------------------------------
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11209
|
||||
|
||||
Changes in version 1.0.2 (Mar 31, 2009)
|
||||
---------------------------------------
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11153
|
||||
|
||||
Changes in version 1.0.1 (Dec 17, 2008)
|
||||
---------------------------------------
|
||||
For changes in this release, see:
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11146
|
||||
|
||||
|
||||
Changes in version 1.0.0 (Nov 26, 2008)
|
||||
---------------------------------------
|
||||
For changes in this release, see:
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=10791
|
||||
|
||||
|
||||
Changes in version 1.0.0.RC2 (Nov 14, 2008)
|
||||
-------------------------------------------
|
||||
For changes in this release, see:
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11102
|
||||
|
||||
|
||||
Changes in version 1.0.0.RC1 (Nov 03, 2008)
|
||||
-------------------------------------------
|
||||
For changes in this release, see:
|
||||
http://jira.springframework.org/secure/IssueNavigator.jspa?reset=true&pid=10121&fixfor=11101
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
Upgraded Spring Framework dependency to 2.5.6
|
||||
Upgraded Spring Security dependency to 2.0.4
|
||||
Broke 'adapter' module into individual JARs
|
||||
Added JMS samples
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
Added Message Filter
|
||||
Added error handling strategy so that ErrorMessage can be routed to an error channel
|
||||
Added support for a 'defaultChannel' property on MessageChannelTemplate
|
||||
Added @Gateway annotation for per-method configuration of request and/or reply channels
|
||||
Simplified GatewayProxyFactoryBean reply Message correlation
|
||||
GatewayProxyFactoryBean now supports non-pollable replyChannel
|
||||
DefaultMethodResolver now correctly resolves annotated method on Proxy
|
||||
Fixed CronTrigger end of month rollover issue
|
||||
Added <interval-trigger/> and <cron-trigger/> elements for pollers
|
||||
Added transaction support for annotation-based polling
|
||||
AbstractPollingEndpoint now supports an Advice chain
|
||||
Fixed endless loop issue in Router (INT-358)
|
||||
MethodInvokingRouter now accepts a target object only (no method name required)
|
||||
MethodInvokingRouter will check for @Router method-level annotation
|
||||
Added 'default-output-channel' attribute to the <router/> element
|
||||
The 'splitter' element does not require a "ref" (for a DefaultSplitter instance)
|
||||
The 'resequencer' element accepts an "input-channel" attribute
|
||||
AbstractMessageBarrierHandler no longer calls processMessages twice
|
||||
The <pool-executor/> element was renamed to <thread-pool-task-executor/>
|
||||
Default TaskExecutor created for MessageBus sets max-size for pool instead of core
|
||||
Endpoints registered after ApplicationContext refresh are still activated
|
||||
MessageBus started/stopped events are fired
|
||||
Removed the MessageBusInterceptor
|
||||
Stopping/destroying context/MessageBus properly stops all Threads
|
||||
MessageHeaders no longer supports clear
|
||||
MessageHeaders constructor copies the original map for immutability
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Added JMS header enricher
|
||||
Added JmsOutboundGateway and refactored JmsGateway to JmsInboundGateway
|
||||
JMS gateways recognize a payload that is already a Spring Integration Message
|
||||
Added namespace support for JmsOutboundGateway
|
||||
MessageHeader values are propagated when using JMS gateways
|
||||
Enabled configuration of MessageConverter for JmsOutboundGateway
|
||||
FileToStringTransformer is encoding-aware
|
||||
Added inbound Mail Channel Adapters (POP3, IMAP, and IMAP IDLE)
|
||||
Mail outbound-channel-adapter accepts the "channel" attribute
|
||||
Added mail header enricher namespace support
|
||||
Enabled configuration of a WebServiceMessageSender instance for WS outbound gateways
|
||||
WebService gateway supports a Document payload in addition to Source and String
|
||||
RMI and HttpInvoker outbound gateways remove but copy non-serializable Message headers
|
||||
|
||||
*** OTHER ***
|
||||
|
||||
Channel security provides a ChannelInvocation instance
|
||||
Channel security interceptor now extends AbstractSecurityInterceptor
|
||||
XML Document Builders are now Namespace-aware
|
||||
Added XPath Message Selector
|
||||
Added XPath Message Splitter
|
||||
|
||||
|
||||
Changes in version 1.0.0.M6 (Aug 20, 2008)
|
||||
------------------------------------------
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
Refactored Message object to be unmodifiable after initial creation
|
||||
Refactored MessageHeaders object to be an implementation of (unmodifiable) Map<String, Object>
|
||||
Added MessageBuilder for constructing Messages (now used within internal handlers and endpoints)
|
||||
Added Quartz-based MessagingTaskScheduler to support Cron-based polling
|
||||
Reimplemented base Scheduling infrastructure to provide an SPI
|
||||
MessageBus no longer provides an option for auto-creating channels
|
||||
Added HeaderTransformer strategy interface
|
||||
MethodArgumentMessageMapper (f.k.a AnnotationMethodMessageMapper) is used across handler types
|
||||
PublishSubscribeChannels now provide an 'applySequence' property for adding sequence number/size headers
|
||||
SimpleDispatcher no longer attempts retries and does not mask exceptions with rejection limit error
|
||||
Default 'maxMessagesPerPoll' value is now unbounded
|
||||
Aggregator gives precedence to outputChannel and falls back to the returnAddress (consistent with other handlers)
|
||||
Added support for arguments, return-value, and thrown exception payload types for MessagePublishingInterceptor
|
||||
AbstractMessageDispatcher uses a Set (to avoid duplicate subscriptions) instead of a List
|
||||
AbstractMessageBarrierHandler uses returnAddress if outputChannel is null
|
||||
PublisherAnnotationPostProcessor proxies classes if the annotated method is not declared on an interface method
|
||||
Method reference is used for @Subscriber annotation (avoids NoSuchMethodException for method name ambiguity)
|
||||
MethodInvokingSource and MethodInvokingTarget now accept the actual Method reference instead of method name
|
||||
ChannelFactory behavior is now consistent with channels that are defined explicitly (no longer creates proxies)
|
||||
MessageHandlerDecorator (f.k.a. InterceptingMessageHandler) now supports setter injection
|
||||
InboundChannelAdapter (replacement for SourceEndpoint) calls MessageDeliveryAware onSend/onFailure methods
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Added an FTP Target adapter
|
||||
FileEntryParser can be customized for the FtpSource
|
||||
Added PollingMailSource adapter to support (polled) inbound e-mail messages
|
||||
Added SubscribableMailSource adapter to support (event-driven) inbound e-mail messages
|
||||
JMS header-mapping MessageConverter is no longer nested twice when used for source and target
|
||||
JMS message headers are now propagated (JMS-specific and user-prefixed values)
|
||||
AbstractMailHeaderMapper correctly maps the FROM/REPLY_TO attributes
|
||||
|
||||
*** CONFIGURATION ***
|
||||
|
||||
Channel Adapter now creates a DirectChannel implicitly if no "channel" is configured
|
||||
Added namespace support for WireTap
|
||||
The "max-messages-per-poll" value can be configured on <poller/> elements
|
||||
The <poller/> element now accepts a "cron" attribute (as an alternative to "period") if Quartz support is available
|
||||
The <poller/> element now provides "initial-delay" and "fixed-rate" attributes
|
||||
Added support for hybrid XML and annotations configuration (method-level annotations with XML-based endpoint)
|
||||
Added namespace support for configuring the MessageBus' TaskScheduler
|
||||
The "error-handler" attribute is available for XML-based Message Endpoint configuration
|
||||
The "errorChannel" bean is detected within the Application Context rather than being configured on the MessageBus
|
||||
The "channelFactory" bean is detected within the Application Context rather than being configured on the MessageBus
|
||||
Exposed configuration of concurrent-consumers for the JmsGateway
|
||||
The @HeaderProperty and @HeaderAttribute annotations have been replaced with @Header
|
||||
Splitter endpoint's 'output-channel' is now configured correctly when using annotations
|
||||
|
||||
*** WEB SERVICES AND XML ***
|
||||
|
||||
Added XPathRouter
|
||||
DOMResultFactory now creates a DOMResult with a node for OXM Marshaller
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
Upgraded to Spring 2.5.5.A
|
||||
Upgraded to Spring Security 2.0.2.A
|
||||
Upgraded to Spring WS 1.5.4.A
|
||||
|
||||
|
||||
Changes in version 1.0.0.M5 (Jul 08, 2008)
|
||||
------------------------------------------
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
SimpleMessagingTaskScheduler now has a configurable shutdown (for 'shutdown' vs 'shutdownNow')
|
||||
QueueChannel uses TRACE logging for preReceive and only uses DEBUG in postReceive if the Message is not null
|
||||
Added <concurrency-interceptor> for endpoints
|
||||
Added <transaction-interceptor> for endpoints
|
||||
The MessageBus tries to register new channels before starting (on ContextRefreshedEvent)
|
||||
Aggregator now uses its endpoint's output-channel
|
||||
Added MessageTransformer and @Transformer support
|
||||
Added a MessageTransformingChannelInterceptor
|
||||
MessageBus is now an interface
|
||||
MessageHeader is now an interface
|
||||
Added ChannelFactory
|
||||
Added PublishSubscribeChannel and <publish-subscribe-channel/>
|
||||
Channels specified in source-endpoint (now channel-adapter) are now auto-created
|
||||
Added EndpointTrigger for invoking endpoints with a poll command
|
||||
Removed the DispatcherPolicy from channel configuration
|
||||
Added BroadcastingDispatcher
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Added regular expression pattern FilenameFilter implementation
|
||||
The <file-source/> now accepts one of "file-filter", "filename-filter", or "filename-pattern"
|
||||
FileSource now uses a Resource to locate its directory
|
||||
FtpSource closes the connection after poll
|
||||
WebServiceHandler namespace support includes 'message-factory' and 'fault-message-resolver'
|
||||
WebServiceHandler namespace supports injection of the WebServiceMessageCallback
|
||||
Refactored FtpSource and FileSource to be better aligned
|
||||
AggregatorBarrier correctly stops processing messages after completion
|
||||
|
||||
*** CONFIGURATION ***
|
||||
|
||||
Method-level @Handler can now be used without class-level @MessageEndpoint
|
||||
The <channel-adapter/> with "ref" and "source" attributes replaces <source-endpoint/>
|
||||
The <channel-adapter/> with "ref" and "target" attributes replaces <target-endpoint/>
|
||||
The <channel-adapter/> accepts a "method" replacing <source-adapter/> and <target-adapter/>
|
||||
The <router/> element is now a self-sufficient endpoint (rather than just creating a handler)
|
||||
The <splitter/> element is now a self-sufficient endpoint (rather than just creating a handler)
|
||||
The <aggregator/> element is now a self-sufficient endpoint (rather than just creating a handler)
|
||||
Added namespace support for creating a MessageSelectorChain
|
||||
|
||||
*** WEB SERVICES AND XML ***
|
||||
|
||||
Added XML module
|
||||
Added XSLT Transformer
|
||||
Add Spring OXM transformer
|
||||
Add XML Result transformer to convert from a Result to a Document
|
||||
|
||||
*** SECURITY ***
|
||||
|
||||
Added support for Spring Security on MessageChannels
|
||||
Added support for Spring Security on endpoints
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
More Exceptions now provide the 'failedMessage'
|
||||
Added a MessageRejectedException. It is thrown when a MessageSelector rejects a Message
|
||||
|
||||
|
||||
Changes in version 1.0.0.M4 (May 23, 2008)
|
||||
------------------------------------------
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
Improved consistency of 'endpoint' with SourceEndpoint, TargetEndpoint, and HandlerEndpoint implementations
|
||||
SourceEndpoint replaces PollingSourceAdapter and also provides better separation from the actual Source
|
||||
ReplyCorrelator is now encapsulated within RequestReplyTemplate
|
||||
Added MessagingGatewaySupport, SimpleMessagingGateway, and GatewayProxyFactoryBean for Request-Reply operations
|
||||
Renamed SynchronousChannel to DirectChannel, also factored out ThreadLocalChannel
|
||||
@Splitter-annotated methods now attempt to convert the Message payload (consistent with @Handler)
|
||||
Added support for parameter-binding with @HeaderAttribute and @HeaderProperty annotations
|
||||
Handler methods configured with namespace support now accept a Message payload
|
||||
Implemented a MessageSelectorChain (consistent with MessageHandlerChain)
|
||||
Added @CompletionStrategy annotation and CompletionStrategyAdapter for aggregators
|
||||
The sequence number and sequence size are propagated correctly for POJO-based handler methods.
|
||||
Source implementations may be connected to a DirectChannel
|
||||
The ErrorHandler is now provided to ConcurrentTargets
|
||||
Implemented RootCauseErrorMessageRouter
|
||||
Added removeAttribute() and removeProperty() methods to MessageHeader
|
||||
When passing to a handling method, primitive arrays are no longer cast to Object[]
|
||||
Failed Messages (when available) are now propagated within MessageHandlingException and MessageDeliveryException
|
||||
Provided configurable property for registering an asynchronous TaskExecutor for the ApplicationEventMulticaster
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Provided namespace support for configuring the MessageHeaderMapper for JMS sources and targets
|
||||
FileNameGenerator is now configurable for a FileTarget
|
||||
File-Message mapping now supports text, binary, and File object
|
||||
Mapping to JMS properties from the MessageHeader no longer fails on JMSException
|
||||
|
||||
*** CONFIGURATION ***
|
||||
|
||||
Added namespace support for the <gateway/> element
|
||||
Added namespace support for the <splitter/> element
|
||||
Added namespace support for the <router/> element
|
||||
Added namespace support for different channel types (queue, priority, rendezvous, direct, thread-local)
|
||||
Defined ChannelFactory strategy for the plain <channel/> elements and for the MessageBus 'auto-create' mode
|
||||
Added namespace support for <console-source/> and <console-target/> elements
|
||||
The <source-adapter/> element now produces a MethodInvokingSource
|
||||
The <target-adapter/> element now produces a MethodInvokingTarget
|
||||
Added annotation support for scheduling metadata on a message endpoint
|
||||
@Splitter no longer accepts a "channel" attribute (now uses endpoint's output-channel)
|
||||
A @MessageEndpoint annotated class now requires the presence of a handler method
|
||||
The endpoint's <selector/> sub-element has been replaced by the "selector" attribute
|
||||
The endpoint's <concurrency/> and <schedule/> elements can now occur in any order
|
||||
Fixed timing issue between <annotation-driven/> and <message-bus/> in a ClasspathXmlApplicationContext
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
Now using the SpringSource Enterprise Bundle Repository for dependencies
|
||||
Updated MANIFEST.MF files for imports, exports, and bundle metadata
|
||||
Adjusted ivy configuration for provided and runtime dependency scopes
|
||||
Moved spring.schemas and spring.handlers files to src/main/resources
|
||||
Refactored the core's org.springframework.integration.adapter package contents into other packages
|
||||
Added several diagrams to the Reference Documentation's "overview" section
|
||||
Upgraded to Spring 2.5.4.A and Spring-WS 1.5.1.A
|
||||
|
||||
|
||||
Changes in version 1.0.0.M3 (Apr 07, 2008)
|
||||
------------------------------------------
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
Handler method invocation now uses Spring's default type-conversion strategies
|
||||
Message priorities are now defined in the MessagePriority enum
|
||||
Added ResponseCorrelator for polling a reply channel with a correlationId
|
||||
Added SynchronousChannel that invokes handlers on the sender's thread
|
||||
or receives from a PollableSource on the receiver's thread
|
||||
Implemented the WireTap pattern with a ChannelInterceptor that publishes to a secondary channel
|
||||
Calling setErrorChannel on MessageBus no longer throws NullPointerException upon activation
|
||||
ChannelPurger now accepts multiple MessageChannels (as varargs) in its constructors
|
||||
RouterMessageHandlerAdapter now sets the ChannelRegistry on its target Object if it is ChannelRegistryAware
|
||||
DefaultMessageEndpoint now sets the ChannelRegistry on any ChannelRegistryAware handler
|
||||
MessageEndpointAnnotationPostProcessor now sets the ChannelRegistry for any annotated ChannelRegistryAware Object
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Added FtpSourceAdapter
|
||||
Added HttpInvokerSourceAdapter
|
||||
Added HttpInvokerTargetAdapter
|
||||
Added RmiSourceAdapter
|
||||
Added RmiTargetAdapter
|
||||
Added SimpleWebServiceTargetAdapter
|
||||
Added MarshallingWebServiceTargetAdapter
|
||||
Added a DefaultMailHeaderGenerator and defined constants in MailAttributeKeys
|
||||
CharacterStreamSourceAdapter now requires a Reader (not InputStream)
|
||||
CharacterStreamTargetAdapter now requires a Writer (not OutputStream)
|
||||
The stdoutAdapter and stderrAdapter factory methods now accept a 'charsetName'
|
||||
JMS source adapters now copy properties from the received JMS Message header
|
||||
JMS source and target adapter parsers now consider "connectionFactory" as the default bean-name reference
|
||||
|
||||
*** CONFIGURATION ***
|
||||
|
||||
Added namespace support for PriorityChannel with the <priority-channel/> element
|
||||
Added @Concurrency annotation for configuring a @MessageEndpoint's ConcurrencyPolicy
|
||||
Added @Aggregator annotation for specifying aggregating handler methods
|
||||
Added <aggregator/> element for defining an aggregating handler in XML
|
||||
Annotation-based BeanPostProcessors now handle proxies correctly
|
||||
Annotation-based BeanPostProcessors now recognize inherited class-level annotations
|
||||
even if they are not explicitly @Inherited and even if they are on an interface
|
||||
Added support for <rmi-source/> and <rmi-target/> elements
|
||||
Added support for <httpinvoker-source/> and <httpinvoker-target/> elements
|
||||
Added support for the <ftp-source/> element
|
||||
Added support for the <ws-target/> element
|
||||
Added support for the <mail-target/> element
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
The Spring Web Services support is included in a new 'spring-integration-ws' module
|
||||
Updated manifest properties for OSGi-compliance in "core" and "adapters"
|
||||
Added manifest properties for OSGi-compliance for "ws" and "samples"
|
||||
Added "Bundle-Name" to each manifest file
|
||||
|
||||
|
||||
Changes in version 1.0.0.m2 (Feb 28, 2008)
|
||||
------------------------------------------
|
||||
|
||||
*** CORE API ***
|
||||
|
||||
Defined the ChannelInterceptor strategy interface
|
||||
Implemented new priority-based MessageChannel (PriorityChannel)
|
||||
Created a MessageSelectingInterceptor, a ChannelInterceptor that delegates to a MessageSelector
|
||||
Added clear and purge methods to MessageChannel (purge accepts a MessageSelector)
|
||||
Implemented a ChannelPurger that delegates to one or more MessageSelectors
|
||||
ChannelRegistry now provides 'unregister' method for runtime removal of channels
|
||||
Added RequestReplyTemplate for synchronous, blocking request/reply behavior over an asynchronous channel
|
||||
Added isExpired() method to Message
|
||||
Added a constructor to GenericMessage that copies MessageHeader properties and attributes
|
||||
Using the header-copying constructor in MessageHandler adapters to preserve header information
|
||||
Undeliverable replies from endpoint are passed to its ErrorHandler
|
||||
ErrorHandler is now a configurable strategy for MessageEndpoints
|
||||
ReplyHandler is now a configurable strategy for MessageEndpoints
|
||||
Subscription is now immutable
|
||||
Errors in ConcurrentHandler are now always logged at DEBUG level, and at WARN level if no 'errorHandler' is available
|
||||
Endpoints now set the 'correlationId' on reply Messages
|
||||
Defined Aggregator and CompletionStrategy and implemented an AggregatingMessageHandler
|
||||
SplitterMessageHandlerAdapter now sets sequenceNumber and sequenceSize header properties automatically
|
||||
Added 'sendTimeout' property to SplitterMessageHandlerAdapter
|
||||
|
||||
*** ADAPTERS ***
|
||||
|
||||
Added Mail target adapter
|
||||
Acknowledge modes are now configurable for JmsMessageDrivenSourceAdapter
|
||||
JMS attributes are now set from the MessageHeader prior to sending via JmsTargetAdapter
|
||||
The <jms-source/> element now accepts a 'message-converter' attribute
|
||||
|
||||
*** CONFIGURATION ***
|
||||
|
||||
Added <interceptor/> sub-element for <channel/>
|
||||
Added <selector/> sub-element for <endpoint/>
|
||||
Added <handler-chain> element that accepts <handler/> sub-elements for creating a MessageHandlerChain
|
||||
Added <aggregator/> element to the namespace for creating AggregatingMessageHandlers
|
||||
Added "dataype" attribute to the <channel/> element for message payload datatype enforcement
|
||||
Added 'initialDelay' and 'fixedRate' attributes to the @Polled annotation
|
||||
Added 'destination-name' attribute for JmsTargetAdapter
|
||||
Added 'autoStartup' property to MessageBus (and corresponding XML attribute) with a default value of 'true'
|
||||
Added 'defaultConcurrencyPolicy' property to MessageBus (and corresponding XML sub-element)
|
||||
Defined default error channel key as "errorChannel" (also added ERROR_CHANNEL_NAME constant in MessageBus)
|
||||
|
||||
*** GENERAL ***
|
||||
|
||||
Separated "spring-integration-core" from "spring-integration-adapters"
|
||||
Added manifest properties for OSGi-compliance
|
||||
Refactored package structure to remove all cycles
|
||||
Using java.util.UUID for default ID generation strategy
|
||||
Increased DEBUG logging throughout, especially for channel and endpoint
|
||||
Components delegating to (Scheduled)ExecutorService are now configurable through standard injection
|
||||
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,21 +0,0 @@
|
||||
========================================================================
|
||||
== NOTICE file corresponding to section 4 d of the Apache License, ==
|
||||
== Version 2.0, in this case for the Spring Integration distribution. ==
|
||||
========================================================================
|
||||
|
||||
This product includes software developed by
|
||||
the Apache Software Foundation (http://www.apache.org).
|
||||
|
||||
The end-user documentation included with a redistribution, if any,
|
||||
must include the following acknowledgement:
|
||||
|
||||
"This product includes software developed by the Spring Framework
|
||||
Project (http://www.springframework.org)."
|
||||
|
||||
Alternatively, this acknowledgement may appear in the software itself,
|
||||
if and wherever such third-party acknowledgements normally appear.
|
||||
|
||||
The names "Spring", "Spring Framework", and "Spring Integration" must
|
||||
not be used to endorse or promote products derived from this software
|
||||
without prior written permission. For written permission, please contact
|
||||
enquiries@springsource.com.
|
||||
@@ -1,27 +0,0 @@
|
||||
SPRING INTEGRATION 2.0.0 Milestone 7 (Sept 03, 2010)
|
||||
----------------------------------------------------
|
||||
|
||||
To find out what has changed since version 1.0.x or 2.0 M6, see 'changelog.txt'
|
||||
|
||||
Please consult the documentation located within the 'docs/reference' directory of this
|
||||
release and also visit the official Spring Integration home at:
|
||||
http://www.springsource.org/spring-integration
|
||||
|
||||
There you will find links to the forum, issue tracker, and several other resources.
|
||||
|
||||
To build and run the sample applications that are included with this distribution,
|
||||
view the README.txt file in the 'samples' directory.
|
||||
|
||||
To checkout the project from the SVN head and build from source, do the following
|
||||
(NOTE: this requires Maven 2.2.x):
|
||||
|
||||
svn co https://src.springsource.org/svn/spring-integration/trunk .
|
||||
mvn clean install
|
||||
|
||||
To build the JavaDoc, run `mvn javadoc:aggregate` from within the root directory. The
|
||||
result will be available in 'target/site/apidocs'.
|
||||
|
||||
The projects are Maven enabled, so you should be able to import them into any IDE that
|
||||
has support for Maven (2.2 or greater). The SpringSource Tool Suite (STS) ships with
|
||||
support for Maven projects, is free-of-charge and is the recommended IDE for use with
|
||||
Spring Integration (http://springsource.com/products/sts).
|
||||