Results 1 to 4 of 4

Thread: JMS queue messages viewing without removing them from the queue

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Default JMS queue messages viewing without removing them from the queue

    I want to view ALL messages (message-driven POJOs) of a queue without removing them from the queue. Is there a way to accomplish that?

    I found out that with "sessionAcknowledgeMode", I can view one single message before acknowledging and removing it from a queue. But thats not what I want. I want a list of all the message without actually removing them.

    THX!

  2. #2
    Join Date
    Jun 2007
    Location
    Minsk, Belarus
    Posts
    215

    Default

    Have a look at JmsTemplate.browse* methods.

  3. #3
    Join Date
    Oct 2011
    Posts
    2

    Default solution

    Thanks for the hint...it really helped me out. In the following I'm posting my working source code for future readers.

    Code:
    jmstemplate.browse("requestQueue", new BrowserCallback<RepositoryUpdateRequest>() {
    	@Override
    	public RepositoryUpdateRequest doInJms(Session session, QueueBrowser browser) throws JMSException {
    		System.out.println("Whats in the query?");
    		int i = 1;
    
    		Enumeration e = browser.getEnumeration();
    
    		if (e instanceof ActiveMQQueueBrowser) {
    			ActiveMQQueueBrowser activemqbrowser = (ActiveMQQueueBrowser) e;
    
    			while (activemqbrowser.hasMoreElements()) {
    				Object o = activemqbrowser.nextElement();
    				
    				if (o instanceof ActiveMQObjectMessage) {
    					ActiveMQObjectMessage amq_message = (ActiveMQObjectMessage) o;
    					Object obj = amq_message.getObject();
    
    					if (obj instanceof RepositoryUpdateRequest) {
    						RepositoryUpdateRequest request = (RepositoryUpdateRequest) obj;
    						System.out.println(i + ": " + request.getTEST());
    					} else {
    						System.out.println(i + ": " + "not a RepositoryUpdateRequest");
    					}
    					i++;
    				}
    			}
    		}
    
    		return null;
    	}
    
    });

  4. #4
    Join Date
    Jun 2007
    Location
    Minsk, Belarus
    Posts
    215

    Default

    You don't need cast to Active MQ classes.
    Message in your case can be casted to javax.jms.ObjectMessage.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •