コード例 #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)));
                }
            });
        }
コード例 #2
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);
        }