public ConnectedProjectionCatchUp <TContext> CreateCatchUp(
     IReadonlyStreamStore streamStore,
     IConnectedProjectionsCommandBus commandBus,
     IStreamGapStrategy catchUpStreamGapStrategy,
     ILogger logger)
 => new ConnectedProjectionCatchUp <TContext>(
     this,
     _settings,
     streamStore,
     commandBus,
     catchUpStreamGapStrategy,
     logger);
Beispiel #2
0
        public Task HandleAsync(
            IEnumerable <StreamMessage> messages,
            IStreamGapStrategy streamGapStrategy,
            CancellationToken cancellationToken)
        {
            _executions.Add(CreateExecutionId(messages));

            if (_exceptionSequence.Any())
            {
                throw _exceptionSequence.Pop();
            }

            return(Task.CompletedTask);
        }
        public ConnectedProjectionCatchUp(
            IConnectedProjection <TContext> projection,
            IConnectedProjectionCatchUpSettings settings,
            IReadonlyStreamStore streamStore,
            IConnectedProjectionsCommandBus commandBus,
            IStreamGapStrategy catchUpStreamGapStrategy,
            ILogger logger)
        {
            _projection = projection ?? throw new ArgumentNullException(nameof(projection));
            _settings   = settings ?? throw new ArgumentNullException(nameof(settings));

            _streamStore = streamStore ?? throw new ArgumentNullException(nameof(streamStore));
            _commandBus  = commandBus ?? throw new ArgumentNullException(nameof(commandBus));
            _catchUpStreamGapStrategy = catchUpStreamGapStrategy ?? throw new ArgumentNullException(nameof(catchUpStreamGapStrategy));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
Beispiel #4
0
        public ConnectedProjectionsSubscriptionRunner(
            IRegisteredProjections registeredProjections,
            IConnectedProjectionsStreamStoreSubscription streamsStoreSubscription,
            IConnectedProjectionsCommandBus commandBus,
            IStreamGapStrategy subscriptionStreamGapStrategy,
            ILoggerFactory loggerFactory)
        {
            _handlers = new Dictionary <ConnectedProjectionIdentifier, Func <StreamMessage, CancellationToken, Task> >();

            _registeredProjections = registeredProjections ?? throw new ArgumentNullException(nameof(registeredProjections));
            _registeredProjections.IsSubscribed = HasSubscription;

            _streamsStoreSubscription = streamsStoreSubscription ?? throw new ArgumentNullException(nameof(streamsStoreSubscription));
            _commandBus = commandBus ?? throw new ArgumentNullException(nameof(commandBus));
            _subscriptionStreamGapStrategy = subscriptionStreamGapStrategy ?? throw new ArgumentNullException(nameof(subscriptionStreamGapStrategy));
            _logger = loggerFactory?.CreateLogger <ConnectedProjectionsSubscriptionRunner>() ?? throw new ArgumentNullException(nameof(loggerFactory));
        }
        public ConnectedProjectionsCatchUpRunner(
            IRegisteredProjections registeredProjections,
            IReadonlyStreamStore streamStore,
            IConnectedProjectionsCommandBus commandBus,
            IStreamGapStrategy catchUpStreamGapStrategy,
            ILoggerFactory loggerFactory)
        {
            _projectionCatchUps = new Dictionary <ConnectedProjectionIdentifier, CancellationTokenSource>();

            _registeredProjections = registeredProjections ?? throw new ArgumentNullException(nameof(registeredProjections));
            _registeredProjections.IsCatchingUp = IsCatchingUp;

            _streamStore = streamStore ?? throw new ArgumentNullException(nameof(streamStore));
            _commandBus  = commandBus ?? throw new ArgumentNullException(nameof(commandBus));
            _catchUpStreamGapStrategy = catchUpStreamGapStrategy ?? throw new ArgumentNullException(nameof(catchUpStreamGapStrategy));
            _logger = loggerFactory?.CreateLogger <ConnectedProjectionsCatchUpRunner>() ?? throw new ArgumentNullException(nameof(loggerFactory));
        }
Beispiel #6
0
 public async Task HandleAsync(IEnumerable <StreamMessage> messages, IStreamGapStrategy streamGapStrategy, CancellationToken cancellationToken)
 => await _messageHandling(messages, streamGapStrategy, cancellationToken);
        public async Task HandleAsync(
            IEnumerable <StreamMessage> messages,
            IStreamGapStrategy streamGapStrategy,
            CancellationToken cancellationToken)
        {
            ActiveProcessedStreamState?processedState = null;

            using (var context = _contextFactory().Value)
            {
                try
                {
                    var completeMessageInProcess = CancellationToken.None;
                    processedState = new ActiveProcessedStreamState(await context.GetProjectionPosition(Projection, completeMessageInProcess));

                    async Task ProcessMessage(StreamMessage message, CancellationToken ct)
                    {
                        Logger.LogTrace(
                            "[{Projection}] [STREAM {StreamId} AT {Position}] [{Type}] [LATENCY {Latency}]",
                            Projection,
                            message.StreamId,
                            message.Position,
                            message.Type,
                            CalculateNotVeryPreciseLatency(message));

                        await context.ApplyProjections(_projector, message, ct);

                        processedState?.UpdateWithProcessed(message);
                    }

                    foreach (var message in messages)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            break;
                        }

                        var processAction = DetermineProcessMessageAction(message, processedState);
                        switch (processAction)
                        {
                        case ProcessMessageAction.Skip:
                            continue;

                        case ProcessMessageAction.HandleGap:
                            await streamGapStrategy.HandleMessage(
                                message,
                                processedState,
                                ProcessMessage,
                                Projection,
                                completeMessageInProcess);

                            break;

                        case ProcessMessageAction.Process:
                            await ProcessMessage(message, completeMessageInProcess);

                            break;

                        default:
                            throw new NotImplementedException($"No handle defined for {processAction}");
                        }
                    }

                    if (processedState.HasChanged)
                    {
                        await context.UpdateProjectionPosition(
                            Projection,
                            processedState.Position,
                            completeMessageInProcess);
                    }

                    await context.SaveChangesAsync(completeMessageInProcess);
                }
                catch (TaskCanceledException) { }
                catch (Exception exception)
                {
                    await context.SetErrorMessage(Projection, exception, cancellationToken);

                    throw new ConnectedProjectionMessageHandlingException(exception, Projection, processedState);
                }
            }
        }
Beispiel #8
0
 public ConnectedProjectionCatchUp <FakeProjectionContext> CreateCatchUp(
     IReadonlyStreamStore streamStore,
     IConnectedProjectionsCommandBus commandBus,
     IStreamGapStrategy catchUpStreamGapStrategy,
     ILogger logger)
 => throw new NotImplementedException();