在集群环境中通过JMX访问JMSQueue

在集群环境中通过JMX访问JMSQueue,jms,cluster-computing,weblogic-10.x,mbeans,Jms,Cluster Computing,Weblogic 10.x,Mbeans,配置:WLS集群(10.3),具有两个节点#1和#2。一个可迁移的JMSServer当前在#1上可用。一个可迁移的JMSQueue 问题: 一些EJB正在用一条TimeToDeliver设置为60秒的消息填充JSMQUE。(60秒内不可见)另一个EJB将使用JMX在消息可见之前获取该消息(不可见)。如果另一个EJB在#2上执行,它将找不到JMSServer,因此不会弹出消息。该代码在非集群环境下运行良好: public class PurgeWLSQueue { p

配置:WLS集群(10.3),具有两个节点#1和#2。一个可迁移的JMSServer当前在#1上可用。一个可迁移的JMSQueue

问题: 一些EJB正在用一条TimeToDeliver设置为60秒的消息填充JSMQUE。(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吗?还有其他想法吗?

啊,解决了
对于其他面临相同问题的用户,请改用域运行时服务:

ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
并确保访问WLS群集上的管理端口。

啊,解决了
对于其他面临相同问题的用户,请改用域运行时服务:

ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
并确保访问WLS群集上的管理端口