Inheritance: ITypeProvider, IValidatableConfigurationSetting
Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            var serviceBusConnectionString = ConfigurationManager.ConnectionStrings["ServiceBus"].ConnectionString;
            var builder = new ContainerBuilder();
            var typeProvider = new AssemblyScanningTypeProvider(
                   Assembly.GetAssembly(typeof(ExampleEventHandler)),
                   Assembly.GetAssembly(typeof(ExampleCommand))
                   );

            var applicationName = Assembly.GetExecutingAssembly().ToNimbusName();
            var instanceName = Environment.MachineName;

            builder.RegisterNimbus(typeProvider);
            builder.RegisterType<NimbusLogger>().As<ILogger>();
            builder.Register(componetContext => new BusBuilder()
                .Configure()
                .WithConnectionString(serviceBusConnectionString)
                .WithNames(applicationName, instanceName)
                .WithTypesFrom(typeProvider)
                .WithDefaultTimeout(TimeSpan.FromSeconds(30))
                .WithAutofacDefaults(componetContext)
                .Build())
                .As<IBus>()
                .AutoActivate()
                .OnActivated(o => o.Instance.Start())
                .SingleInstance();

            _container = builder.Build();
        }
Ejemplo n.º 3
0
        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<ConsoleLogger>()
                   .AsImplementedInterfaces()
                   .SingleInstance();

            // 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 (HowLongDoPizzasTakeRequest).Assembly);

            builder.RegisterNimbus(typeProvider);
            builder.Register(componentContext => new BusBuilder()
                                 .Configure()
                                 .WithConnectionString(connectionString)
                                 .WithNames("WaitTime", Environment.MachineName)
                                 .WithTypesFrom(typeProvider)
                                 .WithAutofacDefaults(componentContext)
                                 .Build())
                   .As<IBus>()
                   .AutoActivate()
                   .OnActivated(c => c.Instance.Start())
                   .SingleInstance();
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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()
                                                                      .WithTransport(new WindowsServiceBusTransportConfiguration()
                                                                                         .WithConnectionString(connectionString)
                                                                      )
                                                                      .WithNames("PingPong.Windsor", Environment.MachineName)
                                                                      .WithTypesFrom(typeProvider)
                                                                      .WithWindsorDefaults(container)
                                                                      .WithJsonSerializer()
                                                                      .WithDeflateCompressor()
                                                                      .Build())
                                        .LifestyleSingleton()
                );
            Bus bus = (Bus) container.Resolve<IBus>();
            bus.Start().Wait();
        }
Ejemplo n.º 8
0
        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 void TheExceptionShouldIncludeAnInnerException()
        {
            var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(typeof(UnserializableCommandWhoseAssemblyShouldNotBeIncluded).Assembly);

            var exception = Assert.Throws<BusException>(() => assemblyScanningTypeProvider.Verify());

            exception.InnerException.ShouldNotBe(null);
        }
        public async Task NothingShouldGoBang()
        {
            var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly);

            var builder = new ContainerBuilder();
            builder.RegisterNimbus(typeProvider);

            using (builder.Build()) { }
        }
        public async Task NothingShouldGoBang()
        {
            var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly);

            using (var container = new WindsorContainer())
            {
                container.RegisterNimbus(typeProvider);
            }
        }
Ejemplo n.º 12
0
        public void DoFoo()
        {
            var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly());

            var bus = new BusBuilder().Configure()
                                      .WithConnectionString("foo")
                                      .WithNames("MyApp", Environment.MachineName)
                                      .WithTypesFrom(typeProvider)
                                      .Build();
        }
Ejemplo n.º 13
0
        public void DoFoo()
        {
            var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly());
            IMulticastEventHandlerFactory multicastEventHandlerFactory = new DefaultMessageHandlerFactory(typeProvider);

            var bus = new BusBuilder().Configure()
                                      .WithConnectionString("foo")
                                      .WithNames("MyApp", Environment.MachineName)
                                      .WithTypesFrom(typeProvider)
                                      .WithMulticastEventHandlerFactory(multicastEventHandlerFactory)
                                      .Build();
        }
        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>().UsingFactoryMethod(() => CreateBus(container, typeProvider)).LifestyleSingleton()
            );
        }
Ejemplo n.º 15
0
        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 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 (CommandWhoseAssemblyShouldNotBeIncludedHandler).Assembly);
     assemblyScanningTypeProvider.Validate().ShouldNotBeEmpty();
 }
        public void TheTypeScannerShouldThrowOnVerify()
        {
            var scanner = new AssemblyScanningTypeProvider(Assembly.GetAssembly(typeof (DuplicateMessageType)));

            Should.Throw<BusException>(scanner.Verify);
        }
Ejemplo n.º 20
0
        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;
                        
                }


            }

        }
Ejemplo n.º 21
0
        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();
            }
        }
        public void TheAssemblyScannerShouldGoBang()
        {
            var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(typeof (CommandWhoseAssemblyShouldNotBeIncludedHandler).Assembly);

            assemblyScanningTypeProvider.Verify();
        }
 public void ValidationShouldFail()
 {
     var assemblyScanningTypeProvider = new AssemblyScanningTypeProvider(Assembly.GetAssembly(typeof (DuplicateMessageType)));
     assemblyScanningTypeProvider.Validate().ShouldNotBeEmpty();
 }