You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by pcasar <pa...@guests.nch.it> on 2007/01/19 11:15:34 UTC

Receive forever in transacted session

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.


Re: Receive forever in transacted session

Posted by Simon Wistow <si...@thegestalt.org>.
On Fri, Jan 19, 2007 at 06:35:39AM -0800, pcasar said:
> 
> In the test I first send ONE message and then I reveive it twice.
> The problem is that it seems that the receive doesn't remove the message
> returned from the queue...

We've seen similar issues, especially using Stomp.

We suspect it's an ACKing problem.



Re: Receive forever in transacted session

Posted by pcasar <pa...@guests.nch.it>.
In the test I first send ONE message and then I reveive it twice.
The problem is that it seems that the receive doesn't remove the message
returned from the queue...

Paolo.



James.Strachan wrote:
> 
> On 1/19/07, pcasar <pa...@guests.nch.it> wrote:
>> Nothing could be published because I'm the only client that use that
>> queue:
>> The jndi.properties associated to this test is:
>>
>> java.naming.factory.initial =
>> org.apache.activemq.jndi.ActiveMQInitialContextFactory
>> java.naming.provider.url = vm:broker:(vm://localhost)?useJmx=false
>> connectionFactoryNames = connectionFactory, queueConnectionFactory,
>> topicConnectionFactry
>> queue.MyQueue = MyQueue
>>
>> So I create a In memory broker.
> 
> So where do the messages come from then?
> 
> -- 
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> 
> 

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


Re: Receive forever in transacted session

Posted by James Strachan <ja...@gmail.com>.
On 1/19/07, pcasar <pa...@guests.nch.it> wrote:
> Nothing could be published because I'm the only client that use that queue:
> The jndi.properties associated to this test is:
>
> java.naming.factory.initial =
> org.apache.activemq.jndi.ActiveMQInitialContextFactory
> java.naming.provider.url = vm:broker:(vm://localhost)?useJmx=false
> connectionFactoryNames = connectionFactory, queueConnectionFactory,
> topicConnectionFactry
> queue.MyQueue = MyQueue
>
> So I create a In memory broker.

So where do the messages come from then?

-- 

James
-------
http://radio.weblogs.com/0112098/

Re: Receive forever in transacted session

Posted by pcasar <pa...@guests.nch.it>.
Nothing could be published because I'm the only client that use that queue:
The jndi.properties associated to this test is:

java.naming.factory.initial =
org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = vm:broker:(vm://localhost)?useJmx=false
connectionFactoryNames = connectionFactory, queueConnectionFactory,
topicConnectionFactry
queue.MyQueue = MyQueue

So I create a In memory broker.

TIA,
  Paolo.


James.Strachan wrote:
> 
> You don't describe how messages get on the queue - could something
> else have published since your queue browser was created?
> 
> On 1/19/07, pcasar <pa...@guests.nch.it> wrote:
>>
>> 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.
>>
>>
> 
> 
> -- 
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> 
> 

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


Re: Receive forever in transacted session

Posted by James Strachan <ja...@gmail.com>.
You don't describe how messages get on the queue - could something
else have published since your queue browser was created?

On 1/19/07, pcasar <pa...@guests.nch.it> wrote:
>
> 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.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/