I'd say your problem is due to the session running in auto-ack mode (so after the onMessage method completes) and your manual ack. I think ActiveMQ might just ignore your call to acknowledge() and wait for the method to complete. Since the 5 second sleep is inside the onMessage-method it'll assume that the last message was not delivered successfully and tries to redeliver it. Try if a change to manual-ack helps.
Mario On 2/11/08, wha <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm using the following version apache-activemq-5.1-20080208.142256-20.zip > > I have like 500 messages pending in the broker and I have the following > consumer: > > public void run() > { > //Create a connection > Connection conn = null; > > String user = null; > String passw = null; > String brokerurl = "tcp://localhost:61616"; > > try > { > ActiveMQConnectionFactory connFactory = new > ActiveMQConnectionFactory(user,passw,brokerurl); > conn = connFactory.createConnection(); > conn.start(); > > Session session = conn.createSession(false, > Session.AUTO_ACKNOWLEDGE); > > Queue dest = session.createQueue("Q1"); > > MessageConsumer msgConsumer = > session.createConsumer(dest); > > msgConsumer.setMessageListener(this); > > System.out.println("Listening Q1..."); > > } > catch (JMSException jmse) > { > System.out.println(jmse); > } > } > > public void onMessage(Message mess) > { > try > { > DateFormat dateFormat = new > SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); > java.util.Date date = new java.util.Date(); > > System.out.println(dateFormat.format(date) + " - > Received msg: " + > ((TextMessage)mess).getText()); > mess.acknowledge(); > > Thread.sleep(5 * 1000); > > } > catch(InterruptedException ie) > { > System.out.println(ie); > } > catch (JMSException jmse) > { > System.out.println(jmse); > } > > } > > When I stop the consumer and then restart it. The last message that was > received is being resent again by the broker. Is that normal behavior or is > there something wrong with my code?? > > Could it be my Thread.sleep that is executed too fast before an > aknowledgement can be sent ? > > Any help appreciated! > > Thanks! > > -- > View this message in context: > http://www.nabble.com/Start-Stop-Consumer-and-duplicate-message-is-received.-tp15422289s2354p15422289.html > Sent from the ActiveMQ - User mailing list archive at Nabble.com. > >