Example #1
0
        private static void Main(string[] args)
        {
            _log.Info("InternalInventoryService Loading...");

            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("InternalInventoryService");
                c.SetDisplayName("Internal Inventory Service");
                c.SetDescription("Handles inventory for internal systems");

                c.RunAsLocalSystem();
                c.DependencyOnMsmq();

                c.BeforeStartingServices(a =>
                {
                    var container = new DefaultMassTransitContainer("InternalInventoryService.Castle.xml");
                    container.AddComponent <InventoryLevelService>();
                    container.AddComponent <InternalInventoryServiceLifeCycle>(typeof(InternalInventoryServiceLifeCycle).Name);
                    _container = container;
                });

                c.ConfigureService <InternalInventoryServiceLifeCycle>(s =>
                {
                    s.HowToBuildService(name => _container.Resolve <InternalInventoryServiceLifeCycle>());
                    s.WhenStarted(o => o.Start());
                    s.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #2
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("testsubscriber.log4net.xml"));

            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("Test Subscriber");
                c.SetDisplayName("Test Subscriber");
                c.SetDescription("a Mass Transit test service for handling new customer orders.");

                c.RunAsLocalSystem();
                c.DependencyOnMsmq();

                c.BeforeStart(a => { });

                c.ConfigureService <TestSubscriberService>(s =>
                {
                    s.CreateServiceLocator(() =>
                    {
                        IWindsorContainer container = new DefaultMassTransitContainer("TestSubscriber.Castle.xml");
                        container.AddComponent <TestSubscriberService>();
                        container.AddComponent <Subscriber>();
                        return(ServiceLocator.Current);
                    });

                    s.WhenStarted(o => o.Start());
                    s.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #3
0
        private static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.xml"));

            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("PostalService");
                c.SetDisplayName("Sample Email Service");
                c.SetDescription("we goin' postal");

                c.RunAsLocalSystem();
                c.DependencyOnMsmq();

                c.BeforeStartingServices(a =>
                {
                    var container = new DefaultMassTransitContainer("postal-castle.xml");
                    container.AddComponent <SendEmailConsumer>("sec");
                    container.AddComponent <PostalService>();
                });

                c.ConfigureService <PostalService>(typeof(PostalService).Name, a =>
                {
                    a.WhenStarted(o => o.Start());
                    a.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #4
0
        private static IWindsorContainer BootstrapContainer()
        {
            IWindsorContainer container = new DefaultMassTransitContainer("Starbucks.Customer.Castle.xml");

            container.AddComponent <CustomerService>(typeof(CustomerService).Name);
            container.AddComponent <OrderDrinkForm>();
            return(container);
        }
Example #5
0
        private static IWindsorContainer BootstrapContainer()
        {
            IWindsorContainer container = new DefaultMassTransitContainer("Starbucks.Cashier.Castle.xml");

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

            container.AddComponent <CashierService>(typeof(CashierService).Name);
            container.AddComponent <CashierSaga>();
            return(container);
        }
Example #6
0
        private static void Main(string[] args)
        {
            _log.Info("Server Loading");

            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("SampleClientService");
                c.SetDisplayName("SampleClientService");
                c.SetDescription("SampleClientService");
                c.DependencyOnMsmq();
                c.RunAsLocalSystem();


                c.ConfigureService <ClientService>(typeof(ClientService).Name, s =>
                {
                    s.WhenStarted(o =>
                    {
                        var bus = ServiceBusConfigurator.New(servicesBus =>
                        {
                            servicesBus.ReceiveFrom("msmq://localhost/mt_client");
                            servicesBus.ConfigureService <SubscriptionClientConfigurator>(client =>
                            {
                                // need to add the ability to read from configuratino settings somehow
                                client.SetSubscriptionServiceEndpoint("msmq://localhost/mt_subscriptions");
                            });
                        });

                        o.Start(bus);
                    });
                    s.WhenStopped(o => o.Stop());
                    s.CreateServiceLocator(() =>
                    {
                        var container = new DefaultMassTransitContainer();
                        IEndpointFactory endpointFactory = EndpointFactoryConfigurator.New(e =>
                        {
                            e.SetObjectBuilder(ServiceLocator.Current.GetInstance <IObjectBuilder>());
                            e.RegisterTransport <MsmqEndpoint>();
                        });
                        container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);
                        container.AddComponent <ClientService>(typeof(ClientService).Name);
                        container.AddComponent <PasswordUpdater>();
                        return(ServiceLocator.Current);                                                //set in the DefaultMTContainer
                    });
                });
            });

            Runner.Host(cfg, args);
        }
Example #7
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);
        }
Example #8
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("MockShipMessagePublisher.log4net.xml"));

            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("Mock Shipping Msg Service");
                c.SetDisplayName("Mock Shipping Msg Service");
                c.SetDescription("a service for faking shipping messages and Publishing the corresponding events on the Bus.");

                c.DependencyOnMsmq();
                c.RunAsFromInteractive(); //Is this right?
                c.BeforeStart(a => { });

                c.ConfigureService <ShippingMessageService>(s =>
                {
                    s.CreateServiceLocator(() =>
                    {
                        IWindsorContainer container = new DefaultMassTransitContainer("MockShipMessagePublisher.Castle.xml");
                        Container.InitializeWith(container);
                        Environment.Setup();

                        container.AddComponent <ShippingMessageService>();
                        return(ServiceLocator.Current);
                    });

                    s.WhenStarted(o => o.Start());
                    s.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #9
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            var cfg = RunnerConfigurator.New(c =>
            {
                c.RunAsLocalSystem();
                c.SetServiceName("audit");
                c.SetDisplayName("audit");
                c.SetDescription("audit");

                c.BeforeStartingServices(a =>
                {
                    var container = new DefaultMassTransitContainer("audit-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.AddComponent <ISagaRepository <RegisterUserSaga>, NHibernateSagaRepository <RegisterUserSaga> >();
                    container.AddComponent <Responder>();
                    container.AddComponent <RegisterUserSaga>();
                    container.AddComponent <AuditService>(typeof(AuditService).Name);
                });

                c.ConfigureService <AuditService>(a =>
                {
                    a.WhenStarted(o => o.Start());
                    a.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #10
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();
            });
        }
Example #11
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();
            });
        }
Example #12
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("MockOrder.log4net.xml"));
            var cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("MockOrderSubscriber");
                c.SetDisplayName("MockOrderSubscriber");
                c.SetDescription("a service for mocking up order processing.");

                c.DependencyOnMsmq();
                c.RunAsLocalSystem();

                c.BeforeStart(a => { });

                c.ConfigureService <MockOrderService>(s =>
                {
                    s.CreateServiceLocator(() =>
                    {
                        IWindsorContainer container = new DefaultMassTransitContainer("MockOrder.Castle.xml");

                        Container.InitializeWith(container);
                        Environment.Setup();

                        container.AddComponent <MockOrderService>();
                        container.AddComponent <Subscriber <CreateOrderMessage> >();

                        //var builder = new WindsorObjectBuilder(container.Kernel);
                        //ServiceLocator.SetLocatorProvider(() => builder);

                        return(ServiceLocator.Current);
                    });

                    s.WhenStarted(o => o.Start());
                    s.WhenStopped(o => o.Stop());
                });
            });

            Runner.Host(cfg, args);
        }
Example #13
0
        private static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("server.log4net.xml"));
            _log.Info("Server Loading");

            IRunConfiguration cfg = RunnerConfigurator.New(c =>
            {
                c.SetServiceName("SampleService");
                c.SetServiceName("Sample Service");
                c.SetServiceName("Something");
                c.DependencyOnMsmq();

                c.RunAsLocalSystem();

                c.ConfigureService <PasswordUpdateService>(typeof(PasswordUpdateService).Name, s =>
                {
                    s.WhenStarted(o =>
                    {
                        IServiceBus bus = ServiceBusConfigurator.New(x =>
                        {
                            x.ReceiveFrom("msmq://localhost/mt_server");
                            x.ConfigureService <SubscriptionClientConfigurator>(b => { b.SetSubscriptionServiceEndpoint("msmq://localhost/mt_subscriptions"); });
                        });
                        o.Start(bus);
                    });
                    s.WhenStopped(o => o.Stop());
                    s.CreateServiceLocator(() =>
                    {
                        var container = new DefaultMassTransitContainer();
                        IEndpointFactory endpointFactory = EndpointFactoryConfigurator
                                                           .New(x =>
                        {
                            x.SetObjectBuilder(ServiceLocator.Current.GetInstance <IObjectBuilder>());
                            x.RegisterTransport <MsmqEndpoint>();
                        });
                        container.Kernel.AddComponentInstance("endpointFactory", typeof(IEndpointFactory), endpointFactory);
                        container.AddComponent <PasswordUpdateService>(typeof(PasswordUpdateService).Name);
                        return(ServiceLocator.Current);                                                //set in DefaultMTContainer
                    });
                });
            });

            Runner.Host(cfg, args);
        }
Example #14
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);
        }