Exemplo n.º 1
0
        public async Task HandleMessage(
            StreamMessage message,
            IProcessedStreamState state,
            Func <StreamMessage, CancellationToken, Task> executeProjectMessage,
            ConnectedProjectionIdentifier projection,
            CancellationToken cancellationToken)
        {
            if (await IsCloseToStreamEnd(message, cancellationToken))
            {
                throw new StreamGapDetectedException(state.DetermineGapPositions(message), projection);
            }

            _logger.LogWarning(
                "Expected messages at positions [{UnprocessedPositions}] were not processed for {Projection}.",
                string.Join(", ", state.DetermineGapPositions(message)),
                projection);

            await executeProjectMessage(message, cancellationToken);
        }
        private static ProcessMessageAction DetermineProcessMessageAction(
            StreamMessage message,
            IProcessedStreamState lastProcessedPosition)
        {
            if (message.Position <= lastProcessedPosition.Position)
            {
                return(ProcessMessageAction.Skip);
            }

            if (message.Position == lastProcessedPosition.ExpectedNextPosition)
            {
                return(ProcessMessageAction.Process);
            }

            if (message.Position > lastProcessedPosition.ExpectedNextPosition)
            {
                return(ProcessMessageAction.HandleGap);
            }

            return(ProcessMessageAction.Unknown);
        }