Deleting all messages in JMS queue in Widlfy 9
Asked Answered
A

0

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?

Argyres answered 16/8, 2016 at 12:0 Comment(2)
update: If I remove consumer, it works properly; if queue paused first, it doesn't help ...Argyres
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 eitherArgyres

© 2022 - 2024 — McMap. All rights reserved.