private void EventAppeared(EventStorePersistentSubscriptionBase sub, ResolvedEvent e) { _token.ThrowIfCancellationRequested(); Logger.Write(LogLevel.Debug, () => $"Delayed event appeared {e.Event.EventId} type {e.Event.EventType} stream [{e.Event.EventStreamId}] number {e.Event.EventNumber} projection event number {e.OriginalEventNumber}"); Queued.Increment(Id); lock (_lock) _waitingEvents.Add(e); }
public void Acknowledge(ResolvedEvent @event) { if (!Live) { throw new InvalidOperationException("Cannot ACK an event, subscription is dead"); } Processed.Increment(Id); _idleContext.Dispose(); _toAck.Add(@event); }
public DelayedClient(IEventStoreConnection client, string stream, string group, int maxDelayed, CancellationToken token) { _client = client; _stream = stream; _group = group; _maxDelayed = maxDelayed; _token = token; _toAck = new List <ResolvedEvent>(); _lock = new object(); _waitingEvents = new List <ResolvedEvent>(); _acknowledger = Timer.Repeat(state => { var info = (DelayedClient)state; var toAck = Interlocked.Exchange(ref _toAck, new List <ResolvedEvent>()); if (!toAck.Any()) { return(Task.CompletedTask); } if (!info.Live) { return(Task.CompletedTask); } Acknowledged.Increment(Id, toAck.Count); Logger.Write(LogLevel.Info, () => $"Acknowledging {toAck.Count} events to {Id}"); var page = 0; while (page < toAck.Count) { var working = toAck.Skip(page).Take(2000); info._subscription.Acknowledge(working); page += 2000; } return(Task.CompletedTask); }, this, TimeSpan.FromSeconds(30), token, "delayed event acknowledger"); _client.Connected += _client_Connected; }
public PersistentClient(IEventStoreConnection client, string stream, string group, int readsize, int index, CancellationToken token) { _client = client; _stream = stream; _group = group; _index = index; _readsize = readsize; _token = token; _toAck = new List <ResolvedEvent>(); _waitingEvents = new ConcurrentQueue <ResolvedEvent>(); _acknowledger = Timer.Repeat(state => { var info = (PersistentClient)state; ResolvedEvent[] toAck = Interlocked.Exchange(ref _toAck, new List <ResolvedEvent>()).ToArray(); if (!toAck.Any()) { return(Task.CompletedTask); } if (!info.Live) { return(Task.CompletedTask); } //throw new InvalidOperationException( // "Subscription was stopped while events were waiting to be ACKed"); Acknowledged.Increment(Id, toAck.Length); Logger.Write(LogLevel.Info, () => $"Acknowledging {toAck.Length} events to {Id}"); var page = 0; while (page < toAck.Length) { var working = toAck.Skip(page).Take(2000); info._subscription.Acknowledge(working); page += 2000; } return(Task.CompletedTask); }, this, TimeSpan.FromSeconds(30), token, "event acknowledger"); _client.Connected += _client_Connected; }
public void Acknowledge(ResolvedEvent[] events) { Processed.Increment(Id); _idleContext.Dispose(); _toAck.AddRange(events); }
public void Increment() { counter.Increment(); }