public void Handle(ProjectionMessage.Projections.SubscribeProjection message) { if (_stopped) { return; } var fromCheckpointTag = message.FromPosition; var projectionSubscription = new ProjectionSubscription( message.CorrelationId, fromCheckpointTag, message.Subscriber, message.Subscriber, message.CheckpointStrategy, message.CheckpointUnhandledBytesThreshold); _projections.Add(message.CorrelationId, projectionSubscription); bool subscribedHeading = _headingEventDistributionPoint.TrySubscribe( message.CorrelationId, projectionSubscription, fromCheckpointTag); if (!subscribedHeading) { var distibutionPointCorrelationId = Guid.NewGuid(); var eventDistributionPoint = projectionSubscription.CreatePausedEventDistributionPoint( _publisher, distibutionPointCorrelationId); _distributionPoints.Add(distibutionPointCorrelationId, eventDistributionPoint); _projectionDistributionPoints.Add(message.CorrelationId, distibutionPointCorrelationId); _distributionPointSubscriptions.Add(distibutionPointCorrelationId, message.CorrelationId); eventDistributionPoint.Resume(); } }
private bool TrySubscribeHeadingDistributionPoint( ProjectionCoreServiceMessage.CommittedEventDistributed message, Guid projectionId) { if (_pausedProjections.Contains(projectionId)) { return(false); } var projectionSubscription = _subscriptions[projectionId]; if (message.SafeTransactionFileReaderJoinPosition == null || !_headingEventDistributionPoint.TrySubscribe( projectionId, projectionSubscription, message.SafeTransactionFileReaderJoinPosition.Value)) { return(false); } if (message.Data == null) { _logger.Trace( "The '{0}' is subscribing to the heading distribution point with TF-EOF marker event at '{1}'", projectionId, message.SafeTransactionFileReaderJoinPosition); } Guid distributionPointId = message.CorrelationId; _distributionPoints[distributionPointId].Dispose(); _distributionPoints.Remove(distributionPointId); _distributionPointSubscriptions.Remove(distributionPointId); _projectionDistributionPoints[projectionId] = Guid.Empty; return(true); }
public void setup() { _exception = null; try { _point = new HeadingEventDistributionPoint(10); } catch (Exception ex) { _exception = ex; } _distibutionPointCorrelationId = Guid.NewGuid(); _point.Start( _distibutionPointCorrelationId, new TransactionFileReaderEventDistributionPoint( _bus, _distibutionPointCorrelationId, new EventPosition(0, -1))); _point.Handle( new ProjectionMessage.Projections.CommittedEventDistributed( _distibutionPointCorrelationId, new EventPosition(20, 10), "stream", 10, false, new Event(Guid.NewGuid(), "type", false, new byte[0], new byte[0]))); _point.Handle( new ProjectionMessage.Projections.CommittedEventDistributed( _distibutionPointCorrelationId, new EventPosition(40, 30), "stream", 11, false, new Event(Guid.NewGuid(), "type", false, new byte[0], new byte[0]))); _subscription = new FakeProjectionSubscription(); _projectionSubscriptionId = Guid.NewGuid(); var subscribed = _point.TrySubscribe( _projectionSubscriptionId, _subscription, CheckpointTag.FromStreamPosition("stream", 100, prepaprePosition: 30)); _point.Handle( new ProjectionMessage.Projections.CommittedEventDistributed( _distibutionPointCorrelationId, new EventPosition(60, 50), "stream", 12, false, new Event(Guid.NewGuid(), "type", false, new byte[0], new byte[0]))); }
public void setup() { _exception = null; try { _point = new HeadingEventDistributionPoint(10); } catch (Exception ex) { _exception = ex; } _distibutionPointCorrelationId = Guid.NewGuid(); _point.Start( _distibutionPointCorrelationId, new TransactionFileReaderEventDistributionPoint( _bus, _distibutionPointCorrelationId, new EventPosition(0, -1))); _point.Handle( new ProjectionCoreServiceMessage.CommittedEventDistributed( _distibutionPointCorrelationId, new EventPosition(20, 10), "stream", 10, false, new Event(Guid.NewGuid(), "type", false, new byte[0], new byte[0]))); _point.Handle( new ProjectionCoreServiceMessage.CommittedEventDistributed( _distibutionPointCorrelationId, new EventPosition(40, 30), "stream", 11, false, new Event(Guid.NewGuid(), "type", false, new byte[0], new byte[0]))); _subscription = new FakeProjectionSubscription(); _projectionSubscriptionId = Guid.NewGuid(); var subscribed = _point.TrySubscribe(_projectionSubscriptionId, _subscription, 30); Assert.IsTrue(subscribed); // ensure we really unsubscribing.. even if it is tested elsewhere _point.Unsubscribe(_projectionSubscriptionId); }