public void CreateAccountEventIsPublishedToBus() { using (MassTransitDispatcher massTransitDispatcher = new MassTransitDispatcher(bus)) { PollingClient pollingClient = new PollingClient(store.Advanced, 100); IObserveCommits commitObserver = pollingClient.ObserveFrom(null); IEventHandler <SimpleAggregateCreated> denormalizer = A.Fake <IEventHandler <SimpleAggregateCreated> >(); AutoResetEvent are = new AutoResetEvent(false); A.CallTo(() => denormalizer.Handle(A <SimpleAggregateCreated> .Ignored)).Invokes(() => are.Set()); bus.Subscribe(denormalizer); using (PollingHook pollingHook = new PollingHook(commitObserver)) { using (var subscription = commitObserver.Subscribe(massTransitDispatcher)) { commitObserver.PollNow(); commitObserver.Start(); Guid aggregateID = Guid.NewGuid(); SimpleAggregate aggregate = new SimpleAggregate(aggregateID, DateTime.Now); repository.Save(aggregate, Guid.NewGuid(), (o) => { }); are.WaitOne(10000).Should().BeTrue("event should be dispatched and recieved within timeout"); } } } }
public IObserveCommits Construct() { var pollingClient = new PollingClient(_eventStore.Advanced); var checkpoint = _checkpointTracker.GetCheckpoint(); var subscription = pollingClient.ObserveFrom(checkpoint); var started = DateTime.UtcNow; var liveNotification = subscription .SkipWhile(commit => commit.CommitStamp < started) .Cast <object>() .Merge(subscription.Throttle(TimeSpan.FromSeconds(5)).Select(_ => new SubscriptionIsLive())) .Take(1) .Select(_ => new SubscriptionIsLive()); var subscriptionWithLiveNotification = subscription .Cast <object>() .Merge(liveNotification); foreach (var commitObserver in _commitObservers) { subscriptionWithLiveNotification.Subscribe(commitObserver); } if (checkpoint == NullCheckpointToken.Value) { subscription.Start(); } return(subscription); }
protected override void Context() { for (int c = 1; c <= ParallelWriters; c++) { var client = new AcceptanceTestMongoPersistenceFactory().Build(); if (c == 1) { client.Drop(); client.Initialize(); } _writers.Add(client); } _observer = new Observer(); var reader = new AcceptanceTestMongoPersistenceFactory().Build(); _client = new PollingClient(reader, PollingInterval); _observeCommits = _client.ObserveFrom(null); _subscription = _observeCommits.Subscribe(_observer); _observeCommits.Start(); }
protected override void Context() { base.Context(); StoreEvents.Advanced.CommitSingle(); _observeCommits = PollingClient.ObserveFrom(); _commitObserved = _observeCommits.FirstAsync().ToTask(); }
protected override void Context() { base.Context(); StoreEvents.Advanced.CommitSingle(); _observeCommits = PollingClient.ObserveFrom(); _twoCommitsObserved = _observeCommits.Take(2).ToTask(); }
public async Task CreateAccountEventIsPublishedToBus() { MassTransitDispatcher massTransitDispatcher = new MassTransitDispatcher(bus); PollingClient pollingClient = new PollingClient(store.Advanced, 100); IObserveCommits commitObserver = pollingClient.ObserveFrom(null); AccountDenormalizer denormalizer = new AccountDenormalizer(); bus.Subscribe(denormalizer); using (PollingHook pollingHook = new PollingHook(commitObserver)) { using (var subscription = commitObserver.Subscribe(massTransitDispatcher)) { commitObserver.PollNow(); commitObserver.Start(); Guid accountID = Guid.NewGuid(); string name = Guid.NewGuid().ToString(); string twitter = Guid.NewGuid().ToString(); System.Diagnostics.Debug.Print(string.Format("Creating account {0}", accountID)); client.CreateNewAccount(accountID, name, twitter); DateTime timeoutEnd = DateTime.Now.AddSeconds(10); while (denormalizer.AccountName != name && DateTime.Now < timeoutEnd) { await Task.Delay(100); } denormalizer.AccountName.Should().Be(name); } } }
protected override void Context() { base.Context(); StoreEvents.Advanced.CommitMany(4, null, "bucket_2"); StoreEvents.Advanced.CommitMany(4, null, "bucket_1"); _observeCommits = PollingClient.ObserveFrom(); _commitObserved = _observeCommits.FirstAsync().ToTask(); }
protected override void Context() { base.Context(); StoreEvents.Advanced.CommitSingle(); _observeCommits1 = PollingClient.ObserveFrom(); _observeCommits1Complete = _observeCommits1.Take(5).ToTask(); _observeCommits2Complete = _observeCommits1.Take(10).ToTask(); }
private void StartSubscribing(IObserver <ICommit> observer, string checkPointToken = null, int interval = 5000) { var pc = new PollingClient(_store.Advanced, interval); var commitObserver = pc.ObserveFrom(checkPointToken); _pipeLineHook.Subscribe(commitObserver); commitObserver.Subscribe(observer); commitObserver.Start(); }
private void Polling(IStoreEvents store) { var pollingClient = new PollingClient(store.Advanced, 5000); var observeCommits = pollingClient.ObserveFrom("0"); var eventStreamObserver = new EventStreamObserver(); observeCommits.Subscribe(eventStreamObserver); GlobalTimer.Timer.Start(); observeCommits.Start(); }
public IObserveCommits Construct() { var pollingClient = new PollingClient(eventStore.Advanced); var checkpoint = checkpointRepo.LoadCheckpoint(); IObserveCommits subscription = pollingClient.ObserveFrom(checkpoint); foreach (var commitObserver in commitObservers) { subscription.Subscribe(commitObserver); } return(subscription); }
public void Start() { var start = _tracker.LoadCheckpoint(); var client = new PollingClient(_eventStore.Advanced, 1000); var dispatcher = new CommitsDispatcher(_tracker, Logger); _observer = client.ObserveFrom(start); _subscription = _observer.Subscribe(dispatcher); _observer.Start(); Logger.InfoFormat("Projection engine started from {0}", start); }
public async Task TyingItTogether() { var denormalizer = new AccountDenormalizer(); bus.Subscribe(denormalizer); bus.Subscribe(new KaChingNotifier()); bus.Subscribe(new OmgSadnessNotifier()); var massTransitDispatcher = new MassTransitDispatcher(bus); var pollingClient = new PollingClient(store.Advanced, 100); var commitObserver = pollingClient.ObserveFrom(null); using (PollingHook pollingHook = new PollingHook(commitObserver)) { using (var subscription = commitObserver.Subscribe(massTransitDispatcher)) { commitObserver.PollNow(); commitObserver.Start(); Guid accountID = Guid.NewGuid(); string name = Guid.NewGuid().ToString(); string twitter = Guid.NewGuid().ToString(); client.CreateNewAccount(accountID, name, twitter); client.CloseAccount(accountID); DateTime timeoutEnd = DateTime.Now.AddSeconds(10); while ((denormalizer.AccountName != name || denormalizer.IsActive) && DateTime.Now < timeoutEnd) { await Task.Delay(100); } denormalizer.AccountName.Should().Be(name); denormalizer.IsActive.Should().Be(false); store.OpenStream(accountID, 0, int.MaxValue).CommittedEvents.Count.Should().Be(2); } } }
private static void Main() { using (var store = WireupEventStore()) { var client = new PollingClient(store.Advanced); string checkpointToken = LoadCheckpoint(); using (IObserveCommits observeCommits = client.ObserveFrom(checkpointToken)) using (observeCommits.Subscribe(commit => { // Project the commit etc Console.WriteLine(Resources.CommitInfo, commit.BucketId, commit.StreamId, commit.CommitSequence); // Track the most recent checkpoint checkpointToken = commit.CheckpointToken; })) { observeCommits.Start(); Console.WriteLine(Resources.PressAnyKey); Console.ReadKey(); SaveCheckpoint(checkpointToken); } } }