Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private static async Task RunSimpleClientWithEncryptionAsync()
        {
            await Console.Out.WriteLineAsync("Starting SimpleClient w/ Encryption...").ConfigureAwait(false);

            var sentMessage = new TestMessage {
                Message = "Sensitive Message"
            };
            var letter = new Letter("", "TestRabbitServiceQueue", JsonSerializer.SerializeToUtf8Bytes(sentMessage), new LetterMetadata());

            await _rabbitService
            .Topologer
            .CreateQueueAsync("TestRabbitServiceQueue")
            .ConfigureAwait(false);

            // Queue the letter for delivery by the library.
            await _rabbitService
            .Publisher
            .QueueLetterAsync(letter);

            // Start Consumer
            var consumer = _rabbitService.GetConsumer("ConsumerFromConfig");
            await consumer
            .StartConsumerAsync()
            .ConfigureAwait(false);

            // Get Message From Consumer
            var receivedLetter = await consumer
                                 .ReadAsync()
                                 .ConfigureAwait(false);

            // Do work with message inside the receivedLetter
            var decodedLetter = JsonSerializer.Deserialize <TestMessage>(receivedLetter.Letter.Body);

            await Console.Out.WriteLineAsync($"Sent: {sentMessage.Message}").ConfigureAwait(false);

            await Console.Out.WriteLineAsync($"Received: {decodedLetter.Message}").ConfigureAwait(false);

            // Acknowledge Message
            if (receivedLetter.Ackable)
            {
                receivedLetter.AckMessage();
            }

            // Cleanup the queue
            await _rabbitService
            .Topologer
            .DeleteQueueAsync("TestRabbitServiceQueue")
            .ConfigureAwait(false);

            await Console.In.ReadLineAsync().ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public ConsumerDataflow(
            IRabbitService rabbitService,
            string workflowName,
            string consumerName,
            int consumerCount)
        {
            Guard.AgainstNull(rabbitService, nameof(rabbitService));
            Guard.AgainstNullOrEmpty(consumerName, nameof(consumerName));

            WorkflowName   = workflowName;
            _consumerCount = consumerCount;
            _consumerName  = consumerName;

            _logger          = LogHelper.LoggerFactory.CreateLogger <ConsumerDataflow <TState> >();
            _rabbitService   = rabbitService;
            _consumerOptions = rabbitService.GetConsumer(consumerName).ConsumerOptions;

            _linkStepOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };
            _executeStepOptions = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism    = _consumerOptions.ConsumerPipelineOptions.MaxDegreesOfParallelism ?? 1,
                SingleProducerConstrained = true,
                EnsureOrdered             = _consumerOptions.ConsumerPipelineOptions.EnsureOrdered ?? true
            };

            _consumerBlocks = new List <ConsumerBlock <ReceivedData> >();
        }
Ejemplo n.º 4
0
        public async Task ConsumerStartAndStopTesting()
        {
            var consumer = rabbitService.GetConsumer("ConsumerFromConfig");

            for (int i = 0; i < 100; i++)
            {
                await consumer.StartConsumerAsync().ConfigureAwait(false);

                await consumer.StopConsumerAsync().ConfigureAwait(false);
            }
        }