Пример #1
0
        public void Retry()
        {
            string         name     = "Retry";
            List <Message> messages = new List <Message>();

            host.RegisterMessageProcessor(name, new TestMessageProcessor(50, messages));
            linkProcessor = new TestLinkProcessor();
            host.RegisterLinkProcessor(linkProcessor);

            int count      = 80;
            var connection = new Connection(Address);
            var session    = new Session(connection);
            var sender     = new SenderLink(session, "send-link", name);

            for (int i = 0; i < count; i++)
            {
                var m = new Message("msg" + i)
                {
                    ApplicationProperties = new ApplicationProperties(), Header = new Header()
                    {
                        DeliveryCount = 0
                    }, Properties = new Properties()
                    {
                        MessageId = name + i, GroupId = name
                    }
                };
                sender.Send(m, Timeout);
            }
            sender.Close();

            host.RegisterMessageSource(name, new TestMessageSource(new Queue <Message>(messages)));
            var receiver      = new ReceiverLink(session, "recv-link", name);
            var message       = receiver.Receive();
            var deliveryCount = message.Header.DeliveryCount;
            var delay         = 10 * deliveryCount;
            var scheduleTime  = DateTime.UtcNow.AddSeconds(delay);

            using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) {
                var sndr = new SenderLink(session, "retry", "test.queue");
                // create a new message to be queued with scheduled delivery time
                var retry = new Message(message.GetBody <string>())
                {
                    Header                = message.Header,
                    Footer                = message.Footer,
                    Properties            = message.Properties,
                    ApplicationProperties = message.ApplicationProperties
                };
                retry.ApplicationProperties[Constants.SCHEDULED_ENQUEUE_TIME_UTC] = scheduleTime;
                sndr.Send(retry);
                receiver.Accept(message);
            }

            receiver.Close();
            session.Close();
            connection.Close();
        }
Пример #2
0
        public void ContainerHostProcessorOrderTest()
        {
            string         name      = "ContainerHostProcessorOrderTest";
            List <Message> messages  = new List <Message>();
            var            processor = new TestMessageProcessor(50, messages);

            host.RegisterMessageProcessor(name, processor);
            linkProcessor = new TestLinkProcessor();
            host.RegisterLinkProcessor(linkProcessor);

            int count      = 80;
            var connection = new Connection(Address);
            var session    = new Session(connection);
            var sender     = new SenderLink(session, "send-link", name);

            for (int i = 0; i < count; i++)
            {
                var message = new Message("msg" + i);
                message.Properties = new Properties()
                {
                    GroupId = name
                };
                sender.Send(message, Timeout);
            }

            sender.Close();

            Assert.Equal(count, messages.Count);

            host.RegisterMessageSource(name, new TestMessageSource(new Queue <Message>(messages)));
            var receiver = new ReceiverLink(session, "recv-link", name);

            for (int i = 0; i < count; i++)
            {
                var message = receiver.Receive();
                receiver.Accept(message);
            }

            receiver.Close();

            sender = new SenderLink(session, "send-link", "any");
            for (int i = 0; i < count; i++)
            {
                var message = new Message("msg" + i);
                message.Properties = new Properties()
                {
                    GroupId = name
                };
                sender.Send(message, Timeout);
            }

            sender.Close();
            session.Close();
            connection.Close();
        }
Пример #3
0
        public async Task ShouldReceiveMessage_RejectAsync()
        {
            receiverSettings.Queue = Guid.NewGuid().ToString();

            List <Message> messages = new List <Message>();

            host.RegisterMessageProcessor(receiverSettings.Queue + "TestEvent", new TestMessageProcessor(50, messages));
            linkProcessor = new TestLinkProcessor();
            host.RegisterLinkProcessor(linkProcessor);

            int count = 1;

            publisterSettings.Topic = receiverSettings.Queue;
            var publisher = new DomainEventPublisher(publisterSettings, new NullLogger <DomainEventPublisher>());

            for (int i = 0; i < count; i++)
            {
                var @event = new TestEvent()
                {
                    IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
                };
                await publisher.PublishAsync(@event).ConfigureAwait(false);
            }

            var source = new TestMessageSource(new Queue <Message>(messages));

            host.RegisterMessageSource(receiverSettings.Queue, source);
            using (var receiver = new DomainEventReceiver(receiverSettings, provider, new NullLogger <DomainEventReceiver>())) {
                receiver.Start(eventTypes);
                int waits = 0;
                do
                {
                    await Task.Delay(1000).ConfigureAwait(false);

                    if (receiver.Link.LinkState == LinkState.Attached)
                    {
                        break;
                    }
                    waits++;
                }while (waits < 20);

                for (int i = 0; i < count; i++)
                {
                    var message = receiver.Receive(TimeSpan.FromSeconds(10));
                    message.Reject();
                    await Task.Delay(1000).ConfigureAwait(false);
                }
            }

            Assert.Equal(count, source.DeadLetterCount);
            Assert.Equal(0, source.Count);
        }
Пример #4
0
        public async Task ShouldReceiveMessage_Accept()
        {
            receiverSettings.Queue = Guid.NewGuid().ToString();

            List <Message> messages = new List <Message>();

            host.RegisterMessageProcessor(receiverSettings.Queue + "TestEvent", new TestMessageProcessor(50, messages));
            linkProcessor = new TestLinkProcessor();
            host.RegisterLinkProcessor(linkProcessor);

            int count = 1;

            publisterSettings.Topic = receiverSettings.Queue;
            var publisher = new DomainEventPublisher(publisterSettings, new NullLogger <DomainEventPublisher>());

            for (int i = 0; i < count; i++)
            {
                var @event = new TestEvent()
                {
                    IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
                };
                await publisher.PublishAsync(@event).ConfigureAwait(false);
            }

            var source = new TestMessageSource(new Queue <Message>(messages));

            host.RegisterMessageSource(receiverSettings.Queue, source);
            using (var receiver = new DomainEventReceiver(receiverSettings, provider, new NullLogger <DomainEventReceiver>())) {
                receiver.Start(eventTypes);
                for (int i = 0; i < count; i++)
                {
                    var message = receiver.Receive(TimeSpan.FromSeconds(1));
                    Assert.NotNull(message.GetData <TestEvent>());
                    message.Accept();
                }
            }

            Assert.Equal(0, source.DeadLetterCount);
            Assert.Equal(0, source.Count);
        }