Пример #1
0
        public void TcpTransportTest()
        {
            const string localHost = "localhost";
            const int    port      = 30888;

            TransportTestContext serverContext = new TransportTestContext()
            {
                MaxNumber         = TestMaxNumber,
                TransportSettings = AmqpUtils.GetTcpSettings(localHost, port, true)
            };

            TransportTestContext clientContext = new TransportTestContext()
            {
                MaxNumber         = TestMaxNumber,
                TransportSettings = AmqpUtils.GetTcpSettings(localHost, port, false)
            };

            Thread listenerThread = new Thread(new ParameterizedThreadStart(ListenerThread));

            listenerThread.Start(serverContext);

            Thread initiatorThread = new Thread(new ParameterizedThreadStart(InitiatorThread));

            initiatorThread.Start(clientContext);

            listenerThread.Join();
            initiatorThread.Join();

            Trace.WriteLine("TCP transport test completed.");
            Assert.IsTrue(clientContext.Success);
            Assert.IsTrue(serverContext.Success);
        }
Пример #2
0
        public static AmqpConnection CreateConnection(Uri uri, string sslHost, bool doSslUpgrade, SaslHandler saslHandler, int maxFrameSize, uint?idleTimeoutMs = null)
        {
            if (uri.IsSecureTransport() && sslHost == null)
            {
                sslHost = uri.Host;
            }

            return(AmqpUtils.CreateConnection(uri.Host, uri.Port, sslHost, doSslUpgrade, saslHandler, maxFrameSize, idleTimeoutMs));
        }
Пример #3
0
        public void AmqpWebSocketTransportTest()
        {
            string address = "ws://localhost:28088";
            var    broker  = new TestAmqpBroker(new string[] { address }, null, null, null);

            try
            {
                broker.Start();

                string queue = "AmqpWebSocketTransportTest";
                broker.AddQueue(queue);

                AmqpConnection connection = AmqpConnection.Factory.OpenConnectionAsync(address).GetAwaiter().GetResult();

                AmqpSession session = connection.CreateSession(new AmqpSessionSettings());
                session.Open();

                SendingAmqpLink sLink = new SendingAmqpLink(session, AmqpUtils.GetLinkSettings(true, queue, SettleMode.SettleOnSend));
                sLink.Open();

                int messageCount = 100;
                for (int i = 0; i < messageCount; i++)
                {
                    AmqpMessage message = AmqpMessage.Create(new AmqpValue()
                    {
                        Value = "message" + i
                    });
                    sLink.SendMessageAsync(message, AmqpConstants.EmptyBinary, AmqpConstants.NullBinary, TimeSpan.FromSeconds(10)).Wait();
                }

                sLink.Close();

                ReceivingAmqpLink rLink = new ReceivingAmqpLink(session, AmqpUtils.GetLinkSettings(false, queue, SettleMode.SettleOnReceive, 100));
                rLink.Open();

                for (int i = 0; i < messageCount; i++)
                {
                    AmqpMessage message2 = rLink.ReceiveMessageAsync(TimeSpan.FromSeconds(60)).GetAwaiter().GetResult();
                    Assert.NotNull(message2);

                    rLink.AcceptMessage(message2, false);
                    message2.Dispose();
                }

                rLink.Close();

                connection.Close();
            }
            finally
            {
                broker.Stop();
            }
        }
Пример #4
0
        public void AmqpWebSocketTransportTest()
        {
            string queue = "AmqpWebSocketTransportTest";

            broker.AddQueue(queue);

            AmqpConnection connection = AmqpConnection.Factory.OpenConnectionAsync(
                TestAmqpBrokerFixture.WsAddress.OriginalString).GetAwaiter().GetResult();

            AmqpSession session = connection.CreateSession(new AmqpSessionSettings());

            session.Open();

            SendingAmqpLink sLink = new SendingAmqpLink(session, AmqpUtils.GetLinkSettings(true, queue, SettleMode.SettleOnSend));

            sLink.Open();

            int messageCount = 1800;

            for (int i = 0; i < messageCount; i++)
            {
                AmqpMessage message = AmqpMessage.Create(new AmqpValue()
                {
                    Value = "message" + i
                });
                sLink.SendMessageAsync(message, EmptyBinary, NullBinary, TimeSpan.FromSeconds(10)).Wait();
            }

            sLink.Close();

            ReceivingAmqpLink rLink = new ReceivingAmqpLink(session, AmqpUtils.GetLinkSettings(false, queue, SettleMode.SettleOnReceive, 100));

            rLink.Open();

            for (int i = 0; i < messageCount; i++)
            {
                AmqpMessage message2 = rLink.ReceiveMessageAsync(TimeSpan.FromSeconds(60)).GetAwaiter().GetResult();
                Assert.NotNull(message2);

                rLink.AcceptMessage(message2);
                message2.Dispose();
            }

            rLink.Close();

            connection.Close();
        }
        public async Task ListenerSaslTlsTest()
        {
            string address = "amqps://*****:*****@localhost:5676";

            AmqpSettings           settings           = AmqpUtils.GetAmqpSettings(false, "localhost", false, new SaslPlainHandler(new TestSaslPlainAuthenticator()));
            AmqpConnectionSettings connectionSettings = AmqpUtils.GetConnectionSettings(32 * 1024);

            settings.RuntimeProvider = new TestRuntimeProvider();
            AmqpConnectionListener listener = new AmqpConnectionListener(new[] { address }, settings, connectionSettings);

            listener.Open();

            try
            {
                await RunClientAsync(address);
            }
            finally
            {
                listener.Close();
            }
        }
        async Task RunClientAsync(string address)
        {
            AmqpConnectionFactory factory = new AmqpConnectionFactory();

            factory.Settings.TransportProviders.Add(
                new TlsTransportProvider(
                    new TlsTransportSettings()
            {
                CertificateValidationCallback = (a, b, c, d) => true
            },
                    AmqpVersion.V100));

            AmqpConnection connection = await factory.OpenConnectionAsync(address);

            AmqpSession session = connection.CreateSession(new AmqpSessionSettings());
            await session.OpenAsync(TimeSpan.FromSeconds(20));

            SendingAmqpLink sLink = new SendingAmqpLink(session, AmqpUtils.GetLinkSettings(true, queue, SettleMode.SettleOnSend));
            await sLink.OpenAsync(TimeSpan.FromSeconds(20));

            AmqpMessage message = AmqpMessage.Create(new AmqpValue()
            {
                Value = "AmqpConnectionFactoryTest"
            });
            Outcome outcome = await sLink.SendMessageAsync(message, EmptyBinary, NullBinary, TimeSpan.FromSeconds(10));

            Assert.Equal(Accepted.Code, outcome.DescriptorCode);

            ReceivingAmqpLink rLink = new ReceivingAmqpLink(session, AmqpUtils.GetLinkSettings(false, queue, SettleMode.SettleOnDispose, 10));
            await rLink.OpenAsync(TimeSpan.FromSeconds(20));

            var receivedMessage = await rLink.ReceiveMessageAsync(TimeSpan.FromSeconds(20));

            Assert.NotNull(receivedMessage);
            outcome = await rLink.DisposeMessageAsync(receivedMessage.DeliveryTag, new Accepted(), false, TimeSpan.FromSeconds(20));

            Assert.Equal(Accepted.Code, outcome.DescriptorCode);

            await connection.CloseAsync(TimeSpan.FromSeconds(20));
        }
Пример #7
0
        public void AmqpMessageSerializationTest()
        {
            // empty message
            AmqpMessage message = AmqpMessage.Create();

            AddSection(message, SectionFlag.Properties);
            RunSerializationTest(message);

            // data message
            message = AmqpMessage.Create(new Data()
            {
                Value = new ArraySegment <byte>(new byte[60])
            });
            RunSerializationTest(message);

            message = AmqpMessage.Create(new Data[] { new Data()
                                                      {
                                                          Value = new ArraySegment <byte>(new byte[60])
                                                      }, new Data()
                                                      {
                                                          Value = new ArraySegment <byte>(new byte[44])
                                                      } });
            AddSection(message, SectionFlag.Header | SectionFlag.ApplicationProperties);
            RunSerializationTest(message);

            // value message
            message = AmqpMessage.Create(new AmqpValue()
            {
                Value = new AmqpSymbol("symbol value")
            });
            AddSection(message, SectionFlag.Header | SectionFlag.DeliveryAnnotations | SectionFlag.ApplicationProperties);
            RunSerializationTest(message);

            // sequence message
            message = AmqpMessage.Create(new AmqpSequence[] { new AmqpSequence(new List <object>()
                {
                    "string1", 1234
                }), new AmqpSequence(new List <object>()
                {
                    DateTime.Parse("2012-01-01 12:00:00").ToUniversalTime()
                }) });
            AddSection(message, SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties | SectionFlag.Footer);
            RunSerializationTest(message);

            // data message - binary
            message = AmqpUtils.CreateMessage(new byte[888]);
            AddSection(message, SectionFlag.DeliveryAnnotations | SectionFlag.ApplicationProperties | SectionFlag.Footer);
            RunSerializationTest(message);

            // body stream message
            message = AmqpMessage.Create(new MemoryStream(new byte[679]), true);
            AddSection(message, SectionFlag.Header | SectionFlag.MessageAnnotations | SectionFlag.Footer);
            RunSerializationTest(message);

            // the following simulates a message's round trip from client to broker to client
            // message -serialize-> buffers -> input stream message -> output stream message -deserialize> message
            message = AmqpMessage.Create(new AmqpValue()
            {
                Value = new AmqpSymbol("symbol value")
            });
            AddSection(message, SectionFlag.MessageAnnotations | SectionFlag.Properties | SectionFlag.ApplicationProperties);
            // serialize - send the message on client side
            // buffer message - received on broker side, clone for edit
            AmqpMessage message2 = CreateMessage(message, 71).Clone();

            AddSection(message2, SectionFlag.Header | SectionFlag.DeliveryAnnotations);
            message2.MessageAnnotations.Map["delivery-count"] = 5;
            // buffer message - received on client side
            AmqpMessage message3 = CreateMessage(message2, 73);

            // update the original message to match the updated message
            AddSection(message, SectionFlag.Header | SectionFlag.DeliveryAnnotations);
            message.MessageAnnotations.Map["delivery-count"] = 5;
            ValidateMessage(message, message3);
        }