activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wha <willy...@cgi.com>
Subject Start/Stop Consumer and duplicate message is received.
Date Mon, 11 Feb 2008 22:30:16 GMT

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.


Mime
View raw message