2011-10-06 47 views
2

配置:具有两个节点#1和#2的WLS群集(10.3)。一个可迁移的JMSServer目前在#1上可用。一个可迁移的JMSQueue。在群集环境中通过JMX访问JMSQueue

问题: 某些EJB正在使用timeToDeliever设置为60秒的消息填充JSMQueue。 (在60秒内不可见),另一个EJB将使用JMX在可见之前获取该消息(不可见)。如果这个其他EJB在#2上执行,它将无法找到JMSServer,因此不会弹出消息。代码工作在非群集环境优良:



    public class PurgeWLSQueue { 

     private static final String WLS_USERNAME = "weblogic"; 
     private static final String WLS_PASSWORD = "weblogic"; 
     private static final String WLS_HOST = "localhost"; 
     private static final int WLS_PORT = 7001; 
     private static final String JMS_SERVER = "wlsbJMSServer"; 
     private static final String JMS_DESTINATION = "test.q"; 

     private static JMXConnector getMBeanServerConnector(String jndiName) throws Exception { 
      Hashtable h = new Hashtable(); 
      JMXServiceURL serviceURL = new JMXServiceURL("t3", WLS_HOST, WLS_PORT, jndiName); 
      h.put(Context.SECURITY_PRINCIPAL, WLS_USERNAME); 
      h.put(Context.SECURITY_CREDENTIALS, WLS_PASSWORD); 
      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); 
      JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h); 
      return connector; 
     } 

     public static void main(String[] args) { 
      try { 
       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 (JMS_SERVER.equals(jmsServer.getKeyProperty("Name"))) { 
         ObjectName[] destinations = (ObjectName[]) mbeanServerConnection.getAttribute(jmsServer, "Destinations"); 
         for (ObjectName destination: destinations) { 
          if (destination.getKeyProperty("Name").endsWith("!"+JMS_DESTINATION)) { 
           Object o = mbeanServerConnection.invoke(
            destination, 
            "deleteMessages", 
            new Object[] {""},  // selector expression 
            new String[] {"java.lang.String"}); 
           System.out.println("Result: "+o); 
           break; 
          } 
         } 
         break; 
        } 
       } 
       connector.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

(此代码是从米克洛什Csuka借这个论坛)

是否有上获取任何其他方式,如果没有指定JMSServer,即消息可我直接解决JMSQueue?任何其他想法?

回答

0

啊,解决了!
对于其他人面临同样的问题,使用域运行时服务,而不是:

ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean"); 

,并确保访问WLS-群集上管理端口。