public RedisServerEvents(IRedisPubSubServer redisPubSub) { this.RedisPubSub = redisPubSub; this.clientsManager = redisPubSub.ClientsManager; redisPubSub.OnInit = OnInit; redisPubSub.OnError = ex => Log.Error("Exception in RedisServerEvents: " + ex.Message, ex); redisPubSub.OnMessage = HandleMessage; KeepAliveRetryAfterMs = 2000; local = new MemoryServerEvents { NotifyJoin = HandleOnJoin, NotifyLeave = HandleOnLeave, NotifyHeartbeat = HandleOnHeartbeat, Serialize = HandleSerialize, }; var appHost = HostContext.AppHost; var feature = appHost != null ? appHost.GetPlugin<ServerEventsFeature>() : null; if (feature != null) { Timeout = feature.IdleTimeout; OnSubscribe = feature.OnSubscribe; OnUnsubscribe = feature.OnUnsubscribe; NotifyChannelOfSubscriptions = feature.NotifyChannelOfSubscriptions; } }
public RedisServerEvents(IRedisPubSubServer redisPubSub) { this.RedisPubSub = redisPubSub; this.clientsManager = redisPubSub.ClientsManager; redisPubSub.OnInit = OnInit; redisPubSub.OnError = ex => Log.Error("Exception in RedisServerEvents: " + ex.Message, ex); redisPubSub.OnMessage = HandleMessage; WaitBeforeNextRestart = TimeSpan.FromMilliseconds(2000); local = new MemoryServerEvents { NotifyJoin = HandleOnJoin, NotifyLeave = HandleOnLeave, NotifyHeartbeat = HandleOnHeartbeat, Serialize = HandleSerialize, }; var appHost = HostContext.AppHost; var feature = appHost != null ? appHost.GetPlugin<ServerEventsFeature>() : null; if (feature != null) { Timeout = feature.IdleTimeout; HouseKeepingInterval = feature.HouseKeepingInterval; OnSubscribe = feature.OnSubscribe; OnUnsubscribe = feature.OnUnsubscribe; NotifyChannelOfSubscriptions = feature.NotifyChannelOfSubscriptions; } }
public void Register(IAppHost appHost) { var container = appHost.GetContainer(); if (!container.Exists <IServerEvents>()) { var broker = new MemoryServerEvents { IdleTimeout = IdleTimeout, HouseKeepingInterval = HouseKeepingInterval, OnSubscribe = OnSubscribe, OnUnsubscribe = OnUnsubscribe, NotifyChannelOfSubscriptions = NotifyChannelOfSubscriptions, //OnError = OnError, }; container.Register <IServerEvents>(broker); } appHost.RawHttpHandlers.Add(httpReq => httpReq.PathInfo.EndsWith(StreamPath) ? (IHttpHandler) new ServerEventsHandler() : httpReq.PathInfo.EndsWith(HeartbeatPath) ? new ServerEventsHeartbeatHandler() : null); if (UnRegisterPath != null) { appHost.RegisterService(typeof(ServerEventsUnRegisterService), UnRegisterPath); } if (SubscribersPath != null) { appHost.RegisterService(typeof(ServerEventsSubscribersService), SubscribersPath); } }
public override ServiceStackHost Init() { log4net.Config.XmlConfigurator.Configure(); LogManager.LogFactory = new Log4NetFactory(); NServiceBus.Logging.LogManager.Use <NServiceBus.Log4Net.Log4NetFactory>(); var serverEvents = new MemoryServerEvents { IdleTimeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false }; _container = new Container(x => { x.For <IManager>().Use <Manager>(); x.For <ICacheClient>().Use(new MemoryCacheClient()); x.For <IServerEvents>().Use(serverEvents); x.For <ISubscriptionManager>().Use <MemorySubscriptionManager>(); }); var config = new BusConfiguration(); //var conventions = config.Conventions(); //conventions // .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Events")) // .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Commands")) // .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && (t.Namespace.EndsWith("Messages") || t.Namespace.EndsWith("Queries"))); config.LicensePath(@"C:\License.xml"); config.EndpointName("Presentation"); config.EndpointVersion("0.0.0"); //config.AssembliesToScan(AllAssemblies.Matching("Presentation").And("Application").And("Domain").And("Library")); config.UsePersistence <InMemoryPersistence>(); config.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(_container)); config.UseSerialization <NServiceBus.JsonSerializer>(); var bus = Bus.Create(config).Start(); _container.Configure(x => x.For <IBus>().Use(bus).Singleton()); return(base.Init()); }
public void Dispose() { if (RedisPubSub != null) RedisPubSub.Dispose(); if (local != null) local.Dispose(); RedisPubSub = null; local = null; }
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() { LogManager.LogFactory = new Log4NetFactory(true); NServiceBus.Logging.LogManager.Use<NServiceBus.Log4Net.Log4NetFactory>(); var serverEvents = new MemoryServerEvents { IdleTimeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false }; var store = ConfigureStore(); var elastic = ConfigureElastic(); var eventstore = ConfigureEventStore(); _container = new Container(x => { x.For<IManager>().Use<Manager>(); x.For<ICacheClient>().Use(new MemoryCacheClient()); x.For<IServerEvents>().Use(serverEvents); x.For<ISubscriptionManager>().Use<MemorySubscriptionManager>(); x.For<IDocumentStore>().Use(store).Singleton(); x.For<IElasticClient>().Use(elastic).Singleton(); x.For<IEventStoreConnection>().Use(eventstore).Singleton(); x.For<IQueryProcessor>().Use<QueryProcessor>(); x.For<IPersistCheckpoints>().Use<RavenCheckpointPersister>(); x.Scan(y => { AllAssemblies.Matching("Application").ToList().ForEach(a => y.Assembly(a)); y.WithDefaultConventions(); y.ConnectImplementationsToTypesClosing(typeof(IQueryHandler<,>)); y.ConnectImplementationsToTypesClosing(typeof(IPagingQueryHandler<,>)); }); }); var config = new BusConfiguration(); //var conventions = config.Conventions(); //conventions // .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Events")) // .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Commands")) // .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && (t.Namespace.EndsWith("Messages") || t.Namespace.EndsWith("Queries"))); config.LicensePath(@"C:\License.xml"); var endpoint = ConfigurationManager.AppSettings["endpoint"]; if (string.IsNullOrEmpty(endpoint)) endpoint = "application.servicestack"; config.EndpointName(endpoint); //config.AssembliesToScan(AllAssemblies.Matching("Presentation").And("Application").And("Domain").And("Library")); config.UsePersistence<InMemoryPersistence>(); config.UseContainer<StructureMapBuilder>(c => c.ExistingContainer(_container)); config.UseSerialization<NServiceBus.JsonSerializer>(); config.EnableInstallers(); config.EnableFeature<Aggregates.EventStore>(); config.EnableFeature<Aggregates.DurableConsumer>(); 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()); }
public override ServiceStackHost Init() { LogManager.LogFactory = new Log4NetFactory(true); NServiceBus.Logging.LogManager.Use <NServiceBus.Log4Net.Log4NetFactory>(); var serverEvents = new MemoryServerEvents { IdleTimeout = TimeSpan.FromSeconds(30), NotifyChannelOfSubscriptions = false }; var store = ConfigureStore(); var elastic = ConfigureElastic(); var eventstore = ConfigureEventStore(); _container = new Container(x => { x.For <IManager>().Use <Manager>(); x.For <ICacheClient>().Use(new MemoryCacheClient()); x.For <IServerEvents>().Use(serverEvents); x.For <ISubscriptionManager>().Use <MemorySubscriptionManager>(); x.For <IDocumentStore>().Use(store).Singleton(); x.For <IElasticClient>().Use(elastic).Singleton(); x.For <IEventStoreConnection>().Use(eventstore).Singleton(); x.For <IQueryProcessor>().Use <QueryProcessor>(); x.For <IPersistCheckpoints>().Use <RavenCheckpointPersister>(); x.Scan(y => { AllAssemblies.Matching("Application").ToList().ForEach(a => y.Assembly(a)); y.WithDefaultConventions(); y.ConnectImplementationsToTypesClosing(typeof(IQueryHandler <,>)); y.ConnectImplementationsToTypesClosing(typeof(IPagingQueryHandler <,>)); }); }); var config = new BusConfiguration(); //var conventions = config.Conventions(); //conventions // .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Events")) // .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && t.Namespace.EndsWith("Commands")) // .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.StartsWith("Demo") && (t.Namespace.EndsWith("Messages") || t.Namespace.EndsWith("Queries"))); config.LicensePath(@"C:\License.xml"); var endpoint = ConfigurationManager.AppSettings["endpoint"]; if (string.IsNullOrEmpty(endpoint)) { endpoint = "application.servicestack"; } config.EndpointName(endpoint); //config.AssembliesToScan(AllAssemblies.Matching("Presentation").And("Application").And("Domain").And("Library")); config.UsePersistence <InMemoryPersistence>(); config.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(_container)); config.UseSerialization <NServiceBus.JsonSerializer>(); config.EnableInstallers(); config.EnableFeature <Aggregates.EventStore>(); config.EnableFeature <Aggregates.DurableConsumer>(); var bus = Bus.Create(config).Start(); _container.Configure(x => x.For <IBus>().Use(bus).Singleton()); return(base.Init()); }