public class JMSQueueMaintain { public static final String WEBLOGIC_URL = "t3://localhost:7001"; public static final String WEBLOGIC_USER="system"; public static final String WEBLOGIC_PASSWord = "12345678"; public static final String WEBLOGIC_JMSSERVER = "MessageCenterServer"; //JMS服务器的名字,可以看到我的config.xml<JMSServer
MBeanHome home = getMBeanHome(WEBLOGIC_URL,WEBLOGIC_USER,WEBLOGIC_PASSWORD); RemoteMBeanServer homeServer = null; QueryExp query = null; homeServer = home.getMBeanServer(); Set JMSMBeans = homeServer.queryNames(new ObjectName("mydomain:JMSServer="+WEBLOGIC_JMSSERVER+",Type=JMSQueue,*"),
query); //where "query" could be any object that implements the JMX //javax.managementQueryExp for (Iterator itr = JMSMBeans.iterator(); itr.hasNext(); ) { ObjectName mbean = (ObjectName)itr.next(); if(!mbean.getKeyProperty("Name").equals("CenterQueue")){ vect.addElement(mbean.getKeyProperty("Name")); } }
return vect; }
public static void main(String[] args) { JMSQueueMaintain JMSQueueMaintain1 = new JMSQueueMaintain(); try{ System.out.println(JMSQueueMaintain1.getQueuenames()); JMSQueueMaintain1.addQueue("queue0005"); JMSQueueMaintain1.deleteQueue("queue0003"); System.out.println(JMSQueueMaintain1.getQueuenames()); }catch(Exception e){