Hi all, I'm writing a quick app for testing MDP's with Spring 2.5, Active MQ 5.2.0, and Jencks 2.1. I've used the spring context and the MessageListener below. I'd like to utilize the SessionAwareMessageListener interface in Spring so I can have access to the session object. Is there a way to configure this with spring and Jencks? I can't seem to find any documentation on what I need, so any help would be appreciated.
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="com.onwebconsulting.messaging" /> <context:property-placeholder location="file:${properties-file}" /> <bean id="jencks" class="org.jencks.JCAContainer"> <property name="threadPoolSize" value="25" /> <property name="transactionManager" ref="transactionManager" /> <!-- the JCA Resource Adapter --> <property name="resourceAdapter"> <bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter"> <property name="serverUrl" value="${mq.broker.url}" /> </bean> </property> </bean> <bean id="inboundConnectorA" class="org.jencks.JCAConnector"> <property name="jcaContainer" ref="jencks" /> <!-- subscription details --> <property name="activationSpec"> <bean class="org.apache.activemq.ra.ActiveMQActivationSpec"> <property name="destination" value="${mq.queue.name}" /> <property name="destinationType" value="javax.jms.Queue" /> </bean> </property> <property name="transactionManager" ref="transactionManager"></property> <property name="ref" value="listener" /> </bean> <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean" /> </beans> Listener class package com.onwebconsulting.messaging.reader.jms; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.Session; import javax.jms.TextMessage; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.stereotype.Service; import com.onwebconsulting.messaging.reader.MessageReceiver; /** * * @author Todd Nine * */ @Service("listener") public class TextMessageReceiver implements MessageListener, SessionAwareMessageListener, MessageReceiver { /* * (non-Javadoc) * * @see org.springframework.jms.listener.SessionAwareMessageListener#onMessage(javax.jms.Message, * javax.jms.Session) */ public void onMessage(Message message, Session session) throws JMSException { if (!(message instanceof TextMessage)) { session.rollback(); return; } TextMessage txtMessage = (TextMessage) message; receiveMessage(txtMessage.getText()); } /* * (non-Javadoc) * * @see com.onwebconsulting.messaging.reader.MessageReceiver#receiveMessage(java.lang.String) */ public void receiveMessage(String inputMessage) { System.out.println(inputMessage); } public void onMessage(Message message) { if (!(message instanceof TextMessage)) { throw new RuntimeException("Incorrect message type"); } TextMessage txtMessage = (TextMessage) message; try { receiveMessage(txtMessage.getText()); } catch (JMSException e) { throw new RuntimeException(e); } } } Thanks, Todd
