public static void PreWarm(this IApplicationBuilder applicationBuilder) { Startup.LoadTypes(); var internalSubscriptionService = bool.Parse(ConfigurationReader.GetValue("InternalSubscriptionService")); if (internalSubscriptionService) { String eventStoreConnectionString = ConfigurationReader.GetValue("EventStoreSettings", "ConnectionString"); Int32 inflightMessages = int.Parse(ConfigurationReader.GetValue("AppSettings", "InflightMessages")); Int32 persistentSubscriptionPollingInSeconds = int.Parse(ConfigurationReader.GetValue("AppSettings", "PersistentSubscriptionPollingInSeconds")); String filter = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceFilter"); String ignore = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceIgnore"); String streamName = ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionFilterOnStreamName"); Int32 cacheDuration = int.Parse(ConfigurationReader.GetValue("AppSettings", "InternalSubscriptionServiceCacheDuration")); ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(eventStoreConnectionString, cacheDuration); ((SubscriptionRepository)subscriptionRepository).Trace += (sender, s) => Extensions.log(TraceEventType.Information, "REPOSITORY", s); // init our SubscriptionRepository subscriptionRepository.PreWarm(CancellationToken.None).Wait(); var eventHandlerResolver = Startup.ServiceProvider.GetService <IDomainEventHandlerResolver>(); SubscriptionWorker concurrentSubscriptions = SubscriptionWorker.CreateConcurrentSubscriptionWorker(eventStoreConnectionString, eventHandlerResolver, subscriptionRepository, inflightMessages, persistentSubscriptionPollingInSeconds); concurrentSubscriptions.Trace += (_, args) => Extensions.concurrentLog(TraceEventType.Information, args.Message); concurrentSubscriptions.Warning += (_, args) => Extensions.concurrentLog(TraceEventType.Warning, args.Message); concurrentSubscriptions.Error += (_, args) => Extensions.concurrentLog(TraceEventType.Error, args.Message); if (!string.IsNullOrEmpty(ignore)) { concurrentSubscriptions = concurrentSubscriptions.IgnoreSubscriptions(ignore); } if (!string.IsNullOrEmpty(filter)) { //NOTE: Not overly happy with this design, but //the idea is if we supply a filter, this overrides ignore concurrentSubscriptions = concurrentSubscriptions.FilterSubscriptions(filter).IgnoreSubscriptions(null); } if (!string.IsNullOrEmpty(streamName)) { concurrentSubscriptions = concurrentSubscriptions.FilterByStreamName(streamName); } concurrentSubscriptions.StartAsync(CancellationToken.None).Wait(); } }
static async Task SubscriptionsTest() { String eventStoreConnectionString = "esdb://127.0.0.1:2113?tls=false"; Int32 inflightMessages = 1; Int32 persistentSubscriptionPollingInSeconds = 10; String filter = String.Empty; String ignore = String.Empty; String streamName = String.Empty; Int32 cacheDuration = 0; ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(eventStoreConnectionString, cacheDuration); //((SubscriptionRepository)subscriptionRepository).Trace += (sender, s) => Extensions.log(TraceEventType.Information, "REPOSITORY", s); // init our SubscriptionRepository subscriptionRepository.PreWarm(CancellationToken.None).Wait(); IDomainEventHandlerResolver eventHandlerResolver = new DomainEventHandlerResolver(new Dictionary <String, String[]>(), null); SubscriptionWorker concurrentSubscriptions = SubscriptionWorker.CreateConcurrentSubscriptionWorker(Program.ConfigureEventStoreSettings(), eventHandlerResolver, subscriptionRepository, inflightMessages, persistentSubscriptionPollingInSeconds); //concurrentSubscriptions.Trace += (_, args) => Extensions.concurrentLog(TraceEventType.Information, args.Message); //concurrentSubscriptions.Warning += (_, args) => Extensions.concurrentLog(TraceEventType.Warning, args.Message); //concurrentSubscriptions.Error += (_, args) => Extensions.concurrentLog(TraceEventType.Error, args.Message); if (!String.IsNullOrEmpty(ignore)) { concurrentSubscriptions = concurrentSubscriptions.IgnoreSubscriptions(ignore); } if (!String.IsNullOrEmpty(filter)) { //NOTE: Not overly happy with this design, but //the idea is if we supply a filter, this overrides ignore concurrentSubscriptions = concurrentSubscriptions.FilterSubscriptions(filter) .IgnoreSubscriptions(null); } if (!String.IsNullOrEmpty(streamName)) { concurrentSubscriptions = concurrentSubscriptions.FilterByStreamName(streamName); } concurrentSubscriptions.StartAsync(CancellationToken.None).Wait(); }