How to clean HornetQ messaging journal before/after performing a test?

不打扰是莪最后的温柔 提交于 2020-01-02 06:57:12

问题


There's an Arquillian integration test using JMS HornetQ with persisted messages. Some test leave the messaging journal filled with unhandled messages that break other tests expecting no data.

Is there a way of telling JMS to clean its messaging journal before or after executing a test?


回答1:


This does not exist in the JMS API itself, but there's a method 'removeMessages(filter)' in the HornetQ QueueControl management object. This method can be found in the JMX Bean for the Queue, but I wouldn't know how to get that in Arquillian.

Luckily, you can invoke management operations via the 'hornetq.management' queue. See http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/management.html. In practice, the following should work:

     Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
     QueueRequestor requestor = new QueueRequestor(session, managementQueue);
     Message m = session.createMessage();
     JMSManagementHelper.putOperationInvocation(m,
                                                "jms.queue.exampleQueue",
                                                "removeMessages","*");
     Message reply = requestor.request(m);
     boolean success = JMSManagementHelper.hasOperationSucceeded(reply);



回答2:


If you're restarting the server, you could remove the paging and data folders (while keeping the bindings).



来源:https://stackoverflow.com/questions/12509012/how-to-clean-hornetq-messaging-journal-before-after-performing-a-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!