public OutboxBackgroundService(IServiceScopeFactory scopeFactory, OutboxProcessorOptions options,
                                ILogger <OutboxBackgroundService> logger)
 {
     _scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory));
     _options      = options ?? throw new ArgumentNullException(nameof(options));
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Ejemplo n.º 2
0
 public OutboxProcessor(IOutboxRepository outboxRepository,
                        IPublisher publisher,
                        OutboxProcessorOptions options,
                        ILogger <OutboxProcessor> logger)
 {
     _outboxRepository = outboxRepository ?? throw new ArgumentNullException(nameof(outboxRepository));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _options          = options ?? throw new ArgumentNullException(nameof(options));
     _publisher        = publisher ?? throw new ArgumentNullException(nameof(publisher));
 }
Ejemplo n.º 3
0
        public IBusConfigurator WithOutboxProcessorOptions(OutboxProcessorOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.Services.Replace(ServiceDescriptor.Singleton(options));

            return(this);
        }
Ejemplo n.º 4
0
        public async Task StartAsync_should_do_nothing_when_no_pending_messages_available()
        {
            var repo      = NSubstitute.Substitute.For <IOutboxRepository>();
            var publisher = NSubstitute.Substitute.For <IPublisher>();
            var options   = new OutboxProcessorOptions(TimeSpan.FromSeconds(2));
            var logger    = NSubstitute.Substitute.For <ILogger <OutboxProcessor> >();

            var sut = new OutboxProcessor(repo, publisher, options, logger);

            var token = new CancellationTokenSource(options.Interval);

            try
            {
                await sut.StartAsync(token.Token);
            }
            catch (TaskCanceledException) { }

            await repo.Received().ReadMessagesToProcess(Arg.Any <CancellationToken>());

            await publisher.DidNotReceiveWithAnyArgs().PublishAsync(Arg.Any <IMessage>(), Arg.Any <CancellationToken>());
        }
Ejemplo n.º 5
0
        public async Task StartAsync_process_pending_messages_()
        {
            var messages = new[]
            {
                StartDummySaga.New(),
                StartDummySaga.New(),
                StartDummySaga.New()
            };
            var repo = NSubstitute.Substitute.For <IOutboxRepository>();

            repo.ReadMessagesToProcess(Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(messages);

            var publisher = NSubstitute.Substitute.For <IPublisher>();
            var options   = new OutboxProcessorOptions(TimeSpan.FromSeconds(2));
            var logger    = NSubstitute.Substitute.For <ILogger <OutboxProcessor> >();

            var sut = new OutboxProcessor(repo, publisher, options, logger);

            var token = new CancellationTokenSource(options.Interval);

            try
            {
                await sut.StartAsync(token.Token);
            }
            catch (TaskCanceledException) { }

            await repo.Received().ReadMessagesToProcess(Arg.Any <CancellationToken>());

            foreach (var message in messages)
            {
                await publisher.Received(1)
                .PublishAsync(message, Arg.Any <CancellationToken>());

                await repo.MarkAsSentAsync(message, Arg.Any <CancellationToken>());
            }
        }