In this example we want to read one message froom one queue (request-queue) put some header on it and send uppercase response to reply queue (response-queue). Following is Integration diagram.
Create two queues from ActiveMQ web console.
Create two queues from ActiveMQ web console.
Following is configuration file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:int-jms="http://www.springframework.org/schema/integration/jms" | |
xsi:schemaLocation="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/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd"> | |
<!-- Loan Request comes from MQ message (temporary direct message) --> | |
<int:channel id="xmerChannel" /> | |
<int:channel id="svcActChannel" /> | |
<int-jms:inbound-gateway request-channel="xmerChannel" connection-factory="connectionFactory" request-destination="requestQueue" default-reply-destination="responseQueue" acknowledge="transacted"/> | |
<int:header-enricher input-channel="xmerChannel" | |
output-channel="svcActChannel"> | |
<int:header name="lang" value="en" /> | |
</int:header-enricher> | |
<int:service-activator id="printSvcActivator" ref="msgPrintBean" | |
method="printOutput" input-channel="svcActChannel"/> | |
<bean id="msgPrintBean" class="com.techrefresh.spring.integration.bean.UtilBean" /> | |
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue"> | |
<constructor-arg value="request-queue" /> | |
</bean> | |
<bean id="responseQueue" class="org.apache.activemq.command.ActiveMQQueue"> | |
<constructor-arg value="response-queue" /> | |
</bean> | |
<bean id="connectionFactory" | |
class="org.springframework.jms.connection.CachingConnectionFactory"> | |
<property name="targetConnectionFactory"> | |
<bean class="org.apache.activemq.ActiveMQConnectionFactory"> | |
<property name="brokerURL" value="tcp://localhost:61616" /> | |
</bean> | |
</property> | |
<property name="sessionCacheSize" value="10" /> | |
</bean> | |
<int:poller fixed-rate="1000" id="pollermain"></int:poller> | |
</beans> |
Folloiwng is util bean.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.techrefresh.spring.integration.bean; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class UtilBean { | |
private static final Logger logger = LoggerFactory.getLogger(UtilBean.class); | |
public String printOutput(String msg){ | |
logger.info("Simple message {}",msg); | |
return msg.toUpperCase(); | |
} | |
} |
Now send message from activemq web console.
Following is what you receive on response channel.