コード例 #1
0
        public void BuildSimplePipelineTest()
        {
            // Arrange
            var pipeline = new Pipeline <ReceivedData, WorkState>(5);

            // Act
            pipeline.AddStep <ReceivedData, WorkState>(DeserializeStep);
            pipeline.AddAsyncStep <WorkState, WorkState>(ProcessStepAsync);
            pipeline.AddAsyncStep <WorkState, WorkState>(AckMessageAsync);
            pipeline.AddStep <WorkState, WorkState>(LogStep);

            pipeline
            .Finalize((state) =>
            {
                if (state.AllStepsSuccess)
                {
                    _output.WriteLine($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - LetterId: {state.LetterId} - Finished route successful.");
                }
                else
                {
                    _output.WriteLine($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - LetterId: {state.LetterId} - Finished route unsuccesfully.");
                }

                // Lastly mark the excution pipeline finished for this message.
                state.ReceivedData.Complete();     // This impacts wait to completion step in the WorkFlowEngine.
            });

            // Assert
            Assert.Equal(pipeline.StepCount, 5);
        }
コード例 #2
0
        // Build out your workflow
        public Pipeline <ReceivedData, TwilioWorkState> BuildPipeline(int maxDoP, bool?ensureOrdered)
        {
            var pipeline = new Pipeline <ReceivedData, TwilioWorkState>(
                maxDoP,
                healthCheckInterval: TimeSpan.FromSeconds(10),
                pipelineName: "Text.Message.Pipline");

            pipeline.AddAsyncStep <ReceivedData, TwilioWorkState>(DeserializeStepAsync);
            pipeline.AddAsyncStep <TwilioWorkState, TwilioWorkState>(ProcessMessageStepAsync);
            pipeline.AddStep <TwilioWorkState, TwilioWorkState>(AckMessage);

            pipeline
            .Finalize(
                (state) =>
            {
                if (state.AllStepsSuccess)
                {
                    _logger.LogDebug($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - Finished route successfully.");
                }
                else
                {
                    _logger.LogWarning($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - Finished route unsuccesfully.");
                }

                // Lastly mark the excution pipeline finished for this message.
                state.ReceivedData?.Complete();         // This impacts wait to completion step in the WorkFlowEngine.
            });

            return(pipeline);
        }
コード例 #3
0
        private void BuildEmailSendPipeline()
        {
            var consumer = _rabbitService.GetConsumer(SendEmailConsumerName);
            var pipeline = new Pipeline <ReceivedData, SendEmailState>(consumer.ConsumerOptions.ConsumerPipelineOptions.MaxDegreesOfParallelism.Value);

            pipeline.AddStep <ReceivedData, SendEmailState>(SendEmailDeserialize);
            pipeline.AddAsyncStep <SendEmailState, SendEmailState>(SendEmailAsync);
            pipeline.Finalize((state) =>
            {
                if (state.StepSuccess[SendEmailStepKey])
                {
                    try
                    {
                        state.ReceivedData.AckMessage(); // Done sending an email.
                        state.ReceivedData.Complete();   // Tell the whole pipeline we are done with this instance.
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, SendEmailFinalizeGenericError);

                        state.ReceivedData.NackMessage(true); // Nack and requeue (for retry.)
                    }
                }
            });

            SendEmailPipeline = new ConsumerPipeline <SendEmailState>(
                _rabbitService.GetConsumer(consumer.ConsumerOptions.ConsumerName),
                pipeline);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: lsfera/Tesseract
        private IPipeline <ReceivedData, WorkState> BuildPipeline(int maxDoP, bool?ensureOrdered = null)
        {
            var pipeline = new Pipeline <ReceivedData, WorkState>(
                maxDoP,
                healthCheckInterval: TimeSpan.FromSeconds(10),
                pipelineName: "ConsumerPipelineExample",
                ensureOrdered);

            pipeline.AddStep <ReceivedData, WorkState>(DeserializeStep);
            pipeline.AddAsyncStep <WorkState, WorkState>(ProcessStepAsync);
            pipeline.AddAsyncStep <WorkState, WorkState>(AckMessageAsync);

            pipeline
            .Finalize(
                async(state) =>
            {
                if (Program.LogOutcome)
                {
                    if (state.AllStepsSuccess)
                    {
                        _logger.LogInformation($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - Id: {state.Message?.MessageId} - Finished route successfully.");
                    }
                    else
                    {
                        _logger.LogInformation($"{DateTime.Now:yyyy/MM/dd hh:mm:ss.fff} - Id: {state.Message?.MessageId} - Finished route unsuccesfully.");
                    }
                }

                // Lastly mark the excution pipeline finished for this message.
                state.ReceivedData?.Complete();         // This impacts wait to completion step in the Pipeline.

                if (Program.AwaitShutdown)
                {
                    Interlocked.Increment(ref _currentMessageCount);
                    if (_currentMessageCount == _targetCount - 1)
                    {
                        await _consumerPipeline.StopAsync().ConfigureAwait(false);
                    }
                }
            });

            return(pipeline);
        }
コード例 #5
0
        private IPipeline <ReceivedData, WorkState> BuildPipeline(int maxDoP, bool?ensureOrdered = null)
        {
            var pipeline = new Pipeline <ReceivedData, WorkState>(
                maxDoP,
                healthCheckInterval: TimeSpan.FromSeconds(10),
                pipelineName: "ConsumerPipelineExample",
                ensureOrdered);

            pipeline.AddAsyncStep <ReceivedData, WorkState>(DeserializeStepAsync);
            pipeline.AddAsyncStep <WorkState, WorkState>(ProcessStepAsync);
            pipeline.AddAsyncStep <WorkState, WorkState>(AckMessageAsync);

            pipeline
            .Finalize((state) =>
            {
                // Lastly mark the excution pipeline finished for this message.
                state.ReceivedData?.Complete();     // This impacts wait to completion step in the Pipeline.
            });

            return(pipeline);
        }