Example #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)));
                }
            });
        }
Example #2
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);
 }
Example #3
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);
        }
Example #4
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);
 }
Example #5
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);
        }