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
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
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.
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?
My queue name is: sonic.tcp::tcp://ip:port/SyncInputMessage
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."
[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
Only SyncInputMessage looks like the queue name. The other parts seem to be the details for the connection.
I tried with only queue name and I have this error message:
javax.jms.InvalidDestinationException: Queue not found: SyncInputMessage
You will have to change the name of the queue.
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
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.
Here my screenshot.
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?
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).
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?
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.
Thank you!