public void Stop()
 {
     HasLoaded = false;
     try
     {
         _subscription.Stop(TimeSpan.MaxValue);
         _subscription = null;
         _connection.Dispose();
     }
     catch { }
 }
        private void RecoverSubscription()
        {
            if (_subscription != null)
            {
                _subscription.Stop();
            }

            var connection = _eventStoreConnectionFactory.Create();
            var settings   = CatchUpSubscriptionSettings.Default;

            //TODO: read credentials from config
            _subscription = connection.SubscribeToAllFrom(_lastProcessedPosition, settings, EventAppeared, null,
                                                          HandleSubscriptionDropped, new UserCredentials("admin", "changeit"));
        }
Exemple #3
0
        private async Task EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent e, CancellationToken token,
                                         Func <string, long, IFullEvent, Task> callback)
        {
            // Don't care about metadata streams
            if (e.Event == null || e.Event.EventStreamId[0] == '$')
            {
                return;
            }

            if (token.IsCancellationRequested)
            {
                Logger.WarnEvent("Cancelation", "Token cancel requested");
                ThreadPool.QueueUserWorkItem((_) => sub.Stop(TimeSpan.FromSeconds(10)));
                token.ThrowIfCancellationRequested();
            }
            try
            {
                await EventAppeared(e, token, callback).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.ErrorEvent("AppearedException", ex, "Stream: [{Stream:l}] Position: {StreamPosition} {ExceptionType} - {ExceptionMessage}", e.Event.EventStreamId, e.Event.EventNumber, ex.GetType().Name, ex.Message);
                //throw;
            }
        }
Exemple #4
0
 public IDisposable Connect()
 {
     SubscribeToStream();
     return(Disposable.Create(() =>
     {
         eventStoreSubscription.Stop();
     }));
 }
Exemple #5
0
 public void Dispose()
 {
     if (_disposed)
     {
         return;
     }
     _disposed = true;
     _subscription.Stop(TimeSpan.FromSeconds(30));
 }
        private async void SubscriptionDropped(EventStoreCatchUpSubscription sub, SubscriptionDropReason reason, Exception ex)
        {
            _logger.LogError(ex, "SubscriptionDropped on StreamId {StreamId}, Projector {ProjectorId}, Reason: {Reason}",
                             sub.StreamId,
                             ProjectorId,
                             reason.ToString());
            sub.Stop();

            if (!_cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation("Re Subscribe Subscription");
                await StartSubscriptionInternal();
            }
        }
Exemple #7
0
        private void EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent e, CancellationToken token,
                                   Action <string, long, IFullEvent> callback)
        {
            // Don't care about metadata streams
            if (e.Event == null || e.Event.EventStreamId[0] == '$')
            {
                return;
            }

            if (token.IsCancellationRequested)
            {
                Logger.Warn($"Token cancelation requested, stopping catchup subscription");
                Task.Run(() => sub.Stop(TimeSpan.FromSeconds(5)));
                token.ThrowIfCancellationRequested();
            }
            EventAppeared(e, token, callback);
        }
        private void EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent e, CancellationToken token,
                                   Action <string, long, IFullEvent> callback)
        {
            // Don't care about metadata streams
            if (e.Event == null || e.Event.EventStreamId[0] == '$')
            {
                return;
            }

            if (token.IsCancellationRequested)
            {
                Logger.Warn($"Token cancelation requested, stopping catchup subscription");
                sub.Stop();
                lock (_subLock) _subscriptions.Remove(sub);
                token.ThrowIfCancellationRequested();
            }
            EventAppeared(e, token, callback);
        }
Exemple #9
0
 private void EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent resolvedEvent)
 {
     if (_cancellationToken != CancellationToken.None && _cancellationToken.IsCancellationRequested)
     {
         Trace.TraceInformation("Cancellation requested, stopping subscription...");
         sub.Stop();
         return;
     }
     if (IsProcessable(resolvedEvent))
     {
         _subject.OnNext(resolvedEvent);
         var pos = resolvedEvent.OriginalPosition;
         if (pos != null)
         {
             _lastCheckpoint = pos;
         }
     }
 }
Exemple #10
0
        protected override void DisposeObject(bool disposing)
        {
            if (disposing)
            {
                disposeToken.Cancel();

                try
                {
                    connectionLock.EnterWriteLock();

                    internalSubscription?.Stop();
                    internalSubscription = null;
                }
                finally
                {
                    connectionLock.ExitWriteLock();
                }
            }
        }
 public void Stop() => _subscription.Stop();
        public void Dispose()
        {
            _logger.LogInformation("Disposing");

            _subscription.Stop();
        }
Exemple #13
0
 public void Dispose()
 {
     _logger.Info("Disposing");
     _subscription.Stop();
 }
 public void Unsubscribe()
 {
     subscription.Stop();
 }
 public void Stop()
 {
     _value.Stop();
 }
Exemple #16
0
 public void Dispose()
 {
     _subscription.Stop();
 }
Exemple #17
0
        protected override Task Close()
        {
            _subscription?.Stop();

            return(base.Close());
        }
 public void Stop()
 {
     _subscription.Stop();
     _cts.Cancel();
 }
 public void StopDispatching(TimeSpan timeout)
 {
     _subscription?.Stop(timeout);
 }
Exemple #20
0
        public Task StopAsync()
        {
            subscription.Stop();

            return(Task.CompletedTask);
        }
Exemple #21
0
        private void HandleError(EventStoreCatchUpSubscription subscription, SubscriptionDropReason reason, Exception ex)
        {
            if (!CanHandleSubscriptionEvent(subscription))
            {
                return;
            }

            try
            {
                connectionLock.EnterUpgradeableReadLock();

                if (CanHandleSubscriptionEvent(subscription))
                {
                    if (reason == SubscriptionDropReason.ConnectionClosed)
                    {
                        var utcNow = DateTime.UtcNow;

                        if (CanReconnect(utcNow))
                        {
                            RegisterReconnectTime(utcNow);

                            try
                            {
                                connectionLock.EnterWriteLock();

                                internalSubscription.Stop();
                                internalSubscription = null;

                                internalSubscription = SubscribeToEventStore();
                            }
                            finally
                            {
                                connectionLock.ExitWriteLock();
                            }

                            DelayForReconnect().Wait();

                            if (!CanHandleSubscriptionEvent(subscription))
                            {
                                return;
                            }

                            try
                            {
                                connectionLock.EnterWriteLock();

                                if (CanHandleSubscriptionEvent(subscription))
                                {
                                    internalSubscription = SubscribeToEventStore();
                                }
                            }
                            finally
                            {
                                connectionLock.ExitWriteLock();
                            }

                            return;
                        }
                    }

                    if (reason != SubscriptionDropReason.UserInitiated)
                    {
                        var exception = ex ?? new ConnectionClosedException($"Subscription closed with reason {reason}.");

                        publishError?.Invoke(exception);
                    }
                }
            }
            finally
            {
                connectionLock.ExitUpgradeableReadLock();
            }
        }
        public Task StopAsync()
        {
            subscription.Stop();

            return(TaskHelper.Done);
        }
Exemple #23
0
 public void Stop()
 {
     activeSub?.Stop();
 }