public EbBaseService(IMessageProducer _mqp, IMessageQueueClient _mqc, IServerEvents _se) { this.MessageProducer3 = _mqp as RabbitMqProducer; this.MessageQueueClient = _mqc as RabbitMqQueueClient; this.ServerEvents = _se as RedisServerEvents; }
public override ServiceStackHost Init() { ServicePointManager.UseNagleAlgorithm = false; ServicePointManager.DefaultConnectionLimit = 1000; var conf = NLog.Config.ConfigurationItemFactory.Default; conf.LayoutRenderers.RegisterDefinition("logsdir", typeof(LogsDir)); conf.LayoutRenderers.RegisterDefinition("Domain", typeof(Library.Logging.Domain)); NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration($"{AppDomain.CurrentDomain.BaseDirectory}/logging.config"); LogManager.LogFactory = new global::ServiceStack.Logging.NLogger.NLogFactory(); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; AppDomain.CurrentDomain.FirstChanceException += ExceptionTrapper; NServiceBus.Logging.LogManager.Use <NServiceBus.NLogFactory>(); IRedisClientsManager redisClient = null; ICacheClient cacheClient; IServerEvents serverEvents; var connectionString = ConfigurationManager.ConnectionStrings["Redis"]; if (connectionString == null) { cacheClient = new MemoryCacheClient(); serverEvents = new MemoryServerEvents { IdleTimeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false }; } else { redisClient = new BasicRedisClientManager(connectionString.ConnectionString); cacheClient = new RedisClientManagerCacheClient(redisClient); serverEvents = new RedisServerEvents(redisClient) { Timeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false, }; } IDbConnectionFactory sql = null; var connectionStringSQL = ConfigurationManager.ConnectionStrings["SQL"]; if (connectionStringSQL != null) { sql = new OrmLiteConnectionFactory(connectionStringSQL.ConnectionString, SqlServer2012Dialect.Provider) { ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current) }; } _container = new Container(x => { if (redisClient != null) { x.For <IRedisClientsManager>().Use(redisClient); } if (sql != null) { x.For <IDbConnectionFactory>().Use(sql); x.For <ISubscriptionStorage>().Use <MSSQLStorage>(); } else { x.For <ISubscriptionStorage>().Use <MemoryStorage>(); } x.For <IManager>().Use <Manager>(); x.For <IFuture>().Use <Future>().Singleton(); x.For <ICacheClient>().Use(cacheClient); x.For <IServerEvents>().Use(serverEvents); x.For <ISubscriptionManager>().Use <SubscriptionManager>().Singleton(); x.Scan(y => { AllAssemblies.Matching("Presentation.ServiceStack").ToList().ForEach(a => y.Assembly(a)); y.WithDefaultConventions(); y.AddAllTypesOf <ISetup>(); }); }); // Do this before bus starts InitiateSetup(); SetupApplication(); var config = new BusConfiguration(); Logger.Info("Initializing Service Bus"); config.LicensePath(ConfigurationManager.AppSettings["license"]); var endpoint = ConfigurationManager.AppSettings["endpoint"]; if (string.IsNullOrEmpty(endpoint)) { endpoint = "application.servicestack"; } config.EndpointName(endpoint); config.EnableInstallers(); config.UsePersistence <InMemoryPersistence>(); config.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(_container)); config.DisableFeature <Sagas>(); config.DisableFeature <SecondLevelRetries>(); // Important to not subscribe to messages as we receive them from the event store config.DisableFeature <AutoSubscribe>(); config.UseTransport <RabbitMQTransport>() .CallbackReceiverMaxConcurrency(36) .UseDirectRoutingTopology() .ConnectionStringName("RabbitMq"); config.Transactions().DisableDistributedTransactions(); //config.DisableDurableMessages(); config.UseSerialization <NewtonsoftSerializer>(); config.EnableFeature <Aggregates.Feature>(); if (Logger.IsDebugEnabled) { config.Pipeline.Register <LogIncomingRegistration>(); } var bus = Bus.Create(config).Start(); _container.Configure(x => x.For <IBus>().Use(bus).Singleton()); return(base.Init()); }
public override ServiceStackHost Init() { ServicePointManager.UseNagleAlgorithm = false; ServicePointManager.DefaultConnectionLimit = 1000; var conf = NLog.Config.ConfigurationItemFactory.Default; conf.LayoutRenderers.RegisterDefinition("logsdir", typeof(LogsDir)); conf.LayoutRenderers.RegisterDefinition("Instance", typeof(Library.Logging.Instance)); NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration($"{AppDomain.CurrentDomain.BaseDirectory}/logging.config"); LogManager.LogFactory = new global::ServiceStack.Logging.NLogger.NLogFactory(); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; AppDomain.CurrentDomain.FirstChanceException += ExceptionTrapper; NServiceBus.Logging.LogManager.Use <NServiceBus.NLogFactory>(); IRedisClientsManager redisClient = null; ICacheClient cacheClient; IServerEvents serverEvents; var connectionString = ConfigurationManager.ConnectionStrings["Redis"]; if (connectionString == null) { cacheClient = new MemoryCacheClient(); serverEvents = new MemoryServerEvents { IdleTimeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false }; } else { redisClient = new BasicRedisClientManager(connectionString.ConnectionString); cacheClient = new RedisClientManagerCacheClient(redisClient); serverEvents = new RedisServerEvents(redisClient) { Timeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false, }; } IDbConnectionFactory sql = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider); var connectionStringSql = ConfigurationManager.ConnectionStrings["SQL"]; if (connectionStringSql != null) { sql = new OrmLiteConnectionFactory(connectionStringSql.ConnectionString, SqlServer2012Dialect.Provider) { ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current) }; } var pulse = ConfigureDemo(); var rabbit = ConfigureRabbit(); ConfigureMetrics(); _container = new Container(x => { if (redisClient != null) { x.For <IRedisClientsManager>().Use(redisClient); } x.For <IDbConnectionFactory>().Use(sql); x.For <ISubscriptionStorage>().Use <MssqlStorage>(); x.For <IManager>().Use <Manager>(); x.For <IFuture>().Use <Future>().Singleton(); x.For <ICacheClient>().Use(cacheClient); x.For <IServerEvents>().Use(serverEvents); x.For <ISubscriptionManager>().Use <SubscriptionManager>().Singleton(); x.For <IDemo>().Use(pulse); x.For <IConnection>().Use(rabbit); x.Scan(y => { y.TheCallingAssembly(); y.AssembliesFromApplicationBaseDirectory((assembly) => assembly.FullName.StartsWith("Presentation.ServiceStack")); y.WithDefaultConventions(); y.AddAllTypesOf <ISetup>(); y.AddAllTypesOf <ICommandMutator>(); y.ConnectImplementationsToTypesClosing(typeof(Q.IChange <,>)); }); }); // Do this before bus starts InitiateSetup(); SetupApplication().Wait(); var bus = InitBus().Result; _container.Configure(x => x.For <IMessageSession>().Use(bus).Singleton()); return(base.Init()); }