Esempio n. 1
0
        static void Main()
        {
            Console.WriteLine("Starting Publisher");

            MsmqEndpointConfigurator.Defaults(config =>
            {
                config.CreateMissingQueues = true;
            });

            var container = new DefaultMassTransitContainer("windsor.xml");
            var bus = container.Resolve<IServiceBus>();

            string name;
            while((name = GetName()) != "q")
            {
                var message = new NewCustomerMessage {Name = name};
                bus.Publish(message);

                Console.WriteLine("Published NewCustomerMessage with name {0}", message.Name);
            }

            Console.WriteLine("Stopping Publisher");
            container.Release(bus);
            container.Dispose();
        }
Esempio n. 2
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);
		}
Esempio n. 3
0
		private static IWindsorContainer BootstrapContainer()
		{
			IWindsorContainer container = new DefaultMassTransitContainer("Starbucks.Customer.Castle.xml");
			container.AddComponent<CustomerService>(typeof (CustomerService).Name);
			container.AddComponent<OrderDrinkForm>();
		    return container;
		}
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
		private void StartService()
		{
			StopService();

			try
			{
				
				_container = new DefaultMassTransitContainer("Server.Castle.xml");

				_bus = _container.Resolve<IServiceBus>("server");
				//_controlBus = _container.Resolve<IServiceBus>("control");

			    _container.AddComponent<UserAgentSession>();
			    _container.AddComponent<TheAnswerMan>();

				_bus.Subscribe<UserAgentSession>();
				_bus.Subscribe<TheAnswerMan>();

				messageTimer.Start();
			}
			catch (Exception ex)
			{
				_log.Error(ex);
				MessageBox.Show("The server failed to start:\n\n" + ex.Message);
			}
		}
Esempio n. 7
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);
							var wob = new WindsorObjectBuilder(container.Kernel);
							ServiceLocator.SetLocatorProvider(() => wob);
						});

					c.ConfigureService<InternalInventoryServiceLifeCycle>(typeof(InternalInventoryServiceLifeCycle).Name, s =>
						{
							s.WhenStarted(o => o.Start());
							s.WhenStopped(o => o.Stop());
						});
				});
			Runner.Host(cfg, args);
		}
Esempio n. 8
0
		private static IWindsorContainer BootstrapContainer()
		{
			IWindsorContainer container = new DefaultMassTransitContainer("Starbucks.Barista.Castle.xml");
			container.AddComponent("sagaRepository", typeof (ISagaRepository<>), typeof (InMemorySagaRepository<>));

			container.AddComponent<DrinkPreparationSaga>();
			container.AddComponent<BaristaService>(typeof (BaristaService).Name);
			return container;
		}
Esempio n. 9
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);
		}
Esempio n. 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();
                });
        }
Esempio n. 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();
                });
        }
Esempio n. 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);
        }
Esempio n. 13
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>());
        }
Esempio n. 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.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);

							container.AddComponent<SubscriptionManagerForm>();

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

					x.ConfigureService<SubscriptionService>(typeof(SubscriptionService).Name, ConfigureSubscriptionService);

					x.ConfigureService<TimeoutService>(typeof(TimeoutService).Name, ConfigureTimeoutService);

					x.ConfigureService<HealthService>(typeof(HealthService).Name, ConfigureHealthService);
				});
			Runner.Host(cfg, args);
		}
Esempio n. 15
0
        static void Main()
        {
            Console.WriteLine("Starting Subscriber, hit return to quit");

            MsmqEndpointConfigurator.Defaults(config =>
                {
                    config.CreateMissingQueues = true;
                });

            var container = new DefaultMassTransitContainer("windsor.xml")
                .Register(
                    Component.For<NewCustomerMessageConsumer>().LifeStyle.Transient
                );

            var bus = container.Resolve<IServiceBus>();
            var consumer = container.Resolve<NewCustomerMessageConsumer>();
            consumer.Start(bus);

            Console.ReadLine();
            Console.WriteLine("Stopping Subscriber");
            consumer.Stop();
            container.Dispose();
        }
Esempio n. 16
0
        private void StartClient()
        {
            StopClient();

            try
            {
                _container = new DefaultMassTransitContainer("Client.Castle.xml");

                _bus = _container.Resolve<IServiceBus>("client");

                _container.AddComponent<TimeoutWatcher>();
                _bus.Subscribe<TimeoutWatcher>();
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                MessageBox.Show("The client failed to start:\n\n" + ex.Message);
            }
        }
Esempio n. 17
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();
                }
        }
Esempio n. 18
0
		private void StopService()
		{
			messageTimer.Stop();

			if (_bus != null)
				LogException(() =>
				             	{
				             		_bus.Dispose();
				             		_bus = null;
				             	});

			if (_controlBus != null)
				LogException(() =>
				             	{
									_controlBus.Dispose();
									_controlBus = null;
				             	});

			if (_container != null)
				LogException(() =>
				             	{
									_container.Dispose();
									_container = null;
				             	});
		}
Esempio n. 19
0
        private void StopClient()
        {
            try
            {
                if (_bus != null)
                {
                    _bus.Dispose();
                    _bus = null;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }

            try
            {
                if (_container != null)
                {
                    _container.Dispose();
                    _container = null;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
Esempio n. 20
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();
        }