2

配置:具有两个节点 #1 和 #2 的 WLS 集群 (10.3)。一个可迁移的 JMSServer 目前在 #1 上可用。一个可迁移的 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();
            }
        }
    }

(这个代码是从这个论坛上的 Miklos Csuka 借来的)

在不指定 JMSServer 的情况下是否有其他方法可以获取该消息,即我可以直接寻址 JMSQueue 吗?还有其他想法吗?

4

1 回答 1

0

Ah, solved it!
For others facing the same problem, use the domain runtime service instead:

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

and be sure to access the admin port on the WLS-cluster.

于 2011-10-07T07:53:35.567 回答