1

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?

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Todd Johnson
  • 147
  • 1
  • 11
  • Since you're using ActiveMQ Artemis embedded within JBoss EAP you're going to need to use the JBoss EAP MBeans instead of the ActiveMQ Artemis MBeans. JBoss EAP disables the ActiveMQ Artemis MBeans by default and exposes their own. They do this so they can provide consistent experience between all their different management interfaces (e.g. JMX, CLI, HTTP, etc.). – Justin Bertram Feb 25 '22 at 19:52
  • FWIW, I didn't provide the answer on [the question you cited](https://stackoverflow.com/questions/70986213/any-example-of-pausing-and-resuming-jms-messages-using-jmsqueuecontrol). The answer came from [SMA](https://stackoverflow.com/users/7064617/sma). I just edited the answer for readability. – Justin Bertram Feb 25 '22 at 19:53
  • 1
    Sorry Justin... you've been so helpful with my Artemis / JMS questions when I saw your name on that original question I assumed you had answered it. Yes, I see now you edited it. I've edited my question to remove that statement. Thanks again! I've got it working now and answered my own question which will hopefully help the next poor soul. – Todd Johnson Feb 25 '22 at 19:58
  • I'm glad to help! – Justin Bertram Feb 25 '22 at 20:00

1 Answers1

2

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();
Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
Todd Johnson
  • 147
  • 1
  • 11
  • If this is the correct answer please mark it as such in order to help other users who have this same question in the future. Thanks! – Justin Bertram Mar 07 '22 at 18:04