Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
0
        private static IWindsorContainer BootstrapContainer()
        {
            IWindsorContainer container = new DefaultMassTransitContainer("Starbucks.Customer.Castle.xml");

            container.AddComponent <CustomerService>(typeof(CustomerService).Name);
            container.AddComponent <OrderDrinkForm>();
            return(container);
        }
        public void Setup()
        {
            _container = new DefaultMassTransitContainer("saga.tests.castle.xml");

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

            Before_each();
        }
Example #8
0
        public void Setup()
        {
            _container = new DefaultMassTransitContainer("saga.tests.castle.xml");

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

            Before_each();
        }
Example #9
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 #10
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 #11
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();
            }
        }
Example #12
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 #13
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 #14
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 #15
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 #16
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);
        }
Example #17
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>());
        }
Example #18
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 #19
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("TestPublisher.log4net.xml"));

            IWindsorContainer container = new DefaultMassTransitContainer("TestPublisher.Castle.xml");
            IServiceBus       bus       = ServiceLocator.Current.GetInstance <IServiceBus>();


            var messaage = new CreateOrderMessage()
            {
                BusinessPartnerCode   = BusinessPartner.FedEx.Code,
                BusinessPartnerNumber = BusinessPartner.FedEx.Number,
                ControlNumber         = "1",
                CustomerPO            = "PO-100",
                Customer = new Customer {
                    CustomerID = "100", CustomerName = "test co."
                },
                BusinessProcessName = "business process name",
                RequestDate         = SystemTime.Now().ToString()
            };

            messaage.Customer.AddAddress(new Address
            {
                Address1    = "test addr1",
                Address2    = "addr2",
                AddressCode = "TEST",
                AddressName = "office",
                AddressType = AddressTypeConstants.ShipTo,
                City        = "austin",
                State       = "TX",
                Zip         = "88888"
            });

            messaage.Add(new CustomerOrderLine
            {
                CustID             = "100",
                CustomerPartNumber = "222",
                CustomerPO         = "333",
                ItemDescription    = "desc",
                ItemID             = "444",
                LineNumber         = 1,
                Notes             = "note",
                OrderMultiple     = 1,
                OrderNumber       = "555",
                RequestedPrice    = 6.0,
                RequestedQuantity = 2,
                RequestNumber     = "1",
                TestMode          = true
            });
            messaage.LineItems.Add(new CustomerOrderLine
            {
                CustID             = "100",
                CustomerPartNumber = "222b",
                CustomerPO         = "333b",
                ItemDescription    = "descb",
                ItemID             = "444b",
                LineNumber         = 2,
                Notes             = "noteb",
                OrderMultiple     = 2,
                OrderNumber       = "555b",
                RequestedPrice    = 7.0,
                RequestedQuantity = 3,
                RequestNumber     = "1b",
                TestMode          = true
            });

            Thread.Sleep(4000);

            bus.Publish(messaage);

            bus.Dispose();
        }