private EventStoreMarker GetMarker() { EventStoreMarker marker; if (!_markerReader.TryGet(_queueName, out marker)) marker = new EventStoreMarker(); return marker; }
private void PerformDistribution(CancellationToken token) { while (!token.IsCancellationRequested) { var envelopes = _eventStore .LoadSince(_lastKnownDispatchSituation.Stamp); bool thereWasSomethingNew = false; foreach (var envelope in envelopes) { var envelopeStamp = envelope.GetStamp(); var envelopeUniqueId = envelope.GetUniqueId(); if (_lastKnownDispatchSituation.KnownMessagesWithinStamp.Contains(envelopeUniqueId)) continue; thereWasSomethingNew = true; if (_lastKnownDispatchSituation.Stamp != envelopeStamp) _lastKnownDispatchSituation = new EventStoreMarker(envelopeStamp); _lastKnownDispatchSituation.KnownMessagesWithinStamp.Add(envelopeUniqueId); _queueWriter.Enqueue(_serializer.Serialize(envelope)); } if (thereWasSomethingNew) { _markerWriter.AddOrReplace(_queueName, _lastKnownDispatchSituation); } else { Thread.Sleep(500); } } }
public void Run(CancellationToken token) { _lastKnownDispatchSituation = GetMarker(); PerformDistribution(token); }