Example #1
0
        public void EnsureNotDuplicateAsync()
        {
            var value           = new byte[] { 1, 2, 3 };
            var acceptor        = Substitute.For <IMessageAcceptor>();
            var lastMiddleware  = Substitute.For <IEventMiddleware <string> >();
            var middlewarequeue = new MiddlewareQueue <string>(_settings);

            middlewarequeue.AddMiddleware(_deduplicationMiddleware);
            middlewarequeue.AddMiddleware(lastMiddleware);

            middlewarequeue.RunMiddlewaresAsync(
                new BasicDeliverEventArgs
            {
                BasicProperties = new BasicProperties(),
                Body            = value
            },
                null,
                acceptor,
                CancellationToken.None)
            .GetAwaiter().GetResult();

            middlewarequeue.RunMiddlewaresAsync(
                new BasicDeliverEventArgs
            {
                BasicProperties = new BasicProperties(),
                Body            = value
            },
                null,
                acceptor,
                CancellationToken.None)
            .GetAwaiter().GetResult();

            lastMiddleware.Received(1).ProcessAsync(Arg.Any <IEventContext <string> >());
        }
Example #2
0
        private void MessageReceived(BasicDeliverEventArgs basicDeliverEventArgs, IModel channel)
        {
            var tag = basicDeliverEventArgs.DeliveryTag;
            var ma  = new MessageAcceptor(channel, tag);

            try
            {
                var model = _messageDeserializer.Deserialize(basicDeliverEventArgs.Body);

                try
                {
                    _middlewareQueue.RunMiddlewaresAsync(
                        basicDeliverEventArgs,
                        model,
                        ma,
                        _cancellationTokenSource.Token)
                    .GetAwaiter().GetResult();
                }
                catch (OperationCanceledException)
                {
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, _settings.GetSubscriberName());

                ma.Reject();
            }
        }
Example #3
0
        public void SuccessfulPath()
        {
            var acceptor        = Substitute.For <IMessageAcceptor>();
            var middlewarequeue = new MiddlewareQueue <string>(_settings);

            middlewarequeue.AddMiddleware(_middleware);
            middlewarequeue.AddMiddleware(new ActualHandlerMiddleware <string>(_ => Task.CompletedTask));

            middlewarequeue.RunMiddlewaresAsync(null, null, acceptor, CancellationToken.None).GetAwaiter().GetResult();

            acceptor.Received(1).Accept();
        }
Example #4
0
        public void ShouldResendToNextHandlerOnError()
        {
            var acceptor = Substitute.For <IMessageAcceptor>();
            var rootEventMiddlewareHandler = Substitute.For <IEventMiddleware <string> >();
            var middlewarequeue            = new MiddlewareQueue <string>(_settings);

            middlewarequeue.AddMiddleware(rootEventMiddlewareHandler);
            middlewarequeue.AddMiddleware(_middleware);
            middlewarequeue.AddMiddleware(new ActualHandlerMiddleware <string>(_ => throw new Exception()));

            middlewarequeue.RunMiddlewaresAsync(null, null, acceptor, CancellationToken.None).GetAwaiter().GetResult();

            rootEventMiddlewareHandler.Received(1).ProcessAsync(Arg.Any <IEventContext <string> >());
        }