Esempio n. 1
0
        static void ConfigureDefaultMongoDbIfNecessary(MessageBusConfigurator cfg)
        {
            string connstr, collection;

            if (!Util.ParseMongoEndpoint(cfg.Endpoint, out connstr, out collection))
            {
                throw new Exception("Invalid mongo connection string: " + cfg.Endpoint);
            }
            var dic = new Dictionary <string, string>();

            foreach (var cs in cfg.GetConnectionStrings())
            {
                if (cs.Name == null || dic.ContainsKey(cs.Name))
                {
                    continue;
                }
                dic[cs.Name] = cs.ConnectionString;
            }
            var cstr = Util.GetMongoConnectionStringForEndpoint(cfg.Endpoint, dic);

            cfg.CustomizeContainer(wc =>
            {
                if (!MessageBusConfigurator.IsServiceRegistered(wc, typeof(MongoDatabase)))
                {
                    wc.Register(Component.For <MongoDatabase>()
                                .Instance(MongoDatabase.Create(cstr)));
                }
            });
        }
Esempio n. 2
0
        protected override void OnStart(string[] args)
        {
            string           componentConfig = ConfigurationManager.AppSettings["NGinnMessageBus.ServiceHost.ComponentConfig"];
            bool             section         = ConfigurationManager.GetSection(componentConfig) != null;
            WindsorContainer wc = null;

            if (!string.IsNullOrEmpty(componentConfig))
            {
                if (section)
                {
                    wc = new WindsorContainer(new XmlInterpreter(new ConfigResource(componentConfig)));
                }
                else if (Path.GetExtension(componentConfig) == "xml" || Path.GetExtension(componentConfig) == ".xml")
                {
                    log.Info("Configuring the container from xml file: {0}", componentConfig);
                    wc = new WindsorContainer(new XmlInterpreter(new FileResource(componentConfig, AppDomain.CurrentDomain.BaseDirectory)));
                }
                else
                {
                    throw new Exception("Don't know how to load config: " + componentConfig);
                }
            }
            else
            {
                wc = new WindsorContainer();
            }
            _host = MessageBusConfigurator.Begin(wc)
                    .ConfigureFromAppConfig()
                    .AutoStartMessageBus(true)
                    .FinishConfiguration();
        }
Esempio n. 3
0
 public static MessageBusConfigurator UseMongoDb(this MessageBusConfigurator cfg)
 {
     cfg.UseMongoDbTransport();
     cfg.UseMongoDbSagaRepository();
     cfg.UseMongoDbSubscriptions();
     return(cfg);
 }
Esempio n. 4
0
        public static IWindsorContainer ConfigureMessageBus(string endpointName, IDictionary <string, string> dbConnectionStrings)
        {
            MessageBusConfigurator cfg = MessageBusConfigurator.Begin()
                                         .SetEndpoint(endpointName)
                                         .SetConnectionStrings(dbConnectionStrings.Select((kv, i) => new ConnectionStringSettings {
                Name = kv.Key, ProviderName = "System.Data.SqlClient", ConnectionString = kv.Value
            }))
                                         .UseSqlSubscriptions()
                                         .UseStaticMessageRouting("Routing.json")
                                         //.RegisterHttpMessageServicesFromAssembly(typeof(Program).Assembly)
                                         .AddMessageHandlersFromAssembly(typeof(Setup).Assembly)
                                         .UseSqlSequenceManager()
                                         .SetEnableSagas(false)
                                         .SetSendOnly(false)
                                         .SetMaxConcurrentMessages(1)
                                         .SetUseTransactionScope(true)
                                         .SetAlwaysPublishLocal(false)
                                         .SetReuseReceiveConnectionForSending(true)
                                         .SetExposeReceiveConnectionToApplication(true)
                                         .SetDefaultSubscriptionLifetime(TimeSpan.FromHours(8))
                                         .AutoStartMessageBus(true);

            cfg.FinishConfiguration();
            return(cfg.Container);
        }
Esempio n. 5
0
 public static IWindsorContainer ConfigureTheBus()
 {
     return(MessageBusConfigurator.Begin()
            .ConfigureFromAppConfig()
            .AutoStartMessageBus(true)
            .FinishConfiguration()
            .Container);
 }
Esempio n. 6
0
 protected override void OnStop()
 {
     if (_host != null)
     {
         _host.StopMessageBus();
         _host.Container.Dispose();
         _host = null;
     }
 }
Esempio n. 7
0
 void Application_Start(object sender, EventArgs e)
 {
     this.mc = MessageBusConfigurator.Begin()
               .ConfigureFromAppConfig()
               .UseSqlSubscriptions()
               .FinishConfiguration()
               .StartMessageBus();
     MessageBus = mc.GetMessageBus();
 }
 void Application_Start(object sender, EventArgs e)
 {
     this.mc = MessageBusConfigurator.Begin()
         .ConfigureFromAppConfig()
         .UseSqlSubscriptions()
         .FinishConfiguration()
         .StartMessageBus();
     MessageBus = mc.GetMessageBus();
 }
Esempio n. 9
0
 protected override void OnStop()
 {
     if (_host != null)
     {
         _host.StopMessageBus();
         _host.Container.Dispose();
         _host = null;
     }
 }
Esempio n. 10
0
 public static IWindsorContainer ConfigureTheBusSendOnly()
 {
     return(MessageBusConfigurator.Begin()
            .ConfigureFromAppConfig()
            .AutoStartMessageBus(true)
            .UseStaticMessageRouting("routing.json")
            .SetSendOnly(true)
            .FinishConfiguration()
            .Container);
 }
Esempio n. 11
0
 public static MessageBusConfigurator UseMongoDbSagaRepository(this MessageBusConfigurator cfg, string sagaCollection)
 {
     ConfigureDefaultMongoDbIfNecessary(cfg);
     cfg.CustomizeContainer(wc =>
     {
         wc.Register(Component.For <ISagaRepository>().ImplementedBy <MongoDbSagaJsonRepository>()
                     .DependsOn(new
         {
             SagaCollection = sagaCollection
         }).LifeStyle.Singleton);
     });
     return(cfg);
 }
Esempio n. 12
0
        public static MessageBusConfigurator RegisterMongoSagaType <TSaga>(this MessageBusConfigurator cfg)
        {
            cfg.RegisterSagaType(typeof(TSaga));
            if (!BsonClassMap.IsClassMapRegistered(typeof(TSaga)))
            {
                BsonClassMap.RegisterClassMap <TSaga>(x =>
                {
                    x.AutoMap();
                    x.SetIgnoreExtraElements(true);
                });
            }

            return(cfg);
        }
Esempio n. 13
0
        public static IWindsorContainer Configure(string endpoint, bool sendOnly)
        {
            var mc = MessageBusConfigurator.Begin()
                     .ConfigureFromAppConfig()
                     .SetEndpoint(endpoint)
                     .SetSendOnly(sendOnly)
                     .AddMessageHandlersFromAssembly(typeof(Program).Assembly)
                     .AutoStartMessageBus(true)
                     .BatchOutgoingMessages(true
                                            )
                     //.UseExternalHandlerContainer(new WindsorServiceResolver(null))
                     .FinishConfiguration();

            return(mc.Container);
        }
Esempio n. 14
0
        public static IMessageBus ConfigureMongoBus()
        {
            IMessageBus bus = MessageBusConfigurator.Begin()
                              .SetEndpoint("mongodb://localhost:27017/cogmon?queueName=Queue1")
                              .SetEnableSagas(true)
                              .SetMaxConcurrentMessages(8)
                              .SetReuseReceiveConnectionForSending(true)
                              .UseMongoDb()
                              .AddMessageHandlersFromAssembly(typeof(MongoQueue).Assembly)
                              .AutoStartMessageBus(true)
                              .FinishConfiguration()
                              .GetMessageBus();

            return(bus);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging(NLog.LogLevel.Warn);
            MessageBusConfigurator mc = ConfigureMessageBus("sql://MessageBus/MQ_Events_SubscriberTwo");
            var bus = mc.GetMessageBus();
            //we'll be receiving events through the message distributor!
            //string eventHub = "sql://MessageBus/MQ_EventHub";
            string eventHub = "sql://MessageBus/MQ_Events";

            bus.SubscribeAt(eventHub, typeof(Object));
            Console.WriteLine("Subscribed at {0}", eventHub);
            Console.WriteLine("Subscriber two listening at {0}, press enter to exit...", bus.Endpoint);
            Console.ReadLine();
            mc.StopMessageBus();
        }
Esempio n. 16
0
        public static IMessageBus ConfigureMessageBus()
        {
            var wc = MessageBusConfigurator.Begin()
                     .ConfigureFromAppConfig()
                     .UseStaticMessageRouting("route.json")
                     .AutoCreateDatabase(false)
                     .SetEnableSagas(false)
                     .SetAlwaysPublishLocal(true)
                     .AddMessageHandlersFromAssembly(typeof(OracleTests).Assembly)
                     .SetMaxConcurrentMessages(1)
                     .AutoStartMessageBus(true)
                     .FinishConfiguration()
                     .Container;

            return(wc.Resolve <IMessageBus>());
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging(LogLevel.Warn);
            var mc = MessageBusConfigurator.Begin()
                     .ConfigureFromAppConfig()
                     .AddMessageHandlersFromAssembly(typeof(Program).Assembly)
                     .FinishConfiguration()
                     .StartMessageBus();
            IMessageBus mb = mc.GetMessageBus();

            mb.SubscribeAt(System.Configuration.ConfigurationManager.AppSettings["PublisherEndpoint"], typeof(Object));
            Console.WriteLine("Subscriber at {0} ready to receive messages. Press Enter to exit", mb.Endpoint);
            Console.ReadLine();
            Console.WriteLine("Stopping...");
            mc.StopMessageBus();
        }
Esempio n. 18
0
        public static IWindsorContainer ConfigureMessageBus(string endpointName, IDictionary <string, string> dbConnectionStrings, string httpUrl)
        {
            MessageBusConfigurator cfg = MessageBusConfigurator.Begin()
                                         .SetEndpoint(endpointName)
                                         .SetConnectionStrings(dbConnectionStrings.Select((kv, i) => new ConnectionStringSettings {
                Name = kv.Key, ProviderName = "System.Data.SqlClient", ConnectionString = kv.Value
            }))
                                         .UseSqlSubscriptions()
                                         .UseStaticMessageRouting("Routing.json")
                                         //.RegisterHttpMessageServicesFromAssembly(typeof(Program).Assembly)
                                         .AddMessageHandlersFromAssembly(typeof(Program).Assembly)
                                         .UseSqlSequenceManager()
                                         .SetEnableSagas(true)
                                         .SetSendOnly(false)
                                         .SetMaxConcurrentMessages(4)
                                         .SetUseTransactionScope(true)
                                         .SetAlwaysPublishLocal(false)
                                         .SetReuseReceiveConnectionForSending(true)
                                         .SetExposeReceiveConnectionToApplication(true)
                                         .SetDefaultSubscriptionLifetime(TimeSpan.FromHours(8))
                                         .AutoStartMessageBus(true);

            if (httpUrl != null)
            {
                cfg.ConfigureHttpReceiver(httpUrl);
            }
            cfg.CustomizeContainer(delegate(IWindsorContainer wc)
            {
                /*wc.Register(Component.For<NGinnBPM.MessageBus.Impl.ISerializeMessages>()
                 *  .ImplementedBy<NGinnBPM.MessageBus.Impl.ServiceStackMessageSerializer>()
                 *  .DependsOn(new { UseFullAssemblyNames = false })
                 *  .LifeStyle.Singleton);*/
                wc.Register(Component.For <IServlet>()
                            .ImplementedBy <FSDirectoryServlet>()
                            .DependsOn(new
                {
                    MatchUrl      = @"/www/(?<id>.+)?",
                    BaseDirectory = "c:\\inetpub\\wwwroot"
                }).LifeStyle.Transient);
            });
            //cfg.ConfigureAdditionalSqlMessageBus("bus2", "sql://testdb1/MQueue2");
            cfg.FinishConfiguration();
            //cfg.StartMessageBus();

            return(cfg.Container);
        }
Esempio n. 19
0
 public static MessageBusConfigurator UseMongoDbSubscriptions(this MessageBusConfigurator cfg)
 {
     ConfigureDefaultMongoDbIfNecessary(cfg);
     cfg.CustomizeContainer(wc =>
     {
         if (!MessageBusConfigurator.IsServiceRegistered(wc, typeof(ISubscriptionService)))
         {
             wc.Register(Component.For <ISubscriptionService>().ImplementedBy <MongoDbSubscriptionService>()
                         .DependsOn(new
             {
                 CollectionName       = "NG_Subscriptions",
                 SubscriptionLifetime = cfg.SubscriptionLifetime
             }).LifeStyle.Singleton);
         }
     });
     return(cfg);
 }
Esempio n. 20
0
        public NGinnConfigurator FinishConfiguration()
        {
            _wc.Register(Component.For <ProcessEngine>()
                         .ImplementedBy <ProcessEngine>()
                         .LifeStyle.Singleton);
            _wc.Register(Component.For <ITaskInstancePersister>()
                         .ImplementedBy <SqlProcessPersister>()
                         .LifeStyle.Singleton);
            _wc.Register(Component.For <ITaskInstanceSerializer>()
                         .ImplementedBy <JsonTaskInstanceSerializer>());

            MessageBusConfigurator.Begin(_wc)
            .AddMessageHandlersFromAssembly(typeof(TaskInstance).Assembly)
            .AddMessageHandlersFromAssembly(typeof(NGinnConfigurator).Assembly)
            .ConfigureFromAppConfig()
            .AutoStartMessageBus(true)
            .FinishConfiguration();
            return(this);
        }
Esempio n. 21
0
        public static MessageBusConfigurator UseMongoDbTransport(this MessageBusConfigurator cfg, string name)
        {
            if (string.IsNullOrEmpty(cfg.Endpoint))
            {
                throw new Exception("Endpoint not set");
            }
            var cs = cfg.GetConnectionStrings();



            cfg.CustomizeContainer(wc =>
            {
                wc.Register(Component.For <IMessageTransport, IStartableService, IHealthCheck>()
                            .ImplementedBy <MongoDBTransport>()
                            .DependsOn(new
                {
                    ConnectionStrings      = cs,
                    Endpoint               = cfg.Endpoint,
                    MessageRetentionPeriod = cfg.MessageRetentionPeriod,
                    MessageLockTimeSec     = 300,
                    MaxConcurrentMessages  = cfg.MaxConcurrentReceivers
                }).LifeStyle.Singleton.Named("MessageTransport_" + name));

                wc.Register(Component.For <IMessageBus>()
                            .ImplementedBy <NGinnBPM.MessageBus.Impl.MessageBus>()
                            .DependsOn(new
                {
                    BatchOutgoingMessagesInTransaction = cfg.BatchOutMessages,
                    UseTransactionScope   = cfg.UseTransactionScope,
                    PublishLocalByDefault = cfg.AlwaysPublishLocal
                })
                            .Parameters(Parameter.ForKey("transport").Eq("${MessageTransport_" + name + "}"))
                            .LifeStyle.Singleton);
            });


            return(cfg);
        }
Esempio n. 22
0
 protected override void OnStart(string[] args)
 {
     string componentConfig = ConfigurationManager.AppSettings["NGinnMessageBus.ServiceHost.ComponentConfig"];
     bool section = ConfigurationManager.GetSection(componentConfig) != null;
     WindsorContainer wc = null;
     if (!string.IsNullOrEmpty(componentConfig))
     {
         if (section)
         {
             wc = new WindsorContainer(new XmlInterpreter(new ConfigResource(componentConfig)));
         }
         else if (Path.GetExtension(componentConfig) == "xml" || Path.GetExtension(componentConfig) == ".xml")
         {
             log.Info("Configuring the container from xml file: {0}", componentConfig);
             wc = new WindsorContainer(new XmlInterpreter(new FileResource(componentConfig, AppDomain.CurrentDomain.BaseDirectory)));
         }
         else throw new Exception("Don't know how to load config: " + componentConfig);
     }
     else wc = new WindsorContainer();
     _host = MessageBusConfigurator.Begin(wc)
         .ConfigureFromAppConfig()
         .AutoStartMessageBus(true)
         .FinishConfiguration();
 }
Esempio n. 23
0
 public static MessageBusConfigurator UseMongoDbTransport(this MessageBusConfigurator cfg)
 {
     return(UseMongoDbTransport(cfg, "mongodb"));
 }
Esempio n. 24
0
 public static void Shutdown(IWindsorContainer wc)
 {
     MessageBusConfigurator.StopMessageBus(wc);
 }
Esempio n. 25
0
 public static MessageBusConfigurator UseMongoDbSagaRepository(this MessageBusConfigurator cfg)
 {
     return(UseMongoDbSagaRepository(cfg, "NG_Saga"));
 }