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.
An "inbound-channel-adapter" element can invoke any method on a Spring-managed Object and send a non-null return
value to a
MessageChannel after converting it to a
When the adapter's subscription is activated, a poller will attempt to receive messages from the source. The
poller will be scheduled with the
TaskScheduler 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'
<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>
If no poller is provided, then a single default poller must be registered within the context. See Section 4.4, “Namespace Support” for more detail.
An "outbound-channel-adapter" element can also connect a
MessageChannel to any POJO consumer
method that should be invoked with the payload of Messages sent to that channel.
<outbound-channel-adapter channel="channel1" ref="target1" method="method1"/>
If the channel being adapted is a
PollableChannel, provide a poller sub-element:
<outbound-channel-adapter channel="channel2" ref="target2" method="method2"> <poller fixed-rate="3000"/> </outbound-channel-adapter> <beans:bean id="target1" class="org.bar.Foo"/>
Using a "ref" attribute is generally recommended if the POJO consumer implementation can be reused
<outbound-channel-adapter> definitions. However if the consumer implementation
should be scoped to a single definition of the
<outbound-channel-adapter>, you can define it as inner bean:
<outbound-channel-adapter channel="channel2" method="method2"> <beans:bean class="org.bar.Foo"/> </outbound-channel-adapter>
Using both the "ref" attribute and an inner handler definition in the same
Any Channel Adapter can be created without a "channel" reference in which case it will implicitly create an
DirectChannel. The created channel's name will match the "id" attribute
of the <inbound-channel-adapter/> or <outbound-channel-adapter element. Therefore, if the "channel"
is not provided, the "id" is required.