상속: IMessageSource
예제 #1
0
        public void EncodeDecodeMessageWithAmqpValueTest()
        {
            string          name     = "EncodeDecodeMessageWithAmqpValueTest";
            Queue <Message> messages = new Queue <Message>();

            messages.Enqueue(new Message("test")
            {
                Properties = new Properties()
                {
                    MessageId = name
                }
            });

            var source = new TestMessageSource(messages);

            this.host.RegisterMessageSource(name, source);

            var connection = new Connection(Address);
            var session    = new Session(connection);
            var receiver   = new ReceiverLink(session, "receiver0", name);

            Message message = receiver.Receive();
            Message copy    = Message.Decode(message.Encode());

            Assert.AreEqual((message.BodySection as AmqpValue).Value, (copy.BodySection as AmqpValue).Value);
        }
예제 #2
0
        public void ContainerHostMessageSourceTest()
        {
            string          name     = "ContainerHostMessageSourceTest";
            int             count    = 100;
            Queue <Message> messages = new Queue <Message>();

            for (int i = 0; i < count; i++)
            {
                messages.Enqueue(new Message("test")
                {
                    Properties = new Properties()
                    {
                        MessageId = name + i
                    }
                });
            }

            var source = new TestMessageSource(messages);

            this.host.RegisterMessageSource(name, source);

            var connection = new Connection(Address);
            var session    = new Session(connection);
            var receiver   = new ReceiverLink(session, "receiver0", name);
            int released   = 0;
            int rejected   = 0;
            int ignored    = 0;

            for (int i = 1; i <= count; i++)
            {
                Message message = receiver.Receive();
                if (i % 5 == 0)
                {
                    receiver.Reject(message);
                    rejected++;
                }
                else if (i % 17 == 0)
                {
                    receiver.Release(message);
                    released++;
                }
                else if (i % 36 == 0)
                {
                    ignored++;
                }
                else
                {
                    receiver.Accept(message);
                }
            }

            receiver.Close();
            session.Close();
            connection.Close();

            Thread.Sleep(500);
            Assert.AreEqual(released + ignored, messages.Count, string.Join(",", messages.Select(m => m.Properties.MessageId)));
            Assert.AreEqual(rejected, source.DeadletterMessage.Count, string.Join(",", source.DeadletterMessage.Select(m => m.Properties.MessageId)));
        }
예제 #3
0
        public void ContainerHostSourceLinkEndpointTest()
        {
            string          name     = "ContainerHostSourceLinkEndpointTest";
            int             count    = 100;
            Queue <Message> messages = new Queue <Message>();

            for (int i = 0; i < count; i++)
            {
                messages.Enqueue(new Message("test")
                {
                    Properties = new Properties()
                    {
                        MessageId = name + i
                    }
                });
            }

            var source = new TestMessageSource(messages);

            this.linkProcessor = new TestLinkProcessor(link => new SourceLinkEndpoint(source, link));
            this.host.RegisterLinkProcessor(this.linkProcessor);

            var connection = new Connection(Address);
            var session    = new Session(connection);
            var receiver   = new ReceiverLink(session, "receiver0", name);
            int released   = 0;
            int rejected   = 0;

            for (int i = 1; i <= count; i++)
            {
                Message message = receiver.Receive();
                if (i % 5 == 0)
                {
                    receiver.Reject(message);
                    rejected++;
                }
                else if (i % 17 == 0)
                {
                    receiver.Release(message);
                    released++;
                }
                else
                {
                    receiver.Accept(message);
                }
            }

            receiver.Close();
            session.Close();
            connection.Close();

            Thread.Sleep(200);
            Assert.AreEqual(released, messages.Count);
            Assert.AreEqual(rejected, source.DeadletterMessage.Count);
        }
예제 #4
0
        public void ContainerHostSourceLinkEndpointTest()
        {
            string name = MethodInfo.GetCurrentMethod().Name;
            int count = 100;
            Queue<Message> messages = new Queue<Message>();
            for (int i = 0; i < count; i++)
            {
                messages.Enqueue(new Message("test") { Properties = new Properties() { MessageId = name + i } });
            }

            var source = new TestMessageSource(messages);
            this.host.RegisterLinkProcessor(new TestLinkProcessor(link => new SourceLinkEndpoint(source, link)));

            var connection = new Connection(Address);
            var session = new Session(connection);
            var receiver = new ReceiverLink(session, "receiver0", name);
            int released = 0;
            int rejected = 0;
            for (int i = 1; i <= count; i++)
            {
                Message message = receiver.Receive();
                if (i % 5 == 0)
                {
                    receiver.Reject(message);
                    rejected++;
                }
                else if (i % 17 == 0)
                {
                    receiver.Release(message);
                    released++;
                }
                else
                {
                    receiver.Accept(message);
                }
            }

            receiver.Close();
            session.Close();
            connection.Close();

            Assert.AreEqual(released, messages.Count);
            Assert.AreEqual(rejected, source.DeadletterMessage.Count);
        }