activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pcasar <paolo.casar...@guests.nch.it>
Subject Receive forever in transacted session
Date Fri, 19 Jan 2007 10:15:34 GMT

Hi,

Using tansacted session I sent ONE message to a queue, then I receive from
the same queue and I get the sent message. After the first receive I create
a queue browser that tell me that my queue is empty, but if I try to receive
once more on the same queue the result is not null!! Why? The queue was
empty!

Here the code of my test:

---------------------------------
	public void testMid2Simple() throws JMSException, NotSupportedException,
SystemException, RollbackException, HeuristicRollbackException,
HeuristicMixedException, NamingException {

		Context ctx = new InitialContext();
	    Queue q = (Queue)ctx.lookup("MyQueue");
	    
	    ///// SEND MESSAGE //////
	    QueueConnectionFactory factory =
(QueueConnectionFactory)ctx.lookup("queueConnectionFactory");
	    QueueConnection mqConn = factory.createQueueConnection();

	    mqConn.start();
		QueueSession mqQSess = mqConn.createQueueSession(true, 0);
		
		// do stuff
		QueueSender qs = mqQSess.createSender(q);
		Message m = mqQSess.createTextMessage("Hello!");
		qs.send(m);
		
		mqQSess.commit();
		mqConn.close();
		
	    ///// RECEIVE MESSAGE //////
		mqConn = factory.createQueueConnection();
		mqQSess = mqConn.createQueueSession(true, 0);
		
		QueueReceiver qr = mqQSess.createReceiver(q);
		mqConn.start();
		m = qr.receive(2000);
		if (m == null) {
			fail();
		}
		mqQSess.commit();
		mqConn.close();
		
		///// BROWSE QUEUE /////
		mqConn = factory.createQueueConnection();
		mqQSess = mqConn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
		
		QueueBrowser qb = mqQSess.createBrowser(q);
		if (qb.getEnumeration().hasMoreElements()) {
			for (Enumeration e = qb.getEnumeration(); e.hasMoreElements();) {
				Message ith = (Message)e.nextElement();
				ith.getJMSMessageID();
			}
			fail();
		}
		
		mqQSess.commit();
		mqConn.close();
		
	    ///// RE-RECEIVE MESSAGE //////
		mqConn = factory.createQueueConnection();
		mqQSess = mqConn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
		
		qr = mqQSess.createReceiver(q);
		mqConn.start();
		m = qr.receive(2000);
		if (m != null) {
			fail();   ///FAILS HERE
		}
		mqQSess.commit();
		mqConn.close();
	}
-----------------------------

TIA,
  Paolo.
-- 
View this message in context: http://www.nabble.com/Receive-forever-in-transacted-session-tf3039151.html#a8446747
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message