Пример #1
0
        public OutboxHostedService(IServiceScopeFactory serviceScopeFactory, IBusPublisher publisher, OutboxOptions options,
                                   ILogger <OutboxHostedService> logger)
        {
            if (options.Enabled && options.IntervalMilliseconds <= 0)
            {
                throw new Exception($"Invalid outbox interval: {options.IntervalMilliseconds} ms.");
            }

            if (!string.IsNullOrWhiteSpace(options.Type))
            {
                if (!Enum.TryParse <OutboxType>(options.Type, true, out var outboxType))
                {
                    throw new ArgumentException($"Invalid outbox type: '{_type}', " +
                                                $"valid types: '{OutboxType.Sequential}', '{OutboxType.Parallel}'.");
                }

                _type = outboxType;
            }

            _serviceScopeFactory = serviceScopeFactory;
            _publisher           = publisher;
            _options             = options;
            _logger   = logger;
            _type     = OutboxType.Sequential;
            _interval = TimeSpan.FromMilliseconds(options.IntervalMilliseconds);
            if (options.Enabled)
            {
                _logger.LogInformation($"Outbox is enabled, type: '{_type}', message processing every {options.IntervalMilliseconds} ms.");
                return;
            }

            _logger.LogInformation("Outbox is disabled.");
        }
Пример #2
0
 public MessageOutboxBuilder(IBareBonesBuilder builder, OutboxOptions options)
 {
     Builder = builder;
     Options = options;
 }