3

I am trying to remove messages from JMS queue on Wildfly 9.0.2 (JBoss) using JMX, see following code:

    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    try {
        String name = "jboss.as.expr:subsystem=messaging,hornetq-server=default,jms-queue=MyQueue";
        ObjectName objectName = new ObjectName(objectNameString);
        String result = (String) server.invoke(objectName, "removeMessages", new Object[]{null},
                new String[]{"java.lang.String"});
        return result;
    } catch (MalformedObjectNameException | InstanceNotFoundException | MBeanException | ReflectionException ignored) {
        log.errorv(ignored, "Error removing messages from JMS queue [{0}]", name);
        return null;
    }

There is an active consumer on that queue. The code runs without exception and returns string "0", but no messages are actually removed. I tried also to use some value as message filter (*), but got failure:

    javax.management.ReflectionException: "HQ119020: Invalid filter: *"

Any idea how to remove the messages?

dedek
  • 7,981
  • 3
  • 38
  • 68
miran
  • 1,419
  • 1
  • 12
  • 26
  • update: If I remove consumer, it works properly; if queue paused first, it doesn't help ... – miran Aug 16 '16 at 13:02
  • update 2: it looked that pausing the queue (jmx operation "pause") and waiting for currently being processed messages to finish will allow to remove remaining messages, but that didn't work either – miran Aug 17 '16 at 13:10

0 Answers0