public async Task<Bus> CreateAndStart() { var logger = new ConsoleLogger(); //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)) .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() .WithDefaults(typeProvider) .WithTransport(new WindowsServiceBusTransportConfiguration() .WithConnectionString( @"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=") ) .WithNames("IntegrationTestHarness", Environment.MachineName) .WithDefaultTimeout(TimeSpan.FromSeconds(TimeoutSeconds)) .WithLogger(logger) .Build(); try { await bus.Start(); Assert.Fail(); } catch (Exception e) { e.ShouldBeTypeOf<BusException>(); } }
private static Bus CreateBus(IWindsorContainer container, ITypeProvider typeProvider) { var configRetriever = container.Resolve<IGetEnvironmentConfiguration>(); try { // Get the Azure Service Bus connection string, app name, and unique name for this running instance string connectionString = configRetriever.GetSetting(AzureServiceBusConnectionStringKey); string appName = configRetriever.AppName; string uniqueName = configRetriever.UniqueInstanceId; Bus bus = new BusBuilder().Configure() .WithConnectionString(connectionString) .WithNames(appName, uniqueName) .WithJsonSerializer() .WithWindsorDefaults(container) .WithTypesFrom(typeProvider) .Build(); bus.Start(); return bus; } finally { container.Release(configRetriever); } }
public async Task TheStartupTimeShouldBeAcceptable() { const int numMessageTypes = 50; var assemblyBuilder = EmitMessageContractsAndHandlersAssembly(numMessageTypes); var logger = TestHarnessLoggerFactory.Create(Guid.NewGuid(), GetType().FullName); var typeProvider = new AssemblyScanningTypeProvider(assemblyBuilder); var firstBus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithDefaults(typeProvider) .WithTransport(new WindowsServiceBusTransportConfiguration() .WithConnectionString(DefaultSettingsReader.Get<AzureServiceBusConnectionString>())) .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(); try { try { await firstBus.Start(MessagePumpTypes.All); } catch (AggregateException exc) { throw exc.Flatten(); } } finally { firstBus.Dispose(); } var subsequentBus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithTransport(new WindowsServiceBusTransportConfiguration() .WithConnectionString(DefaultSettingsReader.Get<AzureServiceBusConnectionString>())) .WithDefaults(typeProvider) .WithLogger(logger) .Build(); try { try { await subsequentBus.Start(MessagePumpTypes.All); } catch (AggregateException exc) { throw exc.Flatten(); } } finally { subsequentBus.Dispose(); } }
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 Nimbus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); var bus = new BusBuilder().Configure() .WithTransport(new WindowsServiceBusTransportConfiguration() .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 static void Main(string[] args) { // This is how you tell Nimbus 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(); bus.Start(); 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": HowLongDoesAPizzaTake(bus); break; case "2": Console.WriteLine("What's the customer's name?"); var customerName = Console.ReadLine().Trim(); if (string.IsNullOrWhiteSpace(customerName)) { Console.WriteLine("You need to enter a customer name."); continue; } var command = new OrderPizzaCommand {CustomerName = customerName}; bus.Send(command); Console.WriteLine("Pizza ordered for {0}", customerName); break; case "3": bus.Stop(); return; default: continue; } } }
public async Task ItShouldGoBangQuickly() { var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace}); var logger = new ConsoleLogger(); 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 Nimbus 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() .WithTransport(new WindowsServiceBusTransportConfiguration() .WithConnectionString(connectionString) ) .WithNames("Ordering", Environment.MachineName) .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; } } }
public static Bus CreateAndStart(ITypeProvider typeProvider, DefaultMessageHandlerFactory messageHandlerFactory) { var logger = new ConsoleLogger(); var bus = new BusBuilder().Configure() .WithNames("MyTestSuite", Environment.MachineName) .WithConnectionString(CommonResources.ConnectionString) .WithTypesFrom(typeProvider) .WithDefaultHandlerFactory(messageHandlerFactory) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .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(); bus.Start(); return bus; }
static void Main(string[] args) { // This is how you tell Nimbus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly(), typeof(NewOrderRecieved).Assembly, typeof(OrderPizzaCommand).Assembly); var messageBroker = new DefaultMessageBroker(typeProvider); var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"]; var bus = new BusBuilder().Configure() .WithNames("Ordering", Environment.MachineName) .WithConnectionString(connectionString) .WithTypesFrom(typeProvider) .WithCommandBroker(messageBroker) .WithRequestBroker(messageBroker) .WithMulticastEventBroker(messageBroker) .WithCompetingEventBroker(messageBroker) .WithMulticastRequestBroker(messageBroker) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .Build(); bus.Start(); Console.WriteLine("Press 1 to get the current wait time."); Console.WriteLine("Press 2 to order a pizza."); Console.WriteLine("Press 3 to Quit."); int nextPizzaId = 1; while (true) { var input = Console.ReadLine(); switch (input) { case "1": #pragma warning disable 4014 FindOutHowLongItWillBe(bus); #pragma warning restore 4014 break; case "2": var command = new OrderPizzaCommand {PizzaId = nextPizzaId}; #pragma warning disable 4014 bus.Send(command); #pragma warning restore 4014 Console.WriteLine("Pizza number {0} ordered", nextPizzaId); nextPizzaId++; break; case "3": bus.Stop(); return; default: continue; } } }
private Task<Bus> BuildMeABus() { return Task.Run(() => { // 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 messageBroker = new DefaultMessageHandlerFactory(typeProvider); var logger = new ConsoleLogger(); var bus = new BusBuilder().Configure() .WithNames("IntegrationTestHarness", Environment.MachineName) .WithConnectionString(CommonResources.ConnectionString) .WithTypesFrom(typeProvider) .WithCommandHandlerFactory(messageBroker) .WithRequestHandlerFactory(messageBroker) .WithMulticastEventHandlerFactory(messageBroker) .WithCompetingEventHandlerFactory(messageBroker) .WithMulticastRequestHandlerFactory(messageBroker) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(logger) .Build(); bus.ShouldNotBe(null); bus.Start(); return bus; }); }
public async Task TheStartupTimeShouldBeAcceptable() { const int numMessageTypes = 100; var assemblyBuilder = EmitMessageContractsAndHandlersAssembly(numMessageTypes); var logger = new ConsoleLogger(); 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(); } }