PDA

View Full Version : Using JmsMessageDrivenSourceAdapter



jtschommer
Mar 5th, 2008, 08:38 AM
I have been trying to use the JmsMessageDrivenSourceAdapter. By my understanding of the documentation, it should create a container listener over a queue and allow for multiple receivers to be passed the messages as they arrive. I have gotten this to work using Spring's standard SimpleMessageListenerContainer and MessageListenerAdapter and see the connection created to the queue manager. Although there are no critical errors when it is run, there are no connections to the queue manager. I have tried it with both WMQ Series and Active MQ with the same results. Here is the code.

Configuration
<message-bus dispatcher-pool-size="25" auto-create-channels="true" >
<annotation-driven />
<context:component-scan base-package="com.springinttest" />

<channel id="inputChannel1" />

<endpoint input-channel="inputChannel1" handler-ref="MyMdp"
handler-method="processMessage">
<concurrency core="5" max="25" />
</endpoint>

<beans:bean id="MySourceAdapter"
class="org.springframework.integration.adapter.jms.JmsMes sageDrivenSourceAdapter"
lazy-init="false" init-method="initialize">
<beans:property name="connectionFactory"
ref="connectionFactory" />
<beans:property name="destination" ref="destination" />
<beans:property name="channel" ref="inputChannel1" />
</beans:bean>

<beans:bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<beans:property name="brokerURL" value="tcp://localhost:61616" />
</beans:bean>

<beans:bean id="destination"
class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg index="0" value="myQueue"/>
</beans:bean>


<beans:bean id="MyMdp" class="com.springinttest.MyMdp" />

</beans:beans>

Handler

package com.springinttest;

import org.springframework.integration.annotation.Message Endpoint;
import org.springframework.integration.annotation.Handler ;
import org.apache.log4j.Logger;

@MessageEndpoint(input="inputChannel1")
public class MyMdp {

private static final Logger LOGGER = Logger.getLogger(MyMdp.class);

public MyMdp() {
LOGGER.warn("Constructor Set");
}
@Handler
public void processMessage(String message) {

try {
System.out.println(message.toString());
LOGGER.warn("Received message is: " + message.toString());
} catch (Exception e) {
System.out.println("Captain Chaos");
// handle this-somehow
}
}
}

jtschommer
Mar 6th, 2008, 09:11 AM
I found the issue, but this is still strange. I was building my project using Maven and deploying on Tomcat. The Maven Repositories that we use here, S3Browse.com, for example only had the core jar file listed and only for m1. So I did not realize I was missing the adapters jar until yesterday. The funny thing is Spring loaded everything and did not complain that it could not find the JmsMessageDrivenSourceAdapter class. It just ran and issued no errors, which is what through me off. Does anyone know of a good Maven repository that has both jars for m2 that I should be using? Thanks

Mark Fisher
Mar 6th, 2008, 09:22 AM
Thanks for pointing that out. I will look into the milestone repository and make sure that the M2 jars are available.

Actually, the snapshot repository is up to date: http://s3browse.com/explore/maven.springframework.org/snapshot/org/springframework/integration/

The jars with a "ci" suffix are produced from our continuous integration build each night. For example, the "ci-57" jars correspond to nightly build 57: https://build.springframework.org/browse/INT-NIGHTLY-57

There you can even see what issues are included in each build, and links to Jira are provided as well.

-Mark

Mark Fisher
Mar 6th, 2008, 02:28 PM
The M2 jars are now available in the milestone repository as well: http://s3browse.com/explore/maven.springframework.org/milestone/org/springframework/integration/

-Mark