public void SetUp()
        {
            _connection            = new FakeEventStoreConnection();
            _raisedEvents          = new List <ResolvedEvent>();
            _dropEvent             = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
            _raisedEventEvent      = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
            _liveProcessingStarted = false;
            _isDropped             = false;
            _dropReason            = SubscriptionDropReason.Unknown;
            _dropException         = null;

            var settings = new CatchUpSubscriptionSettings(1, 1, false, false, String.Empty);

            _subscription = new EventStoreStreamCatchUpSubscription(_connection, new NoopLogger(), StreamId, null, null,
                                                                    (subscription, ev) => {
                _raisedEvents.Add(ev);
                if (_raisedEvents.Count >= 2)
                {
                    _raisedEventEvent.TrySetResult(true);
                }
                return(Task.CompletedTask);
            },
                                                                    subscription => { _liveProcessingStarted = true; },
                                                                    (subscription, reason, ex) => {
                _isDropped     = true;
                _dropReason    = reason;
                _dropException = ex;
                _dropEvent.TrySetResult(true);
            },
                                                                    settings);
        }
 public IDisposable Subscribe(IObserver <T> observer)
 {
     _subscription = _connection.SubscribeToStreamFrom(_stream, _lastCheckpoint, _resolveLinkTos, EventAppeared,
                                                       subscriptionDropped: SubscriptionDropped);
     _observer = observer;
     return(Disposable.Create(Stop));
 }
예제 #3
0
        public async Task Start(long fromCheckpoint)
        {
            Connection            = EventStoreConnection.Create(ESConnectionConfig.ConnectionString);
            Connection.Connected += Connection_Connected;
            await Connection.ConnectAsync().ConfigureAwait(false);

            long?eventstoreCheckpoint = (fromCheckpoint == 0) ? null : (long?)(fromCheckpoint - 1);

            Subscription = Connection.SubscribeToStreamFrom(StreamName, eventstoreCheckpoint, CatchUpSubscriptionSettings.Default, EventAppeared, LiveProcessingStarted, SubscriptionDropped);
        }
예제 #4
0
        public async Task StartAsync()
        {
            var lastCheckpoint = await GetLastCheckpoint();

            _subscription = _connectionProvider().SubscribeToStreamFrom(_streamId,
                                                                        lastCheckpoint,
                                                                        CatchUpSubscriptionSettings.Default,
                                                                        (_, y) => EventAppeared(y).GetAwaiter().GetResult(),
                                                                        LiveProcessingStarted,
                                                                        SubscriptionDropped);
        }
        private void SubscribeToStream(IEventStoreConnection connection)
        {
            if (_subscription != null)
            {
                _subscription.Stop();
                _subscription = null;
            }

            _subscription = connection.SubscribeToStreamFrom(_streamName, _checkpoint,
                                                             CatchUpSubscriptionSettings.Default,
                                                             EventAppeared, LiveProcessingStarted, SubscriptionDropped);
        }
 public EventStoreStreamCatchUpSubscription SubscribeToStreamFrom(
         string stream,
         long? lastCheckpoint,
         CatchUpSubscriptionSettings settings,
         Func<EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared,
         Action<EventStoreCatchUpSubscription> liveProcessingStarted = null,
         Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
         UserCredentials userCredentials = null)
 {
     Ensure.NotNullOrEmpty(stream, "stream");
     Ensure.NotNull(settings, "settings");
     Ensure.NotNull(eventAppeared, "eventAppeared");
     var catchUpSubscription =
             new EventStoreStreamCatchUpSubscription(this, Settings.Log, stream, lastCheckpoint,
                                                     userCredentials, eventAppeared, liveProcessingStarted,
                                                     subscriptionDropped, settings);
     catchUpSubscription.StartAsync();
     return catchUpSubscription;
 }
예제 #7
0
        protected override void PreStart()
        {
            base.PreStart();
            var connectionString = _settings.ConnectionString;
            var connectionName   = _settings.ConnectionName;

            _eventStoreConnection = EventStoreConnection.Create(connectionString, connectionName);

            var self        = Self;
            var stream      = "accounts";
            var from        = 0;
            var settings    = new CatchUpSubscriptionSettings(500, 500, true, true);
            var credentials = _eventStoreConnection.Settings.DefaultUserCredentials;

            _subscription = _eventStoreConnection.SubscribeToStreamFrom(
                stream,
                from,
                settings,
                (s, e) => EventAppeared(self, s, e),
                s => LiveProcessingStarted(self, s),
                (s, r, ex) => SubscriptionDropped(self, s, r, ex),
                credentials
                );
        }
 public EventStoreStreamCatchUpSubscription SubscribeToStreamFrom(string stream,
     int? lastCheckpoint,
     bool resolveLinkTos,
     Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared,
     Action<EventStoreCatchUpSubscription> liveProcessingStarted = null,
     Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
     UserCredentials userCredentials = null,
     int readBatchSize = 500)
 {
     Ensure.NotNullOrEmpty(stream, "stream");
     Ensure.NotNull(eventAppeared, "eventAppeared");
     var catchUpSubscription =
         new EventStoreStreamCatchUpSubscription(this, _settings.Log, stream, lastCheckpoint,
             resolveLinkTos, GetUserCredentials(_settings, userCredentials), eventAppeared,
             liveProcessingStarted, subscriptionDropped, _settings.VerboseLogging, readBatchSize);
     catchUpSubscription.Start();
     return catchUpSubscription;
 }
 public EventStoreStreamCatchUpSubscription SubscribeToStreamFrom(
         string stream,
         int? lastCheckpoint,
         CatchUpSubscriptionSettings settings,
         Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared,
         Action<EventStoreCatchUpSubscription> liveProcessingStarted = null,
         Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
         UserCredentials userCredentials = null)
 {
     Ensure.NotNullOrEmpty(stream, "stream");
     Ensure.NotNull(settings, "settings");
     Ensure.NotNull(eventAppeared, "eventAppeared");
     var catchUpSubscription =
             new EventStoreStreamCatchUpSubscription(this, _settings.Log, stream, lastCheckpoint,
                                                     userCredentials, eventAppeared, liveProcessingStarted,
                                                     subscriptionDropped, settings);
     catchUpSubscription.Start();
     return catchUpSubscription;
 }
 private void Subscribe()
 {
     _sub = _connection.SubscribeToStreamFrom(_streamId, _lastEventPosition, _settings, _eventAppeared, null, SubscriptionDropped, null);
 }
예제 #11
0
 public ProjectionSubscription(IDisposable observableSubscription, EventStoreStreamCatchUpSubscription eventStoreSubscription)
 {
     _observableSubscription = observableSubscription;
     _eventStoreSubscription = eventStoreSubscription;
 }