2 Replies Latest reply: Sep 12, 2012 10:33 AM by jboss debugg RSS

How to list or monitor messages in a Queue which is already under use

Aneesh Sebastian Newbie

I have a requirement to monitor a JBoss messaging queue, where users should be able to delete posted messages dynamically. The application has a MDPOJO registered and is up and running at server start up.


My requirement is, users should be able to delete a posted message any time he wishes. I tried below proto codes :




public void listAllJMS_Messages()


        try {

            ObjectName objectName=new ObjectName("jboss.messaging.destination:name=XXX,service=Queue");

            List ls = (List) server.invoke(objectName, "listMessages" , null, null);

            List<javax.jms.Message> messages=(List<javax.jms.Message>)server.invoke(objectName, "listAllMessages" , null, null);

            int count=0;

            for(javax.jms.Message msg : messages) {


                if(msg.getJMSType() != null && msg.getJMSType().equalsIgnoreCase("Text")) {

                    TextMessage text = (TextMessage)msg;




        } catch (Exception e) {

            // TODO Auto-generated catch block




        // System.out.println((++count)+"t"+msg.getText());





    public void listMsg() {


        String destinationName = "queue/XXX"; 

        Context ic = null; 

        ConnectionFactory cf = null; 

        Connection connection =  null;

        try {

            ic = getInitialContext(); 

            cf = (ConnectionFactory)ic.lookup("/ConnectionFactory"); 

            Queue queue = (Queue)ic.lookup(destinationName); 

            connection = cf.createConnection(); 

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 

            QueueBrowser qbrowser = session.createBrowser(queue);

            Enumeration<?> qamsgs = qbrowser.getEnumeration();

            while (qamsgs.hasMoreElements()){

                Message msg = (Message)qamsgs.nextElement();






        catch(Exception e) 






            if(ic != null) 






                catch(Exception e1) 









In both the options,messages are getting listed in case of no message consumers at present.If have a live message consumer MDB, then list is returned as null.


I defintely need MDB consumer up and running.But still need to monitor messages.I should be able to do below :


1. List messages]

2. Delete a particular message

3. Change priority