[jboss-user] [JBoss Messaging] - How to list or monitor messages in a Queue which is already under use

Aneesh Sebastian do-not-reply at jboss.com
Tue Feb 28 04:12:34 EST 2012


Aneesh Sebastian [https://community.jboss.org/people/aneeshsebastian] created the discussion

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

To view the discussion, visit: https://community.jboss.org/message/720125#720125

--------------------------------------------------------------
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 :

*Option1* 

 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) {
                System.out.println((++count)+"t"+msg.getJMSMessageID());
                if(msg.getJMSType() != null && msg.getJMSType().equalsIgnoreCase("Text")) {
                    TextMessage text = (TextMessage)msg; 
                    System.out.println(text.getText());
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

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

*Option2*

    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();
            }
            connection.start();  


        }
        catch(Exception e)  
        {  
            System.out.println(e);
        }  
        finally  
        {           
            if(ic != null)  
            {  
                try  
                {  
                    ic.close();  
                }  
                catch(Exception e1)  
                {  
                    System.out.println(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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/720125#720125]

Start a new discussion in JBoss Messaging at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120228/74e07bf3/attachment.html 


More information about the jboss-user mailing list