在执行测试之前/之后如何清洁HornetQ消息日志? [英] How to clean HornetQ messaging journal before/after performing a test?

查看:123
本文介绍了在执行测试之前/之后如何清洁HornetQ消息日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 JMS HornetQ 对持久消息进行了 Arquillian 集成测试.某些测试使消息日志中充满未处理的消息,从而破坏了其他预期没有数据的测试.

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.

是否可以在执行测试之前或之后告诉 JMS 清除其消息日志?

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

推荐答案

JMS API本身不存在此方法,但是HornetQ QueueControl管理对象中有一个方法"removeMessages(filter)".可以在用于队列的JMX Bean中找到此方法,但是我不知道如何在Arquillian中获得该方法.

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.

幸运的是,您可以通过"hornetq.management"队列调用管理操作.请参阅 http://docs.jboss. org/hornetq/2.2.5.Final/user-manual/en/html/management.html .实际上,以下方法应该起作用:

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

这篇关于在执行测试之前/之后如何清洁HornetQ消息日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆