Reputation: 3388
Is there a configuration setting on Rebus to clear out the queues on bus startup or shutdown? The reason I need to do this is I have two instances of Rebus running for my integration test, and if a test fails I don't want the failed message to get retried in the subsequent test run.
Here is what I have for the integration test client that sends the messages. Note that RebusHost is just a wrapper around the system under test:
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";
}
}
}
Upvotes: 2
Views: 579
Reputation: 18628
Rebus does not have an "official" API that does this, but you can do what I do in most of Rebus' MSMQ integrations tests: Use the helpful static methods of Rebus' MsmqUtil
- e.g. like this: MsmqUtil.PurgeQueue("mt.testing.integration.input")
Upvotes: 2