Announcement Announcement Module
Collapse
No announcement yet.
Jms - queue browser Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jms - queue browser

    Hi,

    I'm using ActiveMQ 5.2 and I'm trying to browse queue. I'm using JmsTemplate.
    This is fragment of my code:

    Code:
    final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerURL);
    		
    		final Queue embargoQueue = new ActiveMQQueue("embargo");
    		final JmsTemplate embargoJmsTemplate = new JmsTemplate();
    		embargoJmsTemplate.setConnectionFactory(connectionFactory);
    		embargoJmsTemplate.setDefaultDestination(embargoQueue);
    		
    		Integer count = 
    			(Integer)embargoJmsTemplate.execute(new SessionCallback() {
    				
    				public Object doInJms(Session session) throws JMSException {
    					int count = 0;
    					QueueBrowser browser = session.createBrowser((Queue)embargoJmsTemplate.getDefaultDestination());
    					Enumeration messages = browser.getEnumeration();
    					
    					while(messages.hasMoreElements()) {
    						count++;
    						messages.nextElement();
    					}
    					return new Integer(count);
    				}
    			});
    		System.out.println("Number of message -: "+count);
    But I get message that number of message is 0 (queue is empty) whereas jconsole shows that queue contains 27 messages.
    So, why it doesn't work?

    Thanks for any advice.

    Cheers,
    Marcin
Working...
X