2016-04-13 3 views
1

Мне нужно приостановить очередь в Activemq 5.13.2 внутри приложения, и в соответствии с этим сообщением https://stackoverflow.com/a/32165140/1458556 это возможно с версией 5.12, но я не знаю, как ее реализовать. Любые примеры кода Java были бы замечательными.Как приостановить очередь в Activemq

@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$1.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$3.run(ParentRunner.java:231) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
    at org.junit.runners.ParentRunner$2.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 

ответ

1

Похоже имена изменились с

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

Затем работал отлично после изменения.

я обнаружил новый формат имен с API REST управления http://activemq.apache.org/rest.html

http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost

0

Вы можете сделать это с помощью MBean, который представляет Queue, что вы хотите сделать паузу. Таким образом, используя JConsole, вы должны подключиться к брокеру, найти MBean этой очереди и выполнить операцию «пауза» в этой очереди, а затем, когда вы будете готовы снова запустить эту очередь для отправки сообщения, вы должны выполнить «резюме» '.

+0

I хочу сделать это код, Java. –

+0

Я в настоящее время следую этому учебнику [link] https://dzone.com/articles/managing-activemq-jmx-apis, и я нашел Javadoc [link] http://activemq.apache.org/maven/apidocs/ org/apache/activemq/broker/jmx/QueueViewMBean.html Должен работать. –

0

При использовании OpenEJB/TomEE, вы можете найти имя MBean ObjectName с помощью JConsole:

JMX JConsole

Смежные вопросы