private void ClearMeABus()
        {
            // 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[] {"Some.Namespace.That.Does.Not.Exist"});
            var messageBroker = new DefaultMessageHandlerFactory(typeProvider);

            var logger = new ConsoleLogger();

            var busBuilder = 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)
                                             .WithDebugOptions(
                                                 dc =>
                                                     dc.RemoveAllExistingNamespaceElementsOnStartup(
                                                         "I understand this will delete EVERYTHING in my namespace. I promise to only use this for test suites."))
                ;

            using (var bus = busBuilder.Build())
            {
                bus.Start();
            }
        }
示例#2
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);
        }
        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);
            }
        }
示例#6
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();
            }
        }
示例#7
0
        public ScenarioInstance <BusBuilderConfiguration> CreateInstance()
        {
            var transport    = _transport.CreateInstance();
            var router       = _router.CreateInstance();
            var serializer   = _serializer.CreateInstance();
            var compressor   = _compressor.CreateInstance();
            var iocContainer = _iocContainer.CreateInstance();
            var syncContext  = _syncContext.CreateInstance();

            var configuration = new Nimbus.Configuration.BusBuilder()
                                .Configure()
                                .WithTransport(transport.Configuration)
                                .WithRouter(router.Configuration)
                                .WithSerializer(serializer.Configuration)
                                .WithCompressor(compressor.Configuration)
                                .WithDeliveryRetryStrategy(new ImmediateRetryDeliveryStrategy())
                                .WithNames("MyTestSuite", Environment.MachineName)
                                .WithTypesFrom(_typeProvider)
                                .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."))
                                .Chain(iocContainer.Configuration.ApplyContainerDefaults)
            ;

            var instance = new ScenarioInstance <BusBuilderConfiguration>(configuration);

            instance.Disposing += (s, e) => syncContext.Dispose();

            return(instance);
        }
        private async Task ClearMeABus(IConfigurationScenario<TransportConfiguration> scenario)
        {
            using (var instance = scenario.CreateInstance())
            {
                // We want a namespace that doesn't exist here so that all the queues and topics are removed.
                var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {"Some.Namespace.That.Does.Not.Exist"});
                var transportConfiguration = instance.Configuration;

                var busBuilder = new BusBuilder().Configure()
                                                 .WithTransport(transportConfiguration)
                                                 .WithRouter(new DestinationPerMessageTypeRouter())
                                                 .WithSerializer(new JsonSerializer())
                                                 .WithDeliveryRetryStrategy(new ImmediateRetryDeliveryStrategy())
                                                 .WithDependencyResolver(new DependencyResolver(typeProvider))
                                                 .WithNames("MyTestSuite", Environment.MachineName)
                                                 .WithTypesFrom(typeProvider)
                                                 .WithDefaultTimeout(TimeSpan.FromSeconds(TimeoutSeconds))
                                                 .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."))
                    ;

                using (var bus = busBuilder.Build())
                {
                    await bus.Start();
                    await bus.Stop();
                }
            }
        }
示例#9
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 DoFoo()
        {
            var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly());

            var bus = new BusBuilder().Configure()
                                      .WithConnectionString("foo")
                                      .WithNames("MyApp", Environment.MachineName)
                                      .WithTypesFrom(typeProvider)
                                      .Build();
        }
示例#11
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 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();
        }
示例#13
0
        public Bus Build()
        {
            if (TypeProvider != null)
            {
                if (Serializer == null)
                {
                    Serializer = new DataContractSerializer(TypeProvider);
                }

                if (DependencyResolver == null)
                {
                    DependencyResolver = new DependencyResolver(TypeProvider);
                }
            }

            return(BusBuilder.Build(this));
        }
示例#14
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;
                }
            }
        }
示例#15
0
        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;
        }
        public async Task ItShouldGoBangQuickly()
        {
            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(@"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=")
                                      .WithTypesFrom(typeProvider)
                                      .WithCommandHandlerFactory(messageBroker)
                                      .WithRequestHandlerFactory(messageBroker)
                                      .WithMulticastEventHandlerFactory(messageBroker)
                                      .WithCompetingEventHandlerFactory(messageBroker)
                                      .WithMulticastRequestHandlerFactory(messageBroker)
                                      .WithDefaultTimeout(TimeSpan.FromSeconds(10))
                                      .WithLogger(logger)
                                      .Build();

            Should.Throw<BusException>(bus.Start);
        }
        private void BuildMeABus()
        {
            // 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 DefaultMessageBroker(typeProvider);

            var logger = new ConsoleLogger();

            var bus = new BusBuilder().Configure()
                                      .WithNames("MyTestSuite", Environment.MachineName)
                                      .WithConnectionString(CommonResources.ConnectionString)
                                      .WithTypesFrom(typeProvider)
                                      .WithCommandBroker(messageBroker)
                                      .WithRequestBroker(messageBroker)
                                      .WithMulticastEventBroker(messageBroker)
                                      .WithCompetingEventBroker(messageBroker)
                                      .WithMulticastRequestBroker(messageBroker)
                                      .WithDefaultTimeout(TimeSpan.FromSeconds(10))
                                      .WithLogger(logger)
                                      .Build();
            bus.ShouldNotBe(null);
        }
示例#18
0
 public Bus Build()
 {
     AssertConfigurationIsValid();
     return(BusBuilder.Build(this));
 }
示例#19
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();
            }
        }
示例#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;
                        
                }


            }

        }
        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;
                                  });
        }
        private async Task<Bus> BuildMeABus(IConfigurationScenario<TransportConfiguration> scenario)
        {
            var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace});

            using (var instance = scenario.CreateInstance())
            {
                var transportConfiguration = instance.Configuration;

                var configuration = new BusBuilder().Configure()
                                                    .WithTransport(transportConfiguration)
                                                    .WithRouter(new DestinationPerMessageTypeRouter())
                                                    .WithSerializer(new JsonSerializer())
                                                    .WithDeliveryRetryStrategy(new ImmediateRetryDeliveryStrategy())
                                                    .WithDependencyResolver(new DependencyResolver(typeProvider))
                                                    .WithNames("MyTestSuite", Environment.MachineName)
                                                    .WithTypesFrom(typeProvider)
                                                    .WithDefaultTimeout(TimeSpan.FromSeconds(10))
                                                    .WithHeartbeatInterval(TimeSpan.MaxValue)
                                                    .WithLogger(_logger)
                    ;

                var bus = configuration.Build();
                await bus.Start();
                await bus.Stop();
                return bus;
            }
        }