Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IApplicationLifetime applicationLifetime)
        {
            var container = app.ApplicationServices.GetService <IWindsorContainer>();

            var componentContainer = new WindsorComponentContainer(container);

            componentContainer.RegisterSuffixed("Shuttle.Sentinel");
            componentContainer.RegisterSuffixed("Shuttle.Access.Sql");
            componentContainer.RegisterSuffixed("Shuttle.Esb.Scheduling");

            componentContainer.Register <IInspectionQueue, DefaultInspectionQueue>();
            componentContainer.Register <IHttpContextAccessor, HttpContextAccessor>();
            componentContainer.Register <IDatabaseContextCache, ContextDatabaseContextCache>();
            componentContainer.Register <IHashingService, HashingService>();

            componentContainer.RegisterInstance(app.ApplicationServices.GetService <IAccessConfiguration>());
            componentContainer.RegisterInstance(app.ApplicationServices.GetService <ISentinelConfiguration>());

            var applicationPartManager = app.ApplicationServices.GetRequiredService <ApplicationPartManager>();
            var controllerFeature      = new ControllerFeature();

            applicationPartManager.PopulateFeature(controllerFeature);

            foreach (var type in controllerFeature.Controllers.Select(t => t.AsType()))
            {
                componentContainer.Register(type, type);
            }

            ServiceBus.Register(componentContainer);

            componentContainer.Resolve <IDataStoreDatabaseContextFactory>().ConfigureWith("Sentinel");
            componentContainer.Resolve <IDatabaseContextFactory>().ConfigureWith("Sentinel");

            _bus = ServiceBus.Create(componentContainer).Start();

            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(
                options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
                );

            app.UseMvc();
        }
Example #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddCors();

            var container = new WindsorContainer();

            var componentContainer = new WindsorComponentContainer(container);

            componentContainer.RegisterInstance <IAccessConfiguration>(AccessSection.Configuration());

            componentContainer.RegisterSuffixed("Shuttle.Sentinel");
            componentContainer.RegisterSuffixed("Shuttle.Access.Sql");

            componentContainer.Register <IInspectionQueue, DefaultInspectionQueue>();
            componentContainer.Register <IHttpContextAccessor, HttpContextAccessor>();
            componentContainer.Register <IDatabaseContextCache, ContextDatabaseContextCache>();

            ServiceBus.Register(componentContainer);
            EventStore.Register(componentContainer);

            componentContainer.Resolve <IDataStoreDatabaseContextFactory>().ConfigureWith("Sentinel");
            componentContainer.Resolve <IDatabaseContextFactory>().ConfigureWith("Sentinel");
            var inspectionQueue = componentContainer.Resolve <IInspectionQueue>();

            _bus = ServiceBus.Create(componentContainer).Start();

            return(WindsorRegistrationHelper.CreateServiceProvider(container, services));
        }
        public void ExerciseStorage()
        {
            var container = new WindsorComponentContainer(new WindsorContainer());

            container.RegisterInstance(new Mock <IProjectionRepository>().Object);

            EventStore.Register(container);

            using (container.Resolve <IDatabaseContextFactory>().Create(EventStoreConnectionStringName))
            {
                RecallFixture.ExerciseStorage(EventStore.Create(container));
            }
        }
        public void Should_be_able_to_perform_full_processing(bool isTransactionalEndpoint, bool enqueueUniqueMessages)
        {
            DbProviderFactories.RegisterFactory("System.Data.SqlClient", SqlClientFactory.Instance);

            var container = new WindsorComponentContainer(new WindsorContainer());

            container.RegisterInstance <IIdempotenceConfiguration>(new IdempotenceConfiguration
            {
                ProviderName     = "System.Data.SqlClient",
                ConnectionString = "server=.;database=shuttle;user id=sa;password=Pass!000"
            });

            container.Register <IConnectionConfigurationProvider, ConnectionConfigurationProvider>();
            container.RegisterSqlQueue();
            container.RegisterIdempotence();
            container.RegisterDataAccess();

            TestIdempotenceProcessing(new ComponentContainer(container, () => container), @"sql://shuttle/{0}",
                                      isTransactionalEndpoint, enqueueUniqueMessages);
        }
Example #5
0
        public void Should_be_able_to_handle_expired_message()
        {
            var handlerInvoker = new FakeMessageHandlerInvoker();
            var fakeQueue      = new FakeQueue(2);

            var configuration = new ServiceBusConfiguration
            {
                Inbox = new InboxQueueConfiguration
                {
                    WorkQueue   = fakeQueue,
                    ErrorQueue  = fakeQueue,
                    ThreadCount = 1
                }
            };

            var container = new WindsorComponentContainer(new WindsorContainer());

            container.RegisterInstance <IMessageHandlerInvoker>(handlerInvoker);

            ServiceBus.Register(container, configuration);

            using (var bus = ServiceBus.Create(container))
            {
                bus.Start();

                var timeout = DateTime.Now.AddMilliseconds(1000);

                while (fakeQueue.MessageCount < 2 && DateTime.Now < timeout)
                {
                    Thread.Sleep(5);
                }
            }

            Assert.AreEqual(1, handlerInvoker.GetInvokeCount("SimpleCommand"),
                            "FakeHandlerInvoker was not invoked exactly once.");
            Assert.AreEqual(2, fakeQueue.MessageCount, "FakeQueue was not invoked exactly twice.");
        }