83 lines
4.5 KiB
XML
83 lines
4.5 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
|
"http://www.oasis-open.org/docbook/xml/4.5/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>
|
|
<interval-trigger interval="5000"/>
|
|
</poller>
|
|
</inbound-channel-adapter>
|
|
|
|
<inbound-channel-adapter ref="source2" method="method2" channel="channel2">
|
|
<poller>
|
|
<cron-trigger expression="30 * 9-17 * * MON-FRI"/>
|
|
</poller>
|
|
</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>
|
|
<interval-trigger interval="3000"/>
|
|
</poller>]]></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> |