I am trying to write a Java program that can view all JMS queues on a JMS Weblogic server and read messages in a given queue (but not consume them). I am trying to use Weblogic Mbeans and JMX, but new to both. I have the following code to get all the queues and their depth:
private void countMessages1() throws Exception {
JMXConnector connector = getMBeanServerConnector("/jndi/"+RuntimeServiceMBean.MBEANSERVER_JNDI_NAME);
MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();
ObjectName service = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
ObjectName serverRuntime = (ObjectName) mbeanServerConnection.getAttribute(service, "ServerRuntime");
ObjectName jmsRuntime = (ObjectName) mbeanServerConnection.getAttribute(serverRuntime, "JMSRuntime");
ObjectName[] jmsServers = (ObjectName[]) mbeanServerConnection.getAttribute(jmsRuntime, "JMSServers");
for (ObjectName jmsServer: jmsServers) {
if ("JMSServer".equals(jmsServer.getKeyProperty("Name"))) {
ObjectName[] destinations = (ObjectName[]) mbeanServerConnection.getAttribute(jmsServer, "Destinations");
for (ObjectName destination: destinations) {
String queueName = destination.getKeyProperty("Name");
Long queueDepth = (Long) mbeanServerConnection.getAttribute(destination, "MessagesCurrentCount");
System.out.println("Queue: " + queueName + " Depth: " + queueDepth);
}
break;
}
}
connector.close();
}
I also have the option to remove everything from the queue:
mbeanServerConnection.invoke(destination, "deleteMessages", new Object[] {""}, new String[] {"java.lang.String"});
, /. mbeanServerConnection.invoke, getMessage getMessages, , . -, , , ( )? , , :
String message = (String) mbeanServerConnection.invoke(destination, "getMessage", new Object[] { "", 0, JMS_ALL_STATES}, new String[] {"java.lang.String"});