public async Task<Bus> CreateAndStart() { var logger = TestHarnessLoggerFactory.Create(); //var logger = new NullLogger(); // Filter types we care about to only our own test's namespace. It's a performance optimisation because creating and // deleting queues and topics is slow. var typeProvider = new TestHarnessTypeProvider(new[] {_testFixtureType.Assembly}, new[] {_testFixtureType.Namespace}); var bus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithConnectionString(CommonResources.ServiceBusConnectionString) .WithTypesFrom(typeProvider) .WithGlobalInboundInterceptorTypes(typeProvider.InterceptorTypes.Where(t => typeof (IInboundInterceptor).IsAssignableFrom(t)).ToArray()) .WithGlobalOutboundInterceptorTypes(typeProvider.InterceptorTypes.Where(t => typeof (IOutboundInterceptor).IsAssignableFrom(t)).ToArray()) .WithDependencyResolver(new DependencyResolver(typeProvider)) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithHeartbeatInterval(TimeSpan.MaxValue) .WithLogger(logger) .WithDebugOptions( dc => dc.RemoveAllExistingNamespaceElementsOnStartup( "I understand this will delete EVERYTHING in my namespace. I promise to only use this for test suites.")) .Build(); await bus.Start(MessagePumpTypes.All); return bus; }
public async Task ItShouldGoBangQuickly() { var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace}); var logger = TestHarnessLoggerFactory.Create(); var bus = new BusBuilder().Configure() .WithNames("IntegrationTestHarness", Environment.MachineName) .WithConnectionString(@"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=") .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(logger) .Build(); await bus.Start(); }
public static async Task MainAsync() { // This is how you tell Cumulus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly(), typeof (NewOrderRecieved).Assembly, typeof (OrderPizzaCommand).Assembly); var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"]; var bus = new BusBuilder().Configure() .WithNames("Ordering", Environment.MachineName) .WithConnectionString(connectionString) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .Build(); await bus.Start(MessagePumpTypes.Response); while (true) { Console.WriteLine(); Console.WriteLine("Press 1 to get the current wait time."); Console.WriteLine("Press 2 to order a pizza."); Console.WriteLine("Press 3 to Quit."); var input = Console.ReadLine(); switch (input) { case "1": await HowLongDoesAPizzaTake(bus); break; case "2": await OrderAPizza(bus); break; case "3": await bus.Stop(); return; default: continue; } } }
private static void SetUpBus(IUnityContainer container) { //TODO: Set up your own connection string in app.config var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"]; // You'll want a logger. There's a ConsoleLogger and a NullLogger if you really don't care. You can roll your // own by implementing the ILogger interface if you want to hook it to an existing logging implementation. container.RegisterType<ILogger, ConsoleLogger>(); // This is how you tell Cumulus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); var bus = new BusBuilder().Configure() .WithConnectionString(connectionString) .WithNames("PingPong.Unity", Environment.MachineName) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(5)) .WithUnityDependencyResolver(typeProvider, container) .Build(); bus.Start().Wait(); container.RegisterInstance<IBus>(bus); }
private Task<Bus> BuildMeABus() { return Task.Run(async () => { // Filter types we care about to only our own test's namespace. It's a performance optimisation because creating and // deleting queues and topics is slow. var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace}); var logger = TestHarnessLoggerFactory.Create(); var bus = new BusBuilder().Configure() .WithNames("IntegrationTestHarness", Environment.MachineName) .WithConnectionString(CommonResources.ServiceBusConnectionString) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(logger) .Build(); bus.ShouldNotBe(null); await bus.Start(); return bus; }); }
public async Task TheStartupTimeShouldBeAcceptable() { const int numMessageTypes = 100; var assemblyBuilder = EmitMessageContractsAndHandlersAssembly(numMessageTypes); var logger = TestHarnessLoggerFactory.Create(); var typeProvider = new AssemblyScanningTypeProvider(new[] {assemblyBuilder}); var firstBus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithConnectionString(CommonResources.ServiceBusConnectionString) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithServerConnectionCount(100) .WithLogger(logger) .Build(); try { using (new AssertingStopwatch("First bus startup", TimeSpan.FromMinutes(1))) { { try { await firstBus.Start(MessagePumpTypes.All); WriteBlankLines(); } catch (AggregateException exc) { throw exc.Flatten(); } } } } finally { WriteBlankLines(); firstBus.Dispose(); } WriteBlankLines(); var subsequentBus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithConnectionString(CommonResources.ServiceBusConnectionString) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(logger) .Build(); try { using (new AssertingStopwatch("Subsequent bus startup", TimeSpan.FromSeconds(20))) { try { await subsequentBus.Start(MessagePumpTypes.All); WriteBlankLines(); } catch (AggregateException exc) { throw exc.Flatten(); } } } finally { WriteBlankLines(); subsequentBus.Dispose(); } }