简体   繁体   English

在 JBoss EAP 中以编程方式暂停 ActiveMQ Artemis 队列

[英]Pause an ActiveMQ Artemis Queue Programmatically in JBoss EAP

We're using JBoss EAP 7.3 with embedded ActiveMQ Artemis message broker.我们使用带有嵌入式 ActiveMQ Artemis 消息代理的 JBoss EAP 7.3。 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 .我发现的唯一完整示例是在 Stack Overflow 上的这个问题中。

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 ).它在运行 ActiveMQ Artemis 代理的同一个 JBoss 实例中运行。我确实更改了代码以查找我的队列名称 ( 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.不幸的是我根本不知道 JMX。 I wrote this code to get a list off all object names thinking maybe JBoss somehow changed the embedded ActiveMQ Artemis' default name:我写这段代码是为了获得所有 object 名称的列表,我想也许 JBoss 以某种方式改变了嵌入式 ActiveMQ Artemis 的默认名称:

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.我没有看到任何带有artemis的名字。 I do see some names with activemq in it but they look like the JBoss configuration of the queues / addresses.我确实看到了一些带有activemq的名称,但它们看起来像队列/地址的 JBoss 配置。

Any idea what I might be doing wrong here?知道我在这里做错了什么吗?

I figured it out.我想到了。 I used JConsole to look at all the MBeans and their associated operations.我使用 JConsole 查看所有 MBean 及其相关操作。 I found one that references myQueue (although not jms.queue.myQueue ) and it had the "pause" operation.我找到了一个引用myQueue (虽然不是jms.queue.myQueue )并且它有“暂停”操作。 I changed that first line in the code to use that object name and it works.我更改了代码中的第一行以使用 object 名称并且它有效。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM