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;
        }
示例#2
0
        public EventStoreDelayed(IStoreEvents store, string endpoint, int maxSize, int readSize, TimeSpan flushInterval, StreamIdGenerator streamGen)
        {
            _store     = store;
            _streamGen = streamGen;
            _endpoint  = endpoint;

            if (_flusher == null)
            {
                // Add a process exit event handler to flush cached delayed events before exiting the app
                // Not perfect in the case of a fatal app error - but something
                AppDomain.CurrentDomain.ProcessExit += (sender, e) => Flush(new FlushState {
                    Store = store, StreamGen = streamGen, Endpoint = endpoint, MaxSize = maxSize, ReadSize = readSize, Expiration = flushInterval
                }, all: true).Wait();
                _flusher = Timer.Repeat((s) => Flush(s), new FlushState {
                    Store = store, StreamGen = streamGen, Endpoint = endpoint, MaxSize = maxSize, ReadSize = readSize, Expiration = flushInterval
                }, flushInterval, "delayed flusher");
            }
        }