Messaging (JMS)
Spring Integration provides Channel Adapters for receiving and sending JMS messages. There are actually two JMS-based inbound Channel Adapters as follows:
- Uses Spring’s JmsTemplate to receive based on a polling period
- Relies on Spring’s Message Listener Container and is considered “message-driven” approach
In addition, Spring Integration has an outbound Channel Adapter that uses the JmsTemplate to convert and send a JMS Message on demand.
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.
Listing 22-74 below shows the maven dependency required for supporting JMS support using Spring Integration.
Listing 22-74. Maven dependency required
1 2 3 4 5 6 7 8 9 |
<dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-jms</artifactId> <version>${spring-integration-version}</version> </dependency> |
Listing 22-75 below shows configuration of main Spring Integration namespace and JMS related namespace in the Spring configuration file (jms-integration-context.xml).
Listing 22-75. Spring Integration Namespace declaration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?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:int="http://www.springframework.org/schema/integration" xmlns:jms="http://www.springframework.org/schema/integration/jms" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/twitter/spring-integration-jms-2.1.xsd"> … </beans> |
Listing 22-76 below shows configuring jms inbound channel adapter using Spring’s JmsTemplate
Listing 22-76. Configuring jms inbound channel adapter using JmsTemplate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<beans …> … <int:channel id="inputChannel"/> <int:channel id="errorChannel"/> <jms:inbound-channel-adapter jms-template="jmsTemplate" channel="inputChannel"> <int:poller fixed-rate="500" max-messages-per-poll="1" error-channel="errorChannel"/> </jms:inbound-channel-adapter> <bean id="jmsTemplate" factory-method="…"> … </bean> … </beans> |
Listing 22-77 below shows configuring jms inbound channel adapter using Spring’s Message Container Listener
Listing 22-77. Configuring jms inbound channel adapter using Message Container Listener
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<beans …> … <int:channel id="inputChannel"/> <int:channel id="errorChannel"/> <jms:message-driven-channel-adapter id="jmsIn" destination="inQueue" channel="inputChannel" error-channel="errorChannel"/> … </beans> |
Listing 22-78 below shows configuring jms outbound channel adapter. In the below listing the configuration will produce an adapter that receives Spring Integration Messages from the “inputChannel” and then converts those into JMS Messages and sends them to the JMS Destination reference whose bean name is “outQueue”.
Listing 22-78. Configuring jms outbound channel adapter
1 2 3 4 5 6 7 8 9 10 11 |
<beans …> … <int:channel id="inputChannel"/> <jms:outbound-channel-adapter id="jmsOut" destination="outQueue" channel="inputChannel"/> … </beans> |
Listing 22-79 and Listing 22-80 below shows, configuring JMS inbound gateway and outbound gateway repectively, in the Spring configuration file.
Listing 22-79. Configuring jms inbound gateway
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<beans …> … <int:channel id="requestChannel"/> <jms:inbound-gateway id="jmsInGateway" request-destination="inQueue" request-channel="requestChannel"/> … </beans> |
Listing 22-80. Configuring jms outbound gateway
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<beans …> … <int:channel id="requestChannel"/> <int:channel id="replyChannel"/> <jms:outbound-gateway id="jmsOutGateway" request-destination="outQueue" request-channel="requestChannel" reply-channel="replyChannel"/> … </beans> |
Page Visitors: 13117

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023
Hi,
Thanks for this blog and information sharing!
I have one question from Spring Integration. Just thought of checking with you.
I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
This is my current gateway configuration:
Please let me know, if you can throw some light in this area.
Thanks in Advance!
Hi,
Thank you for your information sharing.
I have one doubt,could you please suggest me the correct frameworks to address that issue.
My requirement is I would like to get and process files using spring and camel.
Thanks,
Madhu