Ejemplo n.º 1
0
        private void AddSubscriber(Guid publishWithCorrelationId, IReaderSubscription subscription)
        {
//            _logger.Trace(
//                "The '{0}' projection subscribed to the '{1}' heading distribution point", publishWithCorrelationId,
//                _eventReaderId);
            _headSubscribers.Add(publishWithCorrelationId, subscription);
        }
Ejemplo n.º 2
0
        private bool DispatchRecentMessagesTo(IReaderSubscription subscription, long fromTransactionFilePosition)
        {
            foreach (var m in _lastMessages)
            {
                if (m.Position.CommitPosition >= fromTransactionFilePosition)
                {
                    try {
                        m.Handle(subscription);
                    } catch (Exception ex) {
                        var    item = m as CommittedEventItem;
                        string message;
                        if (item != null)
                        {
                            message = string.Format(
                                "The heading subscription failed to handle a recently cached event {0}:{1}@{2} because {3}",
                                item.Message.Data.EventStreamId, item.Message.Data.EventType,
                                item.Message.Data.PositionSequenceNumber, ex.Message);
                        }
                        else
                        {
                            message = string.Format(
                                "The heading subscription failed to handle a recently cached deleted event at position {0} because {1}",
                                m.Position, ex.Message);
                        }

                        _publisher.Publish(
                            new EventReaderSubscriptionMessage.Failed(subscription.SubscriptionId, message));
                        return(false);
                    }
                }
            }

            return(true);
        }
        public void setup()
        {
            _checkpointUnhandledBytesThreshold = 1000;
            _checkpointProcessedEventsThreshold = 2000;
            Given();
            _bus = new InMemoryBus("bus");
            _projectionCorrelationId = Guid.NewGuid();
            _eventHandler = new TestHandler<EventReaderSubscriptionMessage.CommittedEventReceived>();
            _checkpointHandler = new TestHandler<EventReaderSubscriptionMessage.CheckpointSuggested>();
            _progressHandler = new TestHandler<EventReaderSubscriptionMessage.ProgressChanged>();
            _subscriptionStartedHandler = new TestHandler<EventReaderSubscriptionMessage.SubscriptionStarted>();
            _notAuthorizedHandler = new TestHandler<EventReaderSubscriptionMessage.NotAuthorized>();
            _eofHandler = new TestHandler<EventReaderSubscriptionMessage.EofReached>();
            _partitionEofHandler = new TestHandler<EventReaderSubscriptionMessage.PartitionEofReached>();
            _partitionMeasuredHandler = new TestHandler<EventReaderSubscriptionMessage.PartitionMeasured>();

            _bus.Subscribe(_eventHandler);
            _bus.Subscribe(_checkpointHandler);
            _bus.Subscribe(_progressHandler);
            _bus.Subscribe(_eofHandler);
            _bus.Subscribe(_partitionEofHandler);
            _bus.Subscribe(_partitionMeasuredHandler);
            _readerStrategy = CreateCheckpointStrategy();
            _subscription = CreateProjectionSubscription();


            When();
        }
Ejemplo n.º 4
0
        public void setup()
        {
            _checkpointUnhandledBytesThreshold  = 1000;
            _checkpointProcessedEventsThreshold = 2000;
            _checkpointAfterMs = 10000;
            _timeProvider      = new RealTimeProvider();
            Given();
            _bus = new InMemoryBus("bus");
            _projectionCorrelationId    = Guid.NewGuid();
            _eventHandler               = new TestHandler <EventReaderSubscriptionMessage.CommittedEventReceived>();
            _checkpointHandler          = new TestHandler <EventReaderSubscriptionMessage.CheckpointSuggested>();
            _progressHandler            = new TestHandler <EventReaderSubscriptionMessage.ProgressChanged>();
            _subscriptionStartedHandler = new TestHandler <EventReaderSubscriptionMessage.SubscriptionStarted>();
            _notAuthorizedHandler       = new TestHandler <EventReaderSubscriptionMessage.NotAuthorized>();
            _eofHandler               = new TestHandler <EventReaderSubscriptionMessage.EofReached>();
            _partitionEofHandler      = new TestHandler <EventReaderSubscriptionMessage.PartitionEofReached>();
            _partitionMeasuredHandler = new TestHandler <EventReaderSubscriptionMessage.PartitionMeasured>();
            _partitionDeletedHandler  = new TestHandler <EventReaderSubscriptionMessage.PartitionDeleted>();

            _bus.Subscribe(_eventHandler);
            _bus.Subscribe(_checkpointHandler);
            _bus.Subscribe(_progressHandler);
            _bus.Subscribe(_eofHandler);
            _bus.Subscribe(_partitionEofHandler);
            _bus.Subscribe(_partitionMeasuredHandler);
            _readerStrategy = CreateCheckpointStrategy();
            _subscription   = CreateProjectionSubscription();


            When();
        }
Ejemplo n.º 5
0
 private void DispatchRecentMessagesTo(IReaderSubscription subscription, long fromTransactionFilePosition)
 {
     foreach (var m in _lastMessages)
     {
         if (m.Position.CommitPosition >= fromTransactionFilePosition)
         {
             m.Handle(subscription);
         }
     }
 }
Ejemplo n.º 6
0
 private void AddSubscriber(Guid publishWithCorrelationId, IReaderSubscription subscription)
 {
     _logger.Trace(
         "The '{0}' projection subscribed to the '{1}' heading distribution point", publishWithCorrelationId,
         _eventReaderId);
     _headSubscribers.Add(publishWithCorrelationId, subscription);
     if (_headEventReaderPaused)
     {
         _headEventReaderPaused = false;
         //_headEventReader.Resume();
     }
 }
Ejemplo n.º 7
0
 public bool TrySubscribe(
     Guid projectionId, IReaderSubscription readerSubscription, long fromTransactionFilePosition)
 {
     EnsureStarted();
     if (_headSubscribers.ContainsKey(projectionId))
     {
         throw new InvalidOperationException(
                   string.Format("Projection '{0}' has been already subscribed", projectionId));
     }
     if (_subscribeFromPosition.CommitPosition <= fromTransactionFilePosition)
     {
         if (!DispatchRecentMessagesTo(readerSubscription, fromTransactionFilePosition))
         {
             return(false);
         }
         AddSubscriber(projectionId, readerSubscription);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
 public bool TrySubscribe(
     Guid projectionId, IReaderSubscription readerSubscription, long fromTransactionFilePosition)
 {
     EnsureStarted();
     if (_headSubscribers.ContainsKey(projectionId))
     {
         throw new InvalidOperationException(
                   string.Format("Projection '{0}' has been already subscribed", projectionId));
     }
     // if first available event commit position is before the safe TF (prepare) position - join
     if (_subscribeFromPosition.CommitPosition <= fromTransactionFilePosition)
     {
         _logger.Trace(
             "The '{0}' subscription has joined the heading distribution point at '{1}'", projectionId,
             fromTransactionFilePosition);
         DispatchRecentMessagesTo(readerSubscription, fromTransactionFilePosition);
         AddSubscriber(projectionId, readerSubscription);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 9
0
 public abstract void Handle(IReaderSubscription subscription);
Ejemplo n.º 10
0
 private void AddSubscriber(Guid publishWithCorrelationId, IReaderSubscription subscription)
 {
     _logger.Trace(
         "The '{0}' projection subscribed to the '{1}' heading distribution point", publishWithCorrelationId,
         _eventReaderId);
     _headSubscribers.Add(publishWithCorrelationId, subscription);
     if (_headEventReaderPaused)
     {
         _headEventReaderPaused = false;
         //_headEventReader.Resume();
     }
 }
Ejemplo n.º 11
0
 public bool TrySubscribe(
     Guid projectionId, IReaderSubscription readerSubscription, long fromTransactionFilePosition)
 {
     EnsureStarted();
     if (_headSubscribers.ContainsKey(projectionId))
         throw new InvalidOperationException(
             string.Format("Projection '{0}' has been already subscribed", projectionId));
     // if first available event commit position is before the safe TF (prepare) position - join
     if (_subscribeFromPosition.CommitPosition <= fromTransactionFilePosition)
     {
         _logger.Trace(
             "The '{0}' subscription has joined the heading distribution point at '{1}'", projectionId,
             fromTransactionFilePosition);
         DispatchRecentMessagesTo(readerSubscription, fromTransactionFilePosition);
         AddSubscriber(projectionId, readerSubscription);
         return true;
     }
     return false;
 }
 public override void Handle(IReaderSubscription subscription)
 {
     subscription.Handle(Message);
 }
 public abstract void Handle(IReaderSubscription subscription);
 private void DispatchRecentMessagesTo(IReaderSubscription subscription, long fromTransactionFilePosition)
 {
     foreach (var m in _lastMessages)
         if (m.Position.CommitPosition >= fromTransactionFilePosition)
             m.Handle(subscription);
 }
Ejemplo n.º 15
0
 private void AddSubscriber(Guid publishWithCorrelationId, IReaderSubscription subscription)
 {
     _headSubscribers.Add(publishWithCorrelationId, subscription);
 }
Ejemplo n.º 16
0
 public override void Handle(IReaderSubscription subscription)
 {
     subscription.Handle(Message);
 }
Ejemplo n.º 17
0
        private void AddSubscriber(Guid publishWithCorrelationId, IReaderSubscription subscription)
        {
//            _logger.Trace(
//                "The '{0}' projection subscribed to the '{1}' heading distribution point", publishWithCorrelationId,
//                _eventReaderId);
            _headSubscribers.Add(publishWithCorrelationId, subscription);
        }