protected override void Load(ContainerBuilder builder) { var handlerTypesProvider = new AssemblyScanningTypeProvider(typeof(BusModule).Assembly, typeof(PlaceOrderCommand).Assembly); builder.RegisterNimbus(handlerTypesProvider); builder.Register(componentContext => new BusBuilder() .Configure() // .WithTransport( // new AzureServiceBusTransportConfiguration().WithConnectionString("") // ) .WithTransport( new AzureServiceBusTransportConfiguration().WithConnectionString(Environment.GetEnvironmentVariable("AZURE_SERVICE_BUS_CONNECTIONSTRING")) ) .WithNames("Cashier", Environment.MachineName) .WithTypesFrom(handlerTypesProvider) .WithAutofacDefaults(componentContext) .WithSerilogLogger() .WithJsonSerializer() // .WithGlobalInboundInterceptorTypes(typeof(CorrelationIdInterceptor)) .Build()) .As <IBus>() .AutoActivate() .OnActivated(c => c.Instance.Start()) .OnRelease(bus => { bus.Stop().Wait(); bus.Dispose(); }) .SingleInstance(); }
private static void SetUpBus(IWindsorContainer 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.Register(Component.For <ILogger>().ImplementedBy <SerilogStaticLogger>().LifestyleSingleton()); // This is how you tell Nimbus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); container.RegisterNimbus(typeProvider); container.Register(Component.For <IBus>().ImplementedBy <Bus>() .UsingFactoryMethod <IBus>(() => new BusBuilder() .Configure() .WithConnectionString(connectionString) .WithNames("PingPong.Windsor", Environment.MachineName) .WithTypesFrom(typeProvider) .WithWindsorDefaults(container) .WithJsonSerializer() .WithDeflateCompressor() .Build()) .LifestyleSingleton() ); Bus bus = (Bus)container.Resolve <IBus>(); bus.Start().Wait(); }
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); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); var handlerTypesProvider = new AssemblyScanningTypeProvider(AppDomainScanner.AppDomainScanner.MyAssemblies); builder.RegisterNimbus(handlerTypesProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithTransport(new RedisTransportConfiguration() .WithConnectionString(componentContext.Resolve <BusConnectionString>()) ) .WithNames(componentContext.Resolve <ApplicationName>(), Environment.MachineName) .WithTypesFrom(handlerTypesProvider) .WithAutofacDefaults(componentContext) .WithSerilogLogger() .WithJsonSerializer() .WithGlobalPrefix(componentContext.Resolve <BusGlobalPrefix>()) .WithGlobalInboundInterceptorTypes(typeof(CorrelationIdInterceptor)) .Build()) .As <IBus>() .AutoActivate() .OnActivated(c => c.Instance.Start()) .OnRelease(bus => { bus.Stop().Wait(); bus.Dispose(); }) .SingleInstance(); }
protected override async Task <Bus> Given() { _largeMessageBodyTempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Guid.NewGuid().ToString()); _fakeHandler = new FakeHandler(NumMessagesToSend); _dependencyResolver = new FakeDependencyResolver(_fakeHandler); _timeout = TimeSpan.FromSeconds(300); //FIXME set to 30 seconds _typeProvider = new TestHarnessTypeProvider(new[] { GetType().Assembly }, new[] { GetType().Namespace }); _logger = TestHarnessLoggerFactory.Create(); //_logger = new NullLogger(); var largeMessageBodyStorage = new FileSystemStorageBuilder().Configure() .WithStorageDirectory(_largeMessageBodyTempPath) .WithLogger(_logger) .Build(); var bus = new BusBuilder().Configure() .WithNames("ThroughputTestSuite", Environment.MachineName) .WithLogger(_logger) .WithConnectionString(CommonResources.ServiceBusConnectionString) .WithTypesFrom(_typeProvider) .WithDependencyResolver(_dependencyResolver) .WithLargeMessageStorage(c => c.WithLargeMessageBodyStore(largeMessageBodyStorage) .WithMaxSmallMessageSize(4096)) .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(); return(bus); }
private static IContainer CreateContainer() { var builder = new ContainerBuilder(); builder.RegisterType <DeepThought>(); builder.RegisterType <SerilogStaticLogger>() .As <ILogger>() .SingleInstance(); //TODO: Set up your own connection string in app.config var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"]; var handlerTypesProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); builder.RegisterNimbus(handlerTypesProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithConnectionString(connectionString) .WithNames("MyApp", Environment.MachineName) .WithTypesFrom(handlerTypesProvider) .WithAutofacDefaults(componentContext) .Build()) .As <IBus>() .AutoActivate() .OnActivated(c => c.Instance.Start()) .SingleInstance(); var container = builder.Build(); return(container); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); 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. builder.RegisterType <ConsoleLogger>() .AsImplementedInterfaces() .SingleInstance(); // This is how you tell Nimbus where to find all your message types and handlers. var pizzaOrderingMessagesAssembly = typeof(HowLongDoPizzasTakeRequest).Assembly; var pizzaMakerMessagesAssembly = typeof(PizzaIsReady).Assembly; var nimbusAssembly = typeof(Bus).Assembly; // for stock interceptors var handlerTypesProvider = new AssemblyScanningTypeProvider(ThisAssembly, pizzaOrderingMessagesAssembly, pizzaMakerMessagesAssembly, nimbusAssembly); builder.RegisterNimbus(handlerTypesProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithConnectionString(connectionString) .WithNames("MyApp", Environment.MachineName).WithTypesFrom(handlerTypesProvider) .WithAutofacDefaults(componentContext) .Build()) .As <IBus>() .AutoActivate() .OnActivated(c => c.Instance.Start()) .SingleInstance(); }
protected override void Load(ContainerBuilder builder) { base.Load(builder); //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. builder.RegisterType <SerilogStaticLogger>() .AsImplementedInterfaces() .SingleInstance(); // This is how you tell Nimbus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly(), typeof(OrderPizzaCommand).Assembly, typeof(NewOrderRecieved).Assembly); builder.RegisterNimbus(typeProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithTransport(new WindowsServiceBusTransportConfiguration() .WithConnectionString(connectionString) ) .WithNames("Pizza.Maker", Environment.MachineName) .WithTypesFrom(typeProvider) .WithAutofacDefaults(componentContext) .Build()) .As <IBus>() .AutoActivate() .OnActivated(c => c.Instance.Start().Wait()) .SingleInstance(); }
public void TheMessageShouldMentionTheOffendingTypeByName() { var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(typeof(UnserializableCommandWhoseAssemblyShouldNotBeIncluded).Assembly); var validationErrors = assemblyScanningTypeProvider.Validate().ToArray(); validationErrors.ShouldContain(e => e.Contains(typeof(UnserializableCommandWhoseAssemblyShouldNotBeIncluded).FullName)); }
public async Task NothingShouldGoBang() { var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly); using (var container = new WindsorContainer()) { container.RegisterNimbus(typeProvider); } }
public void DoFoo() { var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); var bus = new BusBuilder().Configure() .WithConnectionString("foo") .WithNames("MyApp", Environment.MachineName) .WithTypesFrom(typeProvider) .Build(); }
public async Task NothingShouldGoBang() { var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly); var builder = new ContainerBuilder(); builder.RegisterNimbus(typeProvider); using (builder.Build()) { } }
public static async Task Startup() { var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var typeProvider = new AssemblyScanningTypeProvider(Assembly.Load("CloudService1.Public")); bus = new BusBuilder() .Configure() .WithNames("EchoMessageHandler", Environment.MachineName) .WithConnectionString(connectionString) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .Build(); await bus.Start(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { // Create the Nimbus type provider to scan all the application's assemblies and register appropriate classes with the container var appAssembly = typeof(NimbusWindsorInstaller).Assembly; var typeProvider = new AssemblyScanningTypeProvider(appAssembly.GetReferencedApplicationAssemblies().ToArray()); container.RegisterNimbus(typeProvider); // Register the bus itself and its logger container.Register( Component.For <ILogger>().ImplementedBy <SerilogStaticLogger>().LifestyleSingleton(), Component.For <IBus, Bus>().UsingFactoryMethod(() => CreateBus(container, typeProvider)).LifestyleSingleton() ); }
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; } } }
private static IBus SetupBus(string connectionString) { var transport = new RedisTransportConfiguration().WithConnectionString(connectionString); var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); var bus = new BusBuilder().Configure() .WithNames("SendAndHandleMessagesApp", Environment.MachineName) .WithTransport(transport) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(1000)) .WithSerilogLogger() .WithJsonSerializer() .Build(); bus.Start(); return(bus); }
public void NothingShouldGoBang() { using (var container = new StandardKernel()) { var typeProvider = new AssemblyScanningTypeProvider(); container.Bind <ILogger>().To <ConsoleLogger>().InSingletonScope(); container.RegisterNimbus(typeProvider); var largeMessageBodyTempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Guid.NewGuid().ToString()); container.Bind <ILargeMessageBodyStore>() .ToMethod( c => new FileSystemStorageBuilder().Configure() .WithStorageDirectory(largeMessageBodyTempPath) .WithLogger(c.Kernel.Get <ILogger>()) .Build()) .InSingletonScope(); container.Bind <IBus>() .ToMethod( c => new BusBuilder().Configure() .WithNames("IntegrationTestHarness", Environment.MachineName) .WithConnectionString( @"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=") .WithLargeMessageStorage( sc => sc.WithLargeMessageBodyStore(c.Kernel.Get <ILargeMessageBodyStore>()) .WithMaxSmallMessageSize(50 * 1024) .WithMaxLargeMessageSize(1024 * 1024)) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(c.Kernel.Get <ILogger>()) .Build()) .InSingletonScope(); container.Get <IBus>(); } }
public void NothingShouldGoBang() { using (var container = new WindsorContainer()) { var typeProvider = new AssemblyScanningTypeProvider(); container.Register(Component.For <ILogger>() .ImplementedBy <ConsoleLogger>() .LifestyleSingleton()); container.RegisterNimbus(typeProvider); container.Register(Component.For <ILargeMessageBodyStore>() .UsingFactoryMethod(c => new BlobStorageBuilder() .Configure() .UsingStorageAccountConnectionString(CommonResources.BlobStorageConnectionString) .WithLogger(c.Resolve <ILogger>()) .Build()) .LifestyleSingleton()); container.Register(Component.For <IBus>() .UsingFactoryMethod(c => new BusBuilder().Configure() .WithNames("IntegrationTestHarness", Environment.MachineName) .WithConnectionString( @"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=") .WithLargeMessageStorage( sc => sc.WithLargeMessageBodyStore(c.Resolve <ILargeMessageBodyStore>()) .WithMaxSmallMessageSize(50 * 1024) .WithMaxLargeMessageSize(1024 * 1024)) .WithTypesFrom(typeProvider) .WithDefaultTimeout(TimeSpan.FromSeconds(10)) .WithLogger(c.Resolve <ILogger>()) .Build()) .LifestyleSingleton()); container.Resolve <IBus>(); } }
public void ValidationShouldFail() { var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(typeof(UnserializableCommandWhoseAssemblyShouldNotBeIncluded).Assembly); assemblyScanningTypeProvider.Validate().ShouldNotBeEmpty(); }
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(); } }
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(); } }
public void ValidationShouldFail() { var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(Assembly.GetAssembly(typeof(DuplicateMessageType))); assemblyScanningTypeProvider.Validate().ShouldNotBeEmpty(); }