Announcement Announcement Module
Collapse
No announcement yet.
JMS queue messages viewing without removing them from the queue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Have a look at JmsTemplate.browse* methods.

    Comment


    • #3
      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;
      	}
      
      });

      Comment


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

        Comment

        Working...
        X