Example #1
0
        private async Task SendOutboxMessagesAsync()
        {
            var jobId = Guid.NewGuid().ToString("N");

            _logger.LogDebug($"Started processing outbox messages... [job id: '{jobId}']");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var messages = await _outbox.GetUnsentAsync();

            _logger.LogDebug($"Found {messages.Count} unsent messages in outbox [job id: '{jobId}'].");
            if (!messages.Any())
            {
                _logger.LogDebug($"No messages to be processed in outbox [job id: '{jobId}'].");
                return;
            }

            var publishTasks = messages.Select(om => _publisher.PublishAsync(om.Message, om.MessageId,
                                                                             om.CorrelationId, om.SpanContext, om.MessageContext, om.Headers));
            await Task.WhenAll(publishTasks);

            await _outbox.ProcessAsync(messages);

            stopwatch.Stop();
            _logger.LogDebug($"Processed {messages} outbox messages in {stopwatch.ElapsedMilliseconds} ms [job id: '{jobId}'].");
        }
Example #2
0
        private async Task SendOutboxMessagesAsync(object state)
        {
            var messages = await _outbox.GetUnsentAsync();

            var publishTasks = messages.Select(om => _publisher.PublishAsync(om.Message, om.MessageId,
                                                                             om.CorrelationId, om.SpanContext, om.MessageContext, om.Headers));
            await Task.WhenAll(publishTasks);

            await _outbox.ProcessAsync(messages);
        }
Example #3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            while (true)
            {
                var messages = await _outbox.GetUnsentAsync();

                var publishTasks = messages.Select(om => _publisher.PublishAsync(om.Message, om.MessageId.ToString()));
                await Task.WhenAll(publishTasks);

                await _outbox.ProcessAsync(messages);

                await Task.Delay(2000, cancellationToken);
            }
        }