2010-03-17 189 views

Respuesta

5

Puede usar JMX para purgar la cola, ya sea desde Java o desde WLST (Python). Puede encontrar las definiciones de MBean para WLS 10.0 en http://download.oracle.com/docs/cd/E11035_01/wls100/wlsmbeanref/core/index.html. Aquí es un ejemplo básico de Java (no se olvide de poner weblogic.jar en el CLASSPATH):

import java.util.Hashtable; 
import javax.management.MBeanServerConnection; 
import javax.management.remote.JMXConnector; 
import javax.management.remote.JMXConnectorFactory; 
import javax.management.remote.JMXServiceURL; 
import javax.management.ObjectName; 
import javax.naming.Context; 
import weblogic.management.mbeanservers.runtime.RuntimeServiceMBean; 

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<String,String> h = new Hashtable<String,String>(); 
     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(); 
     } 
    } 
} 
3

funciona muy bien en un entorno de un solo nodo, pero lo que sucede si se encuentra en un entorno agrupado con UN migratable JMSServer (actualmente en el nodo n. ° 1) y este código se está ejecutando en el nodo n. ° 2. Entonces no habrá JMSServer disponible y no se eliminará ningún mensaje.

Este es el problema que estoy enfrentando en este momento ...

¿Hay una manera de conectar a la JMSQueue sin tener la JMSServer disponibles?

[editar]
encontrado una solución: Utilizar el servicio de tiempo de ejecución de dominio en lugar:

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

y asegúrese de tener acceso al puerto de administración en el WLS-cluster.

4

Aquí se muestra un ejemplo en WLST para un servidor administrado que se ejecuta en el puerto 7005:

connect('weblogic', 'weblogic', 't3://localhost:7005') 
serverRuntime() 

cd('/JMSRuntime/ManagedSrv1.jms/JMSServers/MyAppJMSServer/Destinations/MyAppJMSModule!QueueNameToClear') 

cmo.deleteMessages('') 

El último comando debe devolver el número de mensajes que se borre.

+0

he intentado esto, pero tiene esta excepción: 'java.lang.UnsupportedOperationException: DeleteMessages (String) no es válido para la clase weblogic.jms.backend.BEDestinationRuntimeMBeanImpl' a pesar de que' ls() '' incluye -rx DeleteMessages entero: Cuerda (selector) 'en la información que devuelve. – pharsicle

+0

¡Solucionado por mí mismo! Mi situación tiene un tema con suscriptores duraderos. Necesitaba cd al MBean para el suscriptor y llamar a 'deleteMessages ('')' en él. – pharsicle

0

si se trata de una sola vez, lo más fácil sería hacerlo a través de la consola ...

Cuestiones relacionadas