You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by kaluza <ac...@mailinator.com> on 2010/04/06 06:51:35 UTC

Duplicate queued messages when restarting tomcat

Hello, we have a system that processes email requests that are dumped into a
queue.  The system is a war deployed on Tomcat 6.0.26.  When Tomcat is
restarted we're getting duplicate emails being sent.  These appear to come
from the default persistence provider's data file
(activemq-data/localhost/journal/data-133).  Every time we restart Tomcat,
the same  duplicate email gets sent.  We have many old data-xxx files in the
activemq-data/localhost/journal dir.

We're using an embedded activemq broker and  the version of ActiveMQ is
5.2.0.

Within our application we have one producer populating a queue and 4
consumers threads processing messages off that queue.  We're using
CLIENT_ACKNOWLEDGE.

Why is it that the same messages get replayed when the server is restarted? 
I would have thought that after the first retry attempt, the client ack
would have been received , the messages marked delivered, and the (old)
activemq-data/localhost/journal/data-133 file deleted.  Yet that isn't what
is happening.

Here is a snippet of the context.xml that sets up the JNDI:
    <Resource
        name="jms/ConnectionFactory"
        auth="Container"
        type="org.apache.activemq.ActiveMQConnectionFactory"
        description="JMS Connection Factory"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
               
brokerURL="vm:(broker:(tcp://localhost:61617,network:static:tcp:second:61617))?jms.redeliveryPolicy.maximumRedeliveries=7&amp;jms.redeliveryPolicy.useExponentialBackOff=true"
        brokerName="LocalActiveMQBroker"
        useEmbeddedBroker="true"/>

    <Resource name="jms/queue/j2es0"
        auth="Container"
        type="org.apache.activemq.command.ActiveMQQueue"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="j2es0"/>


Here is a code snippet that sets up the receiver :

      // SETUP THE HIGHEST PRIORITY QUEUE
      // we use 4 threads for listening to this queue
      String queueName = jmsQueue+"0";
      Queue queue = (Queue) env.lookup(queueName);
      // Start four receiver threads for the highest priority queue ('0')
      for ( int x = 0; x < 4; x++ ) { 
        // Each listener must have a separate session in order to handle
recovery properly
        QueueConnection connection = factory.createQueueConnection();
        QueueSession tmp = connection.createQueueSession(false,
javax.jms.Session.CLIENT_ACKNOWLEDGE);
        QueueReceiver receiver = tmp.createReceiver(queue);
        receiver.setMessageListener(new RecoverListener(engine, tmp));
        connection.start();
        receivers.add(receiver);
        log.info("adding listener to queue:"+queueName);
      }   


Thanks for your help.


-- 
View this message in context: http://old.nabble.com/Duplicate-queued-messages-when-restarting-tomcat-tp28147462p28147462.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.