Rebus上是否有配置设置可以在总线启动或关闭时清除队列?我需要这样做的原因是,我有两个Rebus实例正在为我的集成测试运行,如果测试失败,我不希望在随后的测试运行中重试失败的消息。
以下是我为发送消息的集成测试客户端准备的内容。请注意,RebusHost只是被测试系统的包装:
using Rebus.Configuration;
using Rebus.Transports.Msmq;
namespace MT.Testing.Integration
{
[TestClass]
public class IntegrationTestFixture
{
private static IMtHost _host;
[AssemblyInitialize]
public static void IntegrationTestInitialize(TestContext testContext)
{
_host = new RebusHost();
_host.Start();
}
[AssemblyCleanup]
public static void IntegrationTestCleanup()
{
_host.Stop();
}
public static IBus GetClientBus(IContainerAdapter containerAdapter)
{
return Configure.With(containerAdapter)
.Transport(t => t.UseMsmq("mt.testing.integration.client.input", "mt.testing.integration.client.error"))
.MessageOwnership(d => d.Use(new IntegrationMessageOwnership()))
.Subscriptions(s => s.StoreInMemory())
.Sagas(s => s.StoreInMemory())
.CreateBus().Start();
}
}
public class IntegrationMessageOwnership : IDetermineMessageOwnership
{
public string GetEndpointFor(Type messageType)
{
return "mt.testing.integration.input";
}
}
}
Rebus没有"官方"API来执行此操作,但您可以执行我在大多数Rebus的MSMQ集成测试中所做的操作:使用Rebus的MsmqUtil
的有用静态方法,例如:MsmqUtil.PurgeQueue("mt.testing.integration.input")