private static void SetUpBus(ContainerBuilder 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 Cumulus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly(), typeof (OrderPizzaCommand).Assembly, typeof (NewOrderRecieved).Assembly); builder.RegisterCumulus(typeProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithConnectionString(connectionString) .WithNames("Maker", Environment.MachineName) .WithTypesFrom(typeProvider) .WithAutofacDefaults(componentContext) .WithQueueAndTopicCreation(false) .Build()) .As<IBus>() .AutoActivate() .OnActivated(async c => await c.Instance.Start()) .SingleInstance(); }
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.RegisterCumulus(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; }
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 Cumulus where to find all your message types and handlers. var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); container.RegisterCumulus(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(); }
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 Cumulus where to find all your message types and handlers. var pizzaOrderingMessagesAssembly = typeof (HowLongDoPizzasTakeRequest).Assembly; var pizzaMakerMessagesAssembly = typeof (PizzaIsReady).Assembly; var CumulusAssembly = typeof (Bus).Assembly; // for stock interceptors var handlerTypesProvider = new AssemblyScanningTypeProvider(ThisAssembly, pizzaOrderingMessagesAssembly, pizzaMakerMessagesAssembly, CumulusAssembly); builder.RegisterCumulus(handlerTypesProvider); builder.Register(componentContext => new BusBuilder() .Configure() .WithConnectionString(connectionString) .WithNames("MyApp", Environment.MachineName).WithTypesFrom(handlerTypesProvider) .WithAutofacDefaults(componentContext) .Build()) .As<IBus>() .AutoActivate() .OnActivated(async c => await c.Instance.Start()) .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.RegisterCumulus(typeProvider); } }
public async Task NothingShouldGoBang() { var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly); var builder = new ContainerBuilder(); builder.RegisterCumulus(typeProvider); using (builder.Build()) { } }
public void NothingShouldGoBang() { var typeProvider = new AssemblyScanningTypeProvider(); using (var container = new Container(c => Config(c, typeProvider))) { container.RegisterCumulus(typeProvider); container.GetInstance<IBus>(); } }
public void DoFoo() { var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly()); var bus = new BusBuilder().Configure() .WithConnectionString("foo") .WithNames("MyApp", Environment.MachineName) .WithTypesFrom(typeProvider) .Build(); }
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; } } }
public void NothingShouldGoBang() { using (var container = new StandardKernel()) { var typeProvider = new AssemblyScanningTypeProvider(); container.Bind<ILogger>().To<ConsoleLogger>().InSingletonScope(); container.RegisterCumulus(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.RegisterCumulus(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>(); } }
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); }
public void ValidationShouldFail() { var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(typeof (UnserializableCommandWhoseAssemblyShouldNotBeIncluded).Assembly); assemblyScanningTypeProvider.Validate().ShouldNotBeEmpty(); }
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(); } }