如何在 Activemq 中暂停队列
How to pause a queue in Activemq
我需要在应用程序内暂停 Activemq 5.13.2 中的队列,根据此 post 版本 5.12 是可能的,但我不知道如何实现它。任何 Java 代码示例都很棒。
@Test
public void testPauseQueue() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName queue = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq");
QueueViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(conn, queue,QueueViewMBean.class, true);
System.out.println(mbean.isPaused());
}
异常
at za.co.fnb.cii.relandheir.batch.inputprocessor.service.MessengerServiceTest.testPauseQueue(MessengerServiceTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:50)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: javax.management.InstanceNotFoundException: org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq
您可以使用表示要暂停的队列的 MBean 来执行此操作。因此,使用 JConsole 您将连接到代理,找到相关队列的 MBean 并对该队列执行 'pause' 操作,然后当您准备好再次让该队列开始发送消息时,您将执行'resume' 操作。
名字好像变了
ObjectName queue = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq");
到
ObjectName queue = new ObjectName("org.apache.activemq:brokerName=localhost,destinationName=testq,destinationType=Queue,type=Broker");
修改后完美运行
我发现了 REST 管理的新名称格式 API http://activemq.apache.org/rest.html
http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost
如果使用 OpenEJB/TomEE,您可以使用 JConsole:
找到 MBean ObjectName 名称
我需要在应用程序内暂停 Activemq 5.13.2 中的队列,根据此 post 版本 5.12 是可能的,但我不知道如何实现它。任何 Java 代码示例都很棒。
@Test
public void testPauseQueue() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection conn = jmxc.getMBeanServerConnection();
ObjectName queue = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq");
QueueViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(conn, queue,QueueViewMBean.class, true);
System.out.println(mbean.isPaused());
}
异常
at za.co.fnb.cii.relandheir.batch.inputprocessor.service.MessengerServiceTest.testPauseQueue(MessengerServiceTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:50)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: javax.management.InstanceNotFoundException: org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq
您可以使用表示要暂停的队列的 MBean 来执行此操作。因此,使用 JConsole 您将连接到代理,找到相关队列的 MBean 并对该队列执行 'pause' 操作,然后当您准备好再次让该队列开始发送消息时,您将执行'resume' 操作。
名字好像变了
ObjectName queue = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=testq");
到
ObjectName queue = new ObjectName("org.apache.activemq:brokerName=localhost,destinationName=testq,destinationType=Queue,type=Broker");
修改后完美运行
我发现了 REST 管理的新名称格式 API http://activemq.apache.org/rest.html
http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost
如果使用 OpenEJB/TomEE,您可以使用 JConsole:
找到 MBean ObjectName 名称