I've been trying to figure this out for the last few day and I've run out of
ideas. I am testing a message driven been ActiveMQ 4.1 using Jencks 2.0 and
Spring 2.0.3. Things work fine when no runtime exception is thrown in my
message listener. When I do through one ActiveMQ reconnects to the broker
and neither the rolled back message nor any other message  makes it to my
listener until I restart the application.

This is my Spring file for the listener.

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: spring -->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd";>
<beans>
  <!--
  || The TransactionManager
  -->
  <bean id="transactionManager"
class="org.jencks.factory.TransactionManagerFactoryBean"/>

  <!-- START SNIPPET: jca -->
  <bean id="jencks" class="org.jencks.JCAContainer">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="threadPoolSize" value="25"/>

    <!-- the JCA Resource Adapter -->
    <property name="resourceAdapter">
      <bean id="activeMQResourceAdapter"
class="org.apache.activemq.ra.ActiveMQResourceAdapter">
        <property name="serverUrl" value="tcp://localhost:61616"/>
      </bean>
    </property>
  </bean>
  <!-- END SNIPPET: jca -->

  <bean id="echoBean" class="my.sandbox.jms.EchoBean"/>
 
  <!-- END SNIPPET: inbound -->

  <!--
    || an inbound message connector using a stateful, pooled 
MessageListener
    -->
  <bean id="requestResponseMEP" 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="test.spring.inboundConnectorB"/>
        <property name="destinationType" value="javax.jms.Queue"/>
      </bean>
    </property>

    <!-- use XA transactions -->
    <property name="transactionManager" ref="transactionManager"/>

    <property name="ref" value="echoBean"/>
  </bean>  
 
</beans>

        <!-- END SNIPPET: spring -->

The EchoBean is very simple.

package my.sandbox.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EchoBean implements MessageListener
{
        private final Log logger = LogFactory.getLog(getClass());
         
        public void onMessage(Message message)
        {
                try {
                        logger.info("onMessage: " +
((TextMessage)message).getText());
                        throw new RuntimeException("Boom!...Please roll me
back");
                } catch (JMSException e) {
                        logger.error(e);
                }
        }

}

Stepping through the code it appears that the exception makes it all the way
back to ActiveMQSession and hits this snippet...

            try {
                messageListener.onMessage(message);
            } catch ( Throwable e ) {  
                // TODO: figure out proper way to handle error.
                log.error("error dispatching message: ",e);
                connection.onAsyncException(e);
            }


That TODO ends up closing the current connections to the broker and while it
does reconnect the messages never get to the listener. They get as far as
the ActiveMQSession  but a flag appears to not let them be processed. I have
gotten the rollback to work using Springs DefaultMessageListenerContainer
but I'm not a big fan of it for an enterprise solution.

I know something very obvious is staring me right in the face, but after 3
days I'm hoping somebody will tell me what it is. I'd appreciate any help.
-- 
View this message in context: 
http://www.nabble.com/Problems-with-Rollbacks-tf3408597s2354.html#a9495461
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to