queueactivemq-artemispausejboss-eap-7

Pause an ActiveMQ Artemis Queue Programmatically in JBoss EAP


We're using JBoss EAP 7.3 with embedded ActiveMQ Artemis message broker. I have a use case where I need to programmatically pause a queue. The only complete example I found was here on Stack Overflow in this question.

His solution is the code shown below:

String eapObjectName = "org.apache.activemq.artemis:broker=\"default\",component=addresses,address=\"jms.queue.exampleQueue\",subcomponent=queues,routing-type=\"anycast\",queue=\"jms.queue.exampleQueue\"";
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = ObjectName.getInstance(eapObjectName);
QueueControl queueControl = MBeanServerInvocationHandler.newProxyInstance(mBeanServer,objectName,QueueControl.class,false)

queueControl.pause();

I tried to implement this solution. It is running in the same JBoss instance that the ActiveMQ Artemis broker is running in. I did change the code to look for my queue name (jms.queue.myQueue). I'm getting this exception below:

javax.management.InstanceNotFoundException: org.apache.activemq.artemis:broker="default",component=addresses,address="jms.queue.myQueue",subcomponent=queues,routing-type="anycast",queue="jms.queue.myQueue"

Unfortunately I don't know JMX at all. I wrote this code to get a list off all object names thinking maybe JBoss somehow changed the embedded ActiveMQ Artemis' default name:

Set mbeans = mBeanServer.queryNames(null, null);
for (Object mbean : mbeans)
{
    ObjectName objName = (ObjectName)mbean;
    logger.info(objName);
}

I'm not seeing any name with artemis in it. I do see some names with activemq in it but they look like the JBoss configuration of the queues / addresses.

Any idea what I might be doing wrong here?


Solution

  • I figured it out. I used JConsole to look at all the MBeans and their associated operations. I found one that references myQueue (although not jms.queue.myQueue) and it had the "pause" operation. I changed that first line in the code to use that object name and it works.

    String eapObjectName = "jboss.as:subsystem=\"messaging-activemq\",server=\"default\",jms-queue=\"myQueue\"";
    
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = ObjectName.getInstance(eapObjectName);
    QueueControl queueControl = MBeanServerInvocationHandler.newProxyInstance(mBeanServer,objectName,QueueControl.class,false)
    
    queueControl.pause();