2011-10-06 51 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-羣集上管理端口。