How to get the size of queued Messages in a Sonic MQ queue

Posted by Admin on 09-Dec-2010 03:27

Hello to all, and thanks in advange by your support.

We are stating to use Sonic MQ 7.6, and Ineed to get the size  of queued Messages in some Queues. For make this, I would create Java application.

heres the code i used:


        ConnectionFactory connectionFactory = null;
        try {
            connectionFactory = new progress.message.jclient.ConnectionFactory;();
        } catch (JMSException e)  {
            e.printStackTrace();
        }
        connectionFactory.setConnectionURLs("My_URL");
        connectionFactory.setConnectID(null);
        try {
            progress.message.jclient.Connection connection = (progress.message.jclient.QueueConnection)connectionFactory.createConnection();
        } catch (JMSException e) {
            e.printStackTrace();
        }

Is there a sample code that will allow me to do this? Thanks

All Replies

Posted by tsteinbo on 09-Dec-2010 06:28

Since you are using QueueConnection you can use a JMS Browser and peek at the queue and determine the message size that way.

Alternatively, use the Management Runtime API for the Broker (see BrokerProxy).

Thomas

Posted by Admin on 09-Dec-2010 08:44

Thanks for your answer. I complete my code but I have error :

javax.jms.InvalidDestinationException: Cannot create QueueBrowser on remote queue.

I don't understand why.

here my new code:

            connectionFactory = new ConnectionFactory();
            connectionFactory.setConnectionURLs("URL");
            connectionFactory.setConnectID(null);
            javax.jms.Connection connection = connectionFactory.createConnection("Administrator", "Administrator");
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("QueueName");
            QueueBrowser queueBrowser = session.createBrowser(queue);

I have check my queue name but I can't create browser.

Posted by rrudis on 09-Dec-2010 09:20

It would appear that you are trying to browse a queue is on a remote (DRA) node?  Is so, that is not supported - you have to be connected to a broker on that node. What is the your QueueName?

Posted by Admin on 09-Dec-2010 09:31

My queue name is: sonic.tcp::tcp://ip:port/SyncInputMessage

Posted by rrudis on 09-Dec-2010 09:43

Set the character restrictions in the 'Naming Rules and Allowed Characters in SonicMQ' section of the MQ Instatllation and Upgrade Guide.  In particular for queues: "Adjacent colons (::) are reserved for delimiting sections of global routing names."

Posted by Admin on 09-Dec-2010 10:02

[Edit:] Ok but I don't know how write the queue name because it is in a specific domain which use tcp protocol. can I connect to domain for get queue size?

Ce message a été modifié par: senol ozer

Posted by tsteinbo on 09-Dec-2010 10:11

Only SyncInputMessage looks like the queue name. The other parts seem to be the details for the connection.

Posted by Admin on 09-Dec-2010 10:15

I tried with only queue name and I have this error message:

javax.jms.InvalidDestinationException: Queue not found: SyncInputMessage

Posted by rrudis on 09-Dec-2010 10:26

You will have to change the name of the queue.

Posted by Admin on 09-Dec-2010 10:39

Why will I have to change the name of the queue? My problem is the queue is not found.. If I only change name, my problem will not resolved

Posted by rrudis on 09-Dec-2010 12:15

When I refer to a 'queue' I am referring to the queue object that is configured in the broker, not the queue name that you are passing to the session.createBrowser method. If you have somehow managed to create a queue in the broker that is named 'sonic.tcp::tcp://ip:port/SyncInputMessage' (and if so it would be good to know how the queue was created) you will not be able to access that queue, you will need to delete it a recreate it with a valid name.  If you still have issues you may want to attach a screen shot from the Sonic Management Console showing the list of queues.

Posted by Admin on 10-Dec-2010 02:40

Here my screenshot.

Posted by Admin on 10-Dec-2010 08:46

I found solution by changing  my url parameter in the method connectionFactory. I used other ip address and it is ok. Heres my code:

             connectionFactory = new ConnectionFactory();
            connectionFactory.setConnectionURLs("tcp://ip:port");
            connectionFactory.setConnectID(null);
            javax.jms.Connection connection = connectionFactory.createConnection("Administrator", "Administrator");
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("ASyncInputMessage");
            QueueBrowser queueBrowser = session.createBrowser(queue);
            System.out.println(queueBrowser.getMessageSelector());
            Enumeration messageEnum = queueBrowser.getEnumeration();
            System.out.println("getMessageSelector(): " + queueBrowser.getMessageSelector());
            while (messageEnum.hasMoreElements()) {
                System.out.println(messageEnum.nextElement());
                count++;
            }

But now I have the message number in my queue and I need the queue size. How can I get this information?

Posted by rrudis on 10-Dec-2010 09:29

Are you looking to get the total size of messages on a queue or the size of individual messages?  If total size see the ShowQueues.java sample in the /MQx.x/samples/Management/runtimeAPI folder.  Modify the line that prints out the queue info to include a call to IQueueData.getTotalMessageSize().  Keep in mind that you are connecting to the Domain Manager rather than the individual broker(s).

Posted by Admin on 10-Dec-2010 10:30

I am looking to get the total size of messages on a queue. Thanks for this sample but what is the id parameter of Common.getBrokerProxy?

Posted by rrudis on 10-Dec-2010 10:43

See the common.java source in the sample folder.  You'll also want to take a look at the SonicMQ Administrative Programming Guide, and/or the mgmt_api JavaDoc.

Posted by Admin on 10-Dec-2010 11:16

Thank you!

This thread is closed