[jboss-user] [Messaging, JMS & JBossMQ] - Synchronization Problem JMS Queue/Topic

dpabhay do-not-reply at jboss.com
Mon Nov 6 12:29:52 EST 2006


I have scheduled(once every minute it empties the queue) receiver from the queue. And I have multiple browsers of the queue using the objects from the queue.


I am using following code to browser through the objects on the queue. 
--------------
Queue queue = getQueue();
		    logger.info("Get queue. Name: " + queue.getQueueName());
			
		    conn = getQueueConnection();
			session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
			
			brower = session.createBrowser(queue);
			Enumeration enumeration = brower.getEnumeration();	
			
			while(enumeration.hasMoreElements())
			{
				Object message = enumeration.nextElement();
				if(message instanceof ObjectMessage)
				{
					ObjectMessage objMessage = (ObjectMessage)message;
					Object obj = objMessage.getObject();
					
				}
			}
--------------

And using the following code to receive/remove objects from the queue

--------------
conn = getQueueConnection();
			session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
			receiver = session.createReceiver(queue);
			Message message = null;
			message = receiver.receive(TIME_TO_WAIT);
			while (message != null) {
				message = receiver.receive(TIME_TO_WAIT);
			}
----------------------------

Task - the browsing of the queue and receiving from the queue must be mutually exclusive. Can I control that?

Even greater problem is that I would like to have multiple browsing readers to be able to access the queue and still guarantee that the receivers will run within the reasonably comparable time with the schedule- time of the receiver (1 minute).

How can I access the queue in such a way? Does JBoss have other control structures to do the kind of thing that I am trying to do? Any pointers and answers?

Please assist.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983502#3983502

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983502



More information about the jboss-user mailing list