private void Dropped(EventStoreCatchUpSubscription sub,SubscriptionDropReason reason,Exception ex)
 {
     //Reconnect if we drop
     //TODO: check the reason and handle it appropriately
     _view.ErrorMsg = "Subscription Dropped, press Enter to reconnect";
     Subscribe();
 }
Example #2
0
        void EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent evnt)
        {
            if (evnt.OriginalStreamId.StartsWith("$"))
                return;
    
            dynamic ev = _adapter.TryGetDomainEvent(evnt);
            if (ev == null)
                return;

            try
            {
                lock (this)
                {
                    Dispatch(ev);
                    _succeded++;
                    _checkPoint = evnt.OriginalPosition.GetValueOrDefault();
                    _lastEventNumber = evnt.OriginalEventNumber;
                    if(ev.Timestamp > LastUpdate)
                        LastUpdate = ev.Timestamp;
                }
            }
            catch (Exception)
            {
                Debugger.Break();
            }
           
        }
        private void GotEvent(EventStoreCatchUpSubscription sub, ResolvedEvent evt)
        {
            try
            {
                //create local copies of state variables
                var total = _total;
                var checkpoint = evt.Event.EventNumber;

                var amount = (string)JObject.Parse(Encoding.UTF8.GetString(evt.Event.Data))["amount"];
                switch (evt.Event.EventType.ToUpperInvariant())
                {
                    case "CREDIT":
                        total += int.Parse(amount);
                        break;
                    case "DEBIT":
                        total -= int.Parse(amount);
                        break;
                    default:
                        throw new Exception("Unknown Event Type");
                }
                File.WriteAllText(_localFile, checkpoint + "," + total);
                //Update the common state after commit to disk
                _total = total;
                Checkpoint = checkpoint;
            }
            catch (Exception ex)
            {
                _view.ErrorMsg = "Event Exception: " + ex.Message;
            }
            //repaint screen
            _view.Total = _total;
        }
        private void ProcessEvent(EventStoreCatchUpSubscription subscribtion, ResolvedEvent resolvedEvent)
        {
            var alarm = resolvedEvent.ParseJson<IrresponsibleGamblerDetected>();

            Publish(alarm);

            StoreCheckpoint(resolvedEvent);
        }
Example #5
0
 private void HandleNewEvent(EventStoreCatchUpSubscription subscription, ResolvedEvent @event)
 {
     // make sure the event fits the ones this handler cares about
     if (!_eventFilter(@event)) { return; }
     var _event = ProcessRawEvent(@event);
     // filter for null event ( didn't have metadata or data )
     if (_event == null) { return; }
     HandleEvent(_event);
 }
Example #6
0
 public void Stop()
 {
     HasLoaded = false;
     try
     {
         _subscription.Stop(TimeSpan.MaxValue);
         _subscription = null;
         _connection.Dispose();
     }
     catch { }
 }
Example #7
0
 private static void Appeared(EventStoreCatchUpSubscription subscription, ResolvedEvent resolvedEvent)
 {   
     if (resolvedEvent.Event.EventType.Contains("Question") || resolvedEvent.Event.EventType.Contains("Answer"))
     {
         Console.WriteLine("Read event {0} with data: {1}", 
             resolvedEvent.Event.EventType, 
             Encoding.UTF8.GetString(resolvedEvent.Event.Data));
         
         var @event = EventDeserializer.Deserialize(resolvedEvent.Event.EventType, Encoding.UTF8.GetString(resolvedEvent.Event.Data));
         _eventPublisher.Publish(@event);
     }
 }
Example #8
0
        public void Start()
        {
            HasLoaded = false;
            _connection = EventStore.ClientAPI.EventStoreConnection.Create(_endpoint);
            var ct = _connection.ConnectAsync();
            ct.Wait();
            _checkPoint = Position.Start;
            if (string.IsNullOrEmpty(_streamName))
                _subscription = _connection.SubscribeToAllFrom(_checkPoint, false, EventAppeared, Live, SubscriptionDropped, _credentials);
            else
                _subscription = _connection.SubscribeToStreamFrom(_streamName, _lastEventNumber, true, EventAppeared, Live, SubscriptionDropped, _credentials);

        }
 private void EventAppeared(EventStoreCatchUpSubscription subscription, ResolvedEvent re)
 {
     if (re.OriginalEvent.EventType.StartsWith("$")) return; //skip internal events
     if (re.OriginalEvent.Metadata == null || re.OriginalEvent.Metadata.Any() == false) return;
     try
     {
         var e = re.DeserializeEvent();
         Dispatch(e).Wait();
     }
     catch (Exception exception)
     {
         _log.Error(string.Format("Could not deserialize event {0}", re.OriginalEvent.EventType), exception);
     }
 }
Example #10
0
        public void OnEventAppeared(EventStoreCatchUpSubscription subscription, ResolvedEvent resolvedEvent, Action<object,DateTime> callback)
        {
            var type = _typeLocator.Locate(resolvedEvent.Event.EventType);

            if (null == type) {
                _logger.LogDebug("[{0}] unknown type", _streamName);
                return;
            }

            callback(
                JsonConvert.DeserializeObject(
                    Encoding.UTF8.GetString(resolvedEvent.Event.Data),
                    type
                ),
                resolvedEvent.Event.Created
            );
        }
Example #11
0
 private static void Live(EventStoreCatchUpSubscription obj)
 {
     mre.Set();
 }
Example #12
0
        private static void Dropped(EventStoreCatchUpSubscription arg1, SubscriptionDropReason arg2, Exception arg3)
        {

        }
 private void OnSubscriptionDropped(EventStoreCatchUpSubscription subscription, SubscriptionDropReason reason, Exception exception)
 {
     _log.Error(string.Format("Event subscription stopped. Reason: {0}", reason), exception);
 }
        private void SubscriptionDropped(EventStoreCatchUpSubscription eventStoreCatchUpSubscription, SubscriptionDropReason subscriptionDropReason, Exception ex)
        {
            if (ex != null)
            {
                _logger.Info(ex, "Event Store subscription dropped {0}", subscriptionDropReason.ToString());
            }
            else
            {
                _logger.Info("Event Store subscription dropped {0}", subscriptionDropReason.ToString());
            }
            _viewModelIsReady = false;

            lock (_liveProcessingTimer)
            {
                if(!_liveProcessingTimer.Enabled)
                    _liveProcessingTimer.Start();
            }
        }
        private void EventAppeared(EventStoreCatchUpSubscription _, ResolvedEvent resolvedEvent)
        {
            if(resolvedEvent.OriginalEvent.EventType.StartsWith("$")
               || resolvedEvent.OriginalStreamId.StartsWith("$"))
            {
                return;
            }

            _queue.Enqueue(resolvedEvent);
        }
 private void OnLiveProcessingStarted(EventStoreCatchUpSubscription subscription)
 {
     _log.Debug("Live processing of events started");
 }
        public void Dispose()
        {
            if (_isDisposed.EnsureCalledOnce())
            {
                return;
            }

            _disposed.Cancel();
            _projectedEvents.Dispose();
            if(_subscription != null)
            {
                _subscription.Stop();
                _subscription = null;
            }
        }
Example #18
0
 private static void Dropped(EventStoreCatchUpSubscription subscription, SubscriptionDropReason subscriptionDropReason, Exception exception)
 {
     
 }
 private void HandleSubscriptionDropped(EventStoreCatchUpSubscription subscription, SubscriptionDropReason reason, Exception ex)
 {
 }
        private async Task RecoverSubscription()
        {
            var checkpointToken = await _checkpoints.Get();

            _subscription = _streamId == null 
                ? SubscribeToAllFrom(checkpointToken.ParsePosition()) 
                : SubscribeToStreamFrom(checkpointToken == null ? default(int?) : int.Parse(checkpointToken));
        }
 /// <inheritdoc />
 protected override async Task LiveProcessingStarted(EventStoreCatchUpSubscription eventStoreCatchUpSubscription,
                                                     Position lastPosition)
 {
     await CheckpointReachedAction(lastPosition).ConfigureAwait(false);
 }
Example #22
0
 /// <summary>
 /// The callback invoked when the subscription switches to push notifications.
 /// </summary>
 /// <param name="eventStoreCatchUpSubscription"></param>
 /// <param name="lastPosition"></param>
 /// <returns></returns>
 protected abstract Task LiveProcessingStarted(EventStoreCatchUpSubscription eventStoreCatchUpSubscription,
                                               Position lastPosition);
 /// <inheritdoc />
 protected override Task LiveProcessingStarted(EventStoreCatchUpSubscription eventStoreCatchUpSubscription,
                                               Position lastPosition)
 {
     return(TaskEx.CompletedTask);
 }
Example #24
0
        private static void Appeared(EventStoreCatchUpSubscription arg1, ResolvedEvent evnt)
        {
            _adapter.TryGetDomainEvent(evnt);

            count++;
            if(count % 1000 == 0)
                Console.WriteLine("{0}", count);
            //events.Add(arg2);
        }
 private void EventAppeared(EventStoreCatchUpSubscription eventStoreCatchUpSubscription, ResolvedEvent resolvedEvent)
 {
     _queue.Add(resolvedEvent);
 }
        private void LiveProcessingStarted(EventStoreCatchUpSubscription eventStoreCatchUpSubscription)
        {
            lock (_liveProcessingTimer)
            {
                _liveProcessingTimer.Stop();
            }

            _logger.Info("Live event processing started");
            _viewModelIsReady = true;
        }
 public void Start()
 {
     _subscription = _connection.SubscribeToStreamFrom(_streamName, _startingPosition.HasValue ? (int?)_startingPosition.Value : null, true, EventAppeared, LiveProcessingStarted, SubscriptionDropped, readBatchSize: _catchupPageSize);
     Thread processor = new Thread(ProcessEvents);
     processor.Start();
 }
        private void HandleEvent(EventStoreCatchUpSubscription sub, ResolvedEvent evt)
        {
            if (evt.Event.EventType.StartsWith("$"))
                return;

            Debug.WriteLine("Handling event: {1} {0}", evt.Event.EventStreamId, evt.Event.EventNumber);
            var deserializedEvent = _serializer.Deserialize(evt.Event);

            var orderStatusbuilder = new RavenViewModelBuilder<OrderStatusModel>(_store, new OrderStatusModelHandler(), _updateNotifier);
            orderStatusbuilder.Build(evt.Event.EventStreamId, new[] { deserializedEvent });

            var orderItemsBuilder = new RavenViewModelBuilder<OrderItemsModel>(_store, new OrderItemsModelHandler(), _updateNotifier);
            orderItemsBuilder.Build(evt.Event.EventStreamId, new[] { deserializedEvent });

            using (var session = _store.OpenSession())
            {
                StoreViewBuilderData(evt, session);
                StoreCommandData(evt, deserializedEvent, session);
                session.SaveChanges();
            }
        }
        private void SubscriptionDropped(EventStoreCatchUpSubscription _, SubscriptionDropReason reason, Exception ex)
        {
            if(reason == SubscriptionDropReason.UserInitiated)
            {
                return;
            }

            RecoverSubscription().Wait(TimeSpan.FromSeconds(2));
        }
Example #30
0
        //ActorRef GetRef(string id)
        //{
        //    return new ActorRef(id);
        //}

        void EventAppeared(EventStoreCatchUpSubscription sub, ResolvedEvent evnt)
        {
            //evnt.Event.Data
            Message msg = null;

            var worker = FindWorker(msg.ActorId);
            worker.Dispatch(msg);
        }
Example #31
0
 public void OnLiveProcessingStarted(EventStoreCatchUpSubscription subscription)
 {
     _logger.LogDebug("[{0}] in sync", _streamName);
 }
Example #32
0
 private void HandleEvent(EventStoreCatchUpSubscription arg1, ResolvedEvent arg2)
 {
     var @event = EventSerialization.DeserializeEvent(arg2.OriginalEvent);
     if (@event != null)
     {
         var eventType = @event.GetType();
         if (_eventHandlerMapping.ContainsKey(eventType))
         {
             _eventHandlerMapping[eventType](@event);
         }
     }
     _latestPosition = arg2.OriginalPosition;
 }
Example #33
0
 public void OnSubscriptionDropped(EventStoreCatchUpSubscription subscription, SubscriptionDropReason reason, Exception error)
 {
     _logger.LogCritical("Catch up on {0} failure: {1}", _streamName, error.ToString());
 }