Beispiel #1
0
        private async Task ProcessOutboxMessageCore(IOutboxMessage outboxMessage, CancellationToken cancellationToken)
        {
            var handler = _handlerFactory.GetMessageHandler(outboxMessage);

            try
            {
                await handler.ProcessMessage(outboxMessage, cancellationToken).ConfigureAwait(false);
            }
            finally
            {
                if (handler is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }
        }
        public async Task CantProcessNullMessageAsync()
        {
            // Arrange
            var            uow       = new Mock <IOutboxUnitOfWork>();
            var            sender    = new Mock <IOutboxSender>();
            var            ilogger   = new Mock <ILogger <OutboxMessageProcessor> >();
            var            processor = new OutboxMessageProcessor(uow.Object, sender.Object, ilogger.Object);
            var            cts       = new CancellationTokenSource();
            IOutboxMessage message   = null !;

            // Act
            var exception = await Record.ExceptionAsync(async() => _ = await processor.TryProcessAsync(message, cts.Token));

            // Assert
            exception.Should().NotBeNull().And.BeOfType <ArgumentNullException>();
        }
Beispiel #3
0
        public IOutboxMessageHandler GetMessageHandler(IOutboxMessage outboxMessage)
        {
            if (outboxMessage == null)
            {
                throw new ArgumentNullException(nameof(outboxMessage));
            }

            var type        = outboxMessage.GetType();
            var handlerType = typeof(IOutboxMessageHandler <>).MakeGenericType(type);

            if (_serviceProvider.GetService(handlerType) is IOutboxMessageHandler handler)
            {
                return(handler);
            }

            throw new OutboxException($"Can't resolve message handler for '{handlerType}'");
        }
Beispiel #4
0
        /// <inheritdoc/>
        public async Task SendAsync(IOutboxMessage message, CancellationToken cancellationToken = default)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var strMessage = _serializer.Serialize(message);

            try
            {
                _logger.LogInformation("Sending data {strMessage}.", strMessage);

                var dr = await _producer.ProduceAsync(_topicName, new Message <Null, string>
                {
                    Value = strMessage
                }, cancellationToken).ConfigureAwait(false);
            }
            catch (ProduceException <Null, string> e)
            {
                _logger.LogError(e, $"Delivery failed: {e.Error.Reason}.");
                throw;
            }
        }
 public Task ProcessMessage(IOutboxMessage outbox, CancellationToken cancellationToken)
 {
     return(ProcessMessage((TestOutboxCommand)outbox, cancellationToken));
 }
Beispiel #6
0
 private void UpdateOutboxMessage(IOutboxMessage mi)
 {
     using (var db = _serviceManager.CreateDBContext())
         db
             .OutboxMessages(m => m.ID == mi.ID)
             .Set(_ => _.ForumID, m => mi.ForumId)
             .Set(_ => _.Subject, m => mi.Subject)
             .Set(_ => _.Body, m => mi.Message)
             .Set(_ => _.Hold, m => mi.Hold)
             .Update();
 }