Spring Integration provides two adapters for accepting JMS messages (as mentioned above):
JmsSource
and JmsGateway
. The former uses Spring's
JmsTemplate
to receive based on a polling period. The latter configures and delegates to
an instance of Spring's DefaultMessageListenerContainer
.
The JmsSource
requires a reference to either a single JmsTemplate
instance or both ConnectionFactory
and Destination
(a 'destinationName' can be provided in place of the 'destination' reference). The JmsSource
can then be referenced from a "channel-adapter" element that connects the source to a
MessageChannel
instance. The following example defines a JMS source with
a JmsTemplate
as a constructor-argument.
<bean id="jmsSource" class="org.springframework.integration.adapter.jms.JmsSource"> <constructor-arg ref="jmsTemplate"/> </bean>
In most cases, Spring Integration's message-driven JmsGateway
is more appropriate since it
delegates to a MessageListener
container, supports dynamically adjusting
concurrent consumers, and can also handle replies. The JmsGateway
requires references to
a ConnectionFactory
, and a Destination
(or
'destinationName'). The following example defines a JmsGateway
that receives from the JMS
queue called "exampleQueue". Note that the 'expectReply' property has been set to 'true' (it is 'false' by
default):
<bean class="org.springframework.integration.adapter.jms.JmsGateway"> <property name="connectionFactory" ref="connectionFactory"/> <property name="destinationName" value="exampleQueue"/> <property name="expectReply" value="true"/> </bean>
The JmsTarget
implements the MessageTarget
interface
and is capable of mapping Spring Integration Messages
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). In
Section 4.2.4, “Configuring Adapters”, you will see how to configure a JMS target adapter with Spring
Integration's namespace support.