Пример #1
0
        private static void Main()
        {
            /////setup
            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.xml"));

            WindsorContainer c  = new DefaultMassTransitContainer();
            IEndpointFactory ef = EndpointFactoryConfigurator.New(e => e.RegisterTransport <MsmqEndpoint>());

            c.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), ef);
            c.AddComponent <SimpleMessageHandler>();
            c.AddComponentLifeStyle("counter", typeof(Counter), LifestyleType.Singleton);
            c.AddComponentLifeStyle("rvaoeuaoe", typeof(CacheUpdateResponseHandler), LifestyleType.Transient);

            IServiceBus bus = ServiceBusConfigurator.New(b =>
            {
                b.ReceiveFrom("msmq://localhost/mt_client");
                b.ConfigureService <SubscriptionClientConfigurator>(sc => sc.SetSubscriptionServiceEndpoint("msmq://localhost/mt_subscriptions"));
                b.ConfigureService <HealthClientConfigurator>(hc => hc.SetHeartbeatInterval(10));
            });

            c.Kernel.AddComponentInstance("bus", typeof(IServiceBus), bus);

            bus.Subscribe <CacheUpdateResponseHandler>();
            bus.Subscribe <SimpleMessageHandler>();

            IEndpoint ep            = c.Resolve <IEndpointFactory>().GetEndpoint(new Uri("msmq://localhost/mt_subscriptions"));
            var       subTester     = new SubscriptionServiceTester(ep, bus, c.Resolve <Counter>());
            var       healthTester  = new HealthServiceTester(c.Resolve <Counter>(), bus);
            var       timeoutTester = new TimeoutTester(bus);

            bus.Subscribe(healthTester);
            ///////


            Console.WriteLine("Please enter the number of hours you would like this test to run for?");
            Console.WriteLine("(use 0.1 for 6 minutes)");
            Console.WriteLine("(use 0.016 for 1 minute)");
            string   input    = Console.ReadLine();
            double   hours    = double.Parse(input ?? "0");
            DateTime stopTime = DateTime.Now.AddHours(hours);


            Console.WriteLine("Test Started");
            var rand = new Random();

            while (DateTime.Now < stopTime)
            {
                subTester.Test();
                healthTester.Test();
                timeoutTester.Test();

                Thread.Sleep(rand.Next(5, 10) * 1000);
                PrintTime(bus, c.Resolve <Counter>());
            }

            //print final stuff (probably do this by tester)
            subTester.Results();
            Console.WriteLine("Done (press any key to exit)");
            Console.ReadKey(true);
        }
Пример #2
0
        public void Setup()
        {
            _container = new DefaultMassTransitContainer("saga.tests.castle.xml");

            _localBus  = _container.Resolve <IServiceBus>("local");
            _remoteBus = _container.Resolve <IServiceBus>("remote");

            Before_each();
        }
Пример #3
0
        public void Setup()
        {
            _container = new DefaultMassTransitContainer("saga.tests.castle.xml");

            _localBus = _container.Resolve<IServiceBus>("local");
            _remoteBus = _container.Resolve<IServiceBus>("remote");

            Before_each();
        }
Пример #4
0
        private static void ConfigureHealthService(IServiceConfigurator <HealthService> configurator)
        {
            configurator.CreateServiceLocator(() =>
            {
                var container = new DefaultMassTransitContainer();

                container.AddComponent <HealthService>(typeof(HealthService).Name);
                container.AddComponent("sagaRepository", typeof(ISagaRepository <>), typeof(InMemorySagaRepository <>));

                var endpointFactory = EndpointFactoryConfigurator.New(x =>
                {
                    // the default
                    x.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                    x.RegisterTransport <MsmqEndpoint>();
                });

                container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);

                var bus = ServiceBusConfigurator.New(x =>
                {
                    x.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                    x.ReceiveFrom("msmq://localhost/mt_health");
                    x.ConfigureService <SubscriptionClientConfigurator>(client =>
                    {
                        // need to add the ability to read from configuratino settings somehow
                        client.SetSubscriptionServiceEndpoint("msmq://localhost/mt_subscriptions");
                    });
                });

                container.Kernel.AddComponentInstance("bus", typeof(IServiceBus), bus);

                return(container.Resolve <IObjectBuilder>());
            });

            configurator.WhenStarted(service => { service.Start(); });

            configurator.WhenStopped(service =>
            {
                service.Stop();
                service.Dispose();
            });
        }
Пример #5
0
        private static void ConfigureSubscriptionService(IServiceConfigurator <SubscriptionService> configurator)
        {
            configurator.CreateServiceLocator(() =>
            {
                var container = new DefaultMassTransitContainer();

                container.AddComponent("sagaRepository", typeof(ISagaRepository <>), typeof(InMemorySagaRepository <>));

                container.AddComponent <ISubscriptionRepository, InMemorySubscriptionRepository>();
                container.AddComponent <SubscriptionService, SubscriptionService>(typeof(SubscriptionService).Name);

                var endpointFactory = EndpointFactoryConfigurator.New(x =>
                {
                    // the default
                    x.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                    x.RegisterTransport <MsmqEndpoint>();
                });

                container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);

                var bus = ServiceBusConfigurator.New(servicesBus =>
                {
                    servicesBus.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                    servicesBus.ReceiveFrom("msmq://localhost/mt_subscriptions");
                    servicesBus.SetConcurrentConsumerLimit(1);
                });

                container.Kernel.AddComponentInstance("bus", typeof(IServiceBus), bus);

                return(container.ObjectBuilder);
            });

            configurator.WhenStarted(service => service.Start());

            configurator.WhenStopped(service =>
            {
                service.Stop();
                service.Dispose();
            });
        }
Пример #6
0
        protected void Application_Start(object sender, EventArgs e)
        {
            XmlConfigurator.Configure();

            _container = new DefaultMassTransitContainer(Server.MapPath("/web-castle.config"));

            Configuration _cfg = new Configuration().Configure();

            _cfg.AddAssembly(typeof(NHibernateRepositoryFactory).Assembly);

            ISessionFactory _sessionFactory = _cfg.BuildSessionFactory();

            LocalContext.Current.Store(_sessionFactory);

            NHibernateUnitOfWork.SetSessionProvider(_sessionFactory.OpenSession);

            UnitOfWork.SetUnitOfWorkProvider(NHibernateUnitOfWork.Create);

            _container.Kernel.AddComponentInstance <IRepositoryFactory>(NHibernateRepositoryFactory.Configure(x => { }));

            DomainContext.Initialize(_container.Resolve <IServiceBus>("client"), _container.Resolve <IObjectBuilder>());
        }
Пример #7
0
        private static void Main(string[] args)
        {
            _log.Info("subscription_mgr Loading...");

            Console.WriteLine("MSMQ Subscription Service");
            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("subscription_mgr");
                c.SetDisplayName("Subscription Service");
                c.SetDescription("Coordinates subscriptions between multiple systems");
                c.DependencyOnMsmq();
                c.RunAsLocalSystem();

                c.BeforeStartingServices(s =>
                {
                    var container = new DefaultMassTransitContainer();

                    IEndpointFactory endpointFactory = EndpointFactoryConfigurator.New(e =>
                    {
                        e.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                        e.RegisterTransport <MsmqEndpoint>();
                    });
                    container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);


                    _wob = new WindsorObjectBuilder(container.Kernel);
                    ServiceLocator.SetLocatorProvider(() => _wob);
                });

                c.ConfigureService <SubscriptionService>(ConfigureSubscriptionService);

                c.ConfigureService <TimeoutService>(ConfigureTimeoutService);

                c.ConfigureService <HealthService>(ConfigureHealthService);
            });

            try
            {
                Runner.Host(cfg, args);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error trying to run service: " + ex);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #8
0
        private static void Main(string[] args)
        {
            _log.Info("SubscriptionManagerGUI Loading...");

            var cfg = RunnerConfigurator.New(x =>
            {
                x.SetServiceName("SubscriptionManagerGUI");
                x.SetDisplayName("Sample GUI Subscription Service");
                x.SetDescription("Coordinates subscriptions between multiple systems");
                x.DependencyOnMsmq();
                x.RunAsLocalSystem();
                x.UseWinFormHost <SubscriptionManagerForm>();

                x.BeforeStart(s =>
                {
                    var container = new DefaultMassTransitContainer();

                    IEndpointFactory endpointFactory = EndpointFactoryConfigurator.New(e =>
                    {
                        e.SetObjectBuilder(container.Resolve <IObjectBuilder>());
                        e.RegisterTransport <MsmqEndpoint>();
                    });
                    container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);

                    container.AddComponent <SubscriptionManagerForm>();

                    var wob = new WindsorObjectBuilder(container.Kernel);
                    ServiceLocator.SetLocatorProvider(() => wob);
                });

                x.ConfigureService <SubscriptionService>(ConfigureSubscriptionService);

                x.ConfigureService <TimeoutService>(ConfigureTimeoutService);

                x.ConfigureService <HealthService>(ConfigureHealthService);
            });

            Runner.Host(cfg, args);
        }