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(); } }
public async Task SubscriptionWorker_ConnectionDroppedAndIsRestablished() { CancellationToken cancellationToken = CancellationToken.None; SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString, this.domainEventHandlerResolver.Object, this.SubscriptionRepository, 200, 1).UseInMemory(); await sw.StartAsync(cancellationToken); //Give our service time to run await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); sw.IsRunning.ShouldBeTrue(); var connected = sw.GetPersistentSubscription(); var originalCount = connected.Count; //Drop the connection connected[0].SubscriptionDropped("Test"); var stillConnected = sw.GetPersistentSubscription(); stillConnected.Count().ShouldBe(originalCount - 1); //One less than original //Wait for n seconds on reconnect await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); stillConnected = sw.GetPersistentSubscription(); stillConnected.Count().ShouldBe(originalCount); //One less than original }
public void SubscriptionWorker_CanBeCreated_IsCreated() { SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString, this.domainEventHandlerResolver.Object, this.SubscriptionRepository).UseInMemory(); sw.ShouldNotBeNull(); sw.InflightMessages.ShouldBe(200); sw.PersistentSubscriptionPollingInSeconds.ShouldBe(60); }
public void SubscriptionWorker_DefaultValues_WorkerCreated() { Task <List <PersistentSubscriptionInfo> > getSubscriptions = new(TestData.GetPersistentSubscriptions_DemoEstate); String eventStoreConnectionString = "esdb://*****:*****@192.168.1.133:2113?tls=false&tlsVerifyCert=false"; ISubscriptionRepository subscriptionService = SubscriptionRepository.Create(getSubscriptions); SubscriptionWorker concurrentSubscriptions = SubscriptionWorker.CreateConcurrentSubscriptionWorker(eventStoreConnectionString, this.domainEventHandlerResolver.Object, subscriptionService); concurrentSubscriptions.FilterSubscriptions.ShouldBeNull(); concurrentSubscriptions.IgnoreSubscriptions.ShouldBe("local-"); concurrentSubscriptions.StreamNameFilter.ShouldBeNull(); concurrentSubscriptions.InflightMessages.ShouldBe(200); concurrentSubscriptions.IsOrdered.ShouldBeFalse(); }
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(); }
public async Task SubscriptionWorker_CanBeStartedAndStopped() { CancellationToken cancellationToken = CancellationToken.None; SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString, this.domainEventHandlerResolver.Object, this.SubscriptionRepository).UseInMemory(); await sw.StartAsync(cancellationToken); //Give our service time to run await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); sw.IsRunning.ShouldBeTrue(); await sw.StopAsync(cancellationToken); sw.IsRunning.ShouldBe(false); var stillConnected = sw.GetPersistentSubscription().Count; stillConnected.ShouldBe(0); }
public async Task SubscriptionWorker_CanBeCreatedAndReceiveEvents() { CancellationToken cancellationToken = CancellationToken.None; TestDomainEventHandler eventHandler1 = new(); Int32 inflight = 200; Int32 pollingInSeconds = 60; this.domainEventHandlerResolver.Setup(d => d.GetDomainEventHandlers(It.IsAny <IDomainEvent>())).Returns(new List <IDomainEventHandler>() { eventHandler1 }); SubscriptionWorker sw = SubscriptionWorker.CreateConcurrentSubscriptionWorker(this.EventStoreConnectionString, this.domainEventHandlerResolver.Object, this.SubscriptionRepository, inflight, pollingInSeconds).UseInMemory(); await sw.StartAsync(cancellationToken); //Give our service time to run await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); sw.IsRunning.ShouldBeTrue(); PersistentSubscription ps = sw.GetPersistentSubscription()[0]; String @event = "{\r\n \"estateId\": \"4fc2692f-067a-443e-8006-335bf2732248\",\r\n \"estateName\": \"Demo Estate\"\r\n}\t"; ps.Connected.ShouldBeTrue(); ps.PersistentSubscriptionDetails.InflightMessages.ShouldBe(inflight); //Manually add events. ((InMemoryPersistentSubscriptionsClient)ps.PersistentSubscriptionsClient).WriteEvent(@event, "EstateCreatedEvent", cancellationToken); eventHandler1.DomainEvents.Count.ShouldBe(1); }