public void FailoverURL()
        {
            //String url = "amqp://*****:*****@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";
            String url = "amqp://*****:*****@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.AreEqual("roundrobin", connectionurl.FailoverMethod);
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals("bob"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.IsTrue(connectionurl.BrokerCount == 2);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);

            service = connectionurl.GetBrokerInfo(1);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("fancyserver"));
            Assert.IsTrue(service.Port == 3000);
        }
        public void ConnectionFailure()
        {
            string url = "amqp://*****:*****@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''";

            new AMQConnection(QpidConnectionInfo.FromUrl(url));
            Assert.Fail("Connection should not be established");
        }
Beispiel #3
0
        public virtual void Init()
        {
            _logger.Info("public virtual void Init(): called");

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI);

            _connection = new AMQConnection(connectionInfo);
            _logger.Info("Starting...");

            // Register this to listen for exceptions on the test connection.
            _exceptionDelegate             = new ExceptionListenerDelegate(OnException);
            _connection.ExceptionListener += _exceptionDelegate;

            // Establish a session on the broker.
            _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

            // Create a durable, non-temporary, non-exclusive queue.
            _queueName = _channel.GenerateUniqueName();
            _channel.DeclareQueue(_queueName, true, false, false);

            _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey);

            // Clear the most recent message and exception.
            _lastException = null;
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            try
            {
                const string connectionUrl = @"amqp://*****:*****@clientid/test?brokerlist='tcp://localhost:5672'";
                const string queueName     = @"test-queue";

                var connectionInfo = QpidConnectionInfo.FromUrl(connectionUrl);
                var connection     = new AMQConnection(connectionInfo);
                var channel        = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

                channel.DeclareQueue(queueName, false, true, true);
                channel.Bind(queueName, ExchangeNameDefaults.DIRECT, queueName);
                IMessageConsumer consumer = channel.CreateConsumerBuilder(queueName).Create();
                connection.Start();

                ITextMessage message = (ITextMessage)consumer.Receive();
                Console.WriteLine("Got: " + message.Text);
                connection.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public void CheckVirtualHostFormat()
        {
            String url = "amqp://*****:*****@default/t.-_+!=:?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connection = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connection.VirtualHost.Equals("/t.-_+!=:"));
        }
Beispiel #6
0
        /// <summary> Sets up the nth test end-point. </summary>
        ///
        /// <param name="n">The index of the test end-point to set up.</param>
        /// <param name="producer"><tt>true</tt> to set up a producer on the end-point.</param>
        /// <param name="consumer"><tt>true</tt> to set up a consumer on the end-point.</param>
        /// <param name="routingKey">The routing key for the producer to send on.</param>
        /// <param name="ackMode">The ack mode for the end-points channel.</param>
        /// <param name="transacted"><tt>true</tt> to use transactions on the end-points channel.</param>
        /// <param name="exchangeName">The exchange to produce or consume on.</param>
        /// <param name="declareBind"><tt>true</tt> if the consumers queue should be declared and bound, <tt>false</tt> if it has already been.</param>
        /// <param name="durable"><tt>true</tt> to declare the consumers queue as durable.</param>
        /// <param name="subscriptionName">If durable is true, the fixed unique queue name to use.</param>
        /// <param name="exclusive"><tt>true</tt> declare queue as exclusive.</param>
        /// <param name="browse"><tt>true</tt> only browse, don''t consume.</param>
        public void SetUpEndPoint(int n, bool producer, bool consumer, string routingKey, AcknowledgeMode ackMode, bool transacted,
                                  string exchangeName, bool declareBind, bool durable, string subscriptionName, bool exclusive, bool browse)
        {
            // Allow client id to be fixed, or undefined.
            {
                // Use unique id for end point.
                connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);

                connectionInfo.ClientName = "test" + n;
            }

            testConnection[n] = new AMQConnection(connectionInfo);
            testConnection[n].Start();
            testChannel[n] = testConnection[n].CreateChannel(transacted, ackMode);

            if (producer)
            {
                testProducer[n] = testChannel[n].CreatePublisherBuilder()
                                  .WithExchangeName(exchangeName)
                                  .WithRoutingKey(routingKey)
                                  .Create();
            }

            if (consumer)
            {
                string queueName;

                // Use the subscription name as the queue name if the subscription is durable, otherwise use a generated name.
                if (durable)
                {
                    // The durable queue is declared without auto-delete, and passively, in case it has already been declared.
                    queueName = subscriptionName;

                    if (declareBind)
                    {
                        testChannel[n].DeclareQueue(queueName, durable, exclusive, false);
                        testChannel[n].Bind(queueName, exchangeName, routingKey);
                    }
                }
                else
                {
                    queueName = testChannel[n].GenerateUniqueName();

                    if (declareBind)
                    {
                        if (durable)
                        {
                            testQueue[n] = queueName;
                        }
                        testChannel[n].DeclareQueue(queueName, durable, true, true);
                        testChannel[n].Bind(queueName, exchangeName, routingKey);
                    }
                }

                testConsumer[n] = testChannel[n].CreateConsumerBuilder(queueName).WithBrowse(browse).Create();
            }
        }
Beispiel #7
0
 public void SimpleConnection()
 {
     IConnectionInfo connectionInfo = new QpidConnectionInfo();
     connectionInfo.VirtualHost = "test";
     connectionInfo.AddBrokerInfo(_broker);
     using (IConnection connection = new AMQConnection(connectionInfo))
     {
         Console.WriteLine("connection = " + connection);
     }
 }
        public void CheckDefaultPort()
        {
            String url = "amqp://*****:*****@default/test=:?brokerlist='tcp://localhost'";

            IConnectionInfo connection = QpidConnectionInfo.FromUrl(url);

            IBrokerInfo broker = connection.GetBrokerInfo(0);

            Assert.IsTrue(broker.Port == BrokerInfoConstants.DEFAULT_PORT);
        }
 private static void MakeBrokerConnection(SslOptions options)
 {
     IConnectionInfo connectionInfo = new QpidConnectionInfo();
     connectionInfo.VirtualHost = "test";
     connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 8672, options));
     
     using ( IConnection connection = new AMQConnection(connectionInfo) )
     {
         Console.WriteLine("connection = " + connection);
     }
 }
        public void SimpleConnection()
        {
            IConnectionInfo connectionInfo = new QpidConnectionInfo();

            connectionInfo.VirtualHost = "test";
            connectionInfo.AddBrokerInfo(_broker);
            using (IConnection connection = new AMQConnection(connectionInfo))
            {
                Console.WriteLine("connection = " + connection);
            }
        }
        private static void MakeBrokerConnection(SslOptions options)
        {
            IConnectionInfo connectionInfo = new QpidConnectionInfo();

            connectionInfo.VirtualHost = "test";
            connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 8672, options));

            using (IConnection connection = new AMQConnection(connectionInfo))
            {
                Console.WriteLine("connection = " + connection);
            }
        }
Beispiel #12
0
        public override void Init()
        {
            // Ensure that the base init method is called. It establishes a connection with the broker.
            base.Init();

            connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);
            _connection    = new AMQConnection(connectionInfo);
            _channel       = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300);

            _logger.Info("Starting...");
            _logger.Info("Exchange name is '" + _exchangeName + "'...");

            // Register this to listen for exceptions on the test connection.
            _exceptionDelegate             = new ExceptionListenerDelegate(OnException);
            _connection.ExceptionListener += _exceptionDelegate;

            // Declare a new headers exchange with the name of the test service.
            _channel.DeclareExchange(_exchangeName, ExchangeClassConstants.HEADERS);

            // Create a non-durable, temporary (aka auto-delete), exclusive queue.
            string queueName = _channel.GenerateUniqueName();

            _channel.DeclareQueue(queueName, false, true, true);

            // Bind the queue to the new headers exchange, setting up some header patterns for the exchange to match.
            _channel.Bind(queueName, _exchangeName, null, CreatePatternAsFieldTable());

            // Create a test consumer to consume messages from the test exchange.
            _consumer = _channel.CreateConsumerBuilder(queueName)
                        .WithPrefetchLow(100)
                        .WithPrefetchHigh(500)
                        .WithNoLocal(false) // make sure we get our own messages
                        .Create();

            // Register this to listen for messages on the consumer.
            _msgRecDelegate      = new MessageReceivedDelegate(OnMessage);
            _consumer.OnMessage += _msgRecDelegate;

            // Clear the most recent message and exception.
            _lastException = null;
            _lastMessage   = null;

            _publisher = _channel.CreatePublisherBuilder()
                         .WithExchangeName(_exchangeName)
                         .WithMandatory(true)
                         .Create();

            _publisher.DeliveryMode = DeliveryMode.NonPersistent;

            // Start all channel
            _connection.Start();
        }
        public void NoClientID()
        {
            String url = "amqp://user:@default/test?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.Username.Equals("user"));
            Assert.IsTrue(connectionurl.Password.Equals(""));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/test"));
            Assert.IsTrue(connectionurl.ClientName.StartsWith(Dns.GetHostName()));

            Assert.IsTrue(connectionurl.BrokerCount == 1);
        }
        /// <summary>
        /// Establishes an AMQ connection. This is a simple convenience method for code that does not anticipate handling connection failures.
        /// All exceptions that indicate that the connection has failed, are allowed to fall through.
        /// </summary>
        ///
        /// <param name="brokerUrl">   The broker url to connect to, <tt>null</tt> to use the default from the properties. </param>
        /// <param name="virtualHost"> The virtual host to connectio to, <tt>null</tt> to use the default. </param>
        ///
        /// <returns> A JMS conneciton. </returns>
        public static IConnection CreateConnection(string brokerUrl, string virtualHost)
        {
            log.Info("public static Connection createConnection(string brokerUrl = " + brokerUrl + ", string virtualHost = "
                     + virtualHost + "): called");

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(brokerUrl);

            connectionInfo.VirtualHost = virtualHost;
            IConnection connection = new AMQConnection(connectionInfo);

            return(connection);
        }
        public void TestWithUrl()
        {
            _log.Debug("public void runTestWithUrl(): called");

            // Parse the connection parameters from a URL.
            String clientId   = "failover" + DateTime.Now.Ticks;
            string defaultUrl = "amqp://*****:*****@" + clientId + "/test" +
                                "?brokerlist='tcp://localhost:9672;tcp://localhost:9673'&failover='roundrobin'";
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(defaultUrl);

            Init(connectionInfo);
            DoFailoverTest(0);
        }
Beispiel #16
0
        public void PasswordFailureConnection()
        {
            IConnectionInfo connectionInfo = new QpidConnectionInfo();
            connectionInfo.VirtualHost = "test";
            connectionInfo.Password = "******";
            connectionInfo.AddBrokerInfo(_broker);

            using (IConnection connection = new AMQConnection(connectionInfo))
            {
                 Console.WriteLine("connection = " + connection);
                 // wrong
                 Assert.Fail("Authentication succeeded but should've failed");
            }
        }
        public void NoVirtualHostURL()
        {
            String url = "amqp://user@default?brokerlist='tcp://localhost:5672'";

            try
            {
                QpidConnectionInfo.FromUrl(url);
                Assert.Fail("URL has no virtual host should not parse");
            }
            catch (UrlSyntaxException)
            {
                // This should occur.
            }
        }
        public void WrongOptionSeparatorInOptions()
        {
            String url = "amqp://*****:*****@default/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'";

            try
            {
                QpidConnectionInfo.FromUrl(url);
                Assert.Fail("URL Should not parse");
            }
            catch (UrlSyntaxException urise)
            {
                Assert.IsTrue(urise.Message.Equals("Unterminated option. Possible illegal option separator:'+'"));
            }
        }
        public void CheckMissingFinalQuote()
        {
            String url = "amqp://*****:*****@id/test" + "?brokerlist='tcp://localhost:5672";

            try
            {
                QpidConnectionInfo.FromUrl(url);
            }
            catch (UrlSyntaxException e)
            {
//                Assert.AreEqual("Unterminated option at index 32: brokerlist='tcp://localhost:5672",
//                    e.Message);
                Assert.AreEqual("Unterminated option", e.Message);
            }
        }
        public void NoUserDetailsProvidedNOClientID()

        {
            String url = "amqp:///test@default?brokerlist='tcp://localhost:5672;tcp://localhost:5673'";

            try
            {
                QpidConnectionInfo.FromUrl(url);
                Assert.Fail("URL Should not parse");
            }
            catch (UrlSyntaxException urise)
            {
                Assert.IsTrue(urise.Message.StartsWith("User information not found on url"));
            }
        }
        public void FailedURLNullPassword()
        {
            String url = "amqp://ritchiem@default/temp?brokerlist='tcp://localhost:5672'";

            try
            {
                QpidConnectionInfo.FromUrl(url);
                Assert.Fail("URL has null password");
            }
            catch (UrlSyntaxException e)
            {
                Assert.AreEqual("Null password in user information not allowed.", e.Message);
                Assert.IsTrue(e.GetIndex() == 7);
            }
        }
        public void PasswordFailureConnection()
        {
            IConnectionInfo connectionInfo = new QpidConnectionInfo();

            connectionInfo.VirtualHost = "test";
            connectionInfo.Password    = "******";
            connectionInfo.AddBrokerInfo(_broker);

            using (IConnection connection = new AMQConnection(connectionInfo))
            {
                Console.WriteLine("connection = " + connection);
                // wrong
                Assert.Fail("Authentication succeeded but should've failed");
            }
        }
        public void EnsureVirtualHostStartsWithSlash()
        {
            IConnectionInfo connection = new QpidConnectionInfo();

            connection.VirtualHost = "test";
            Assert.AreEqual("/test", connection.VirtualHost);

            connection.VirtualHost = "/mytest";
            Assert.AreEqual("/mytest", connection.VirtualHost);

            connection.VirtualHost = "";
            Assert.AreEqual("/", connection.VirtualHost);

            connection.VirtualHost = null;
            Assert.AreEqual("/", connection.VirtualHost);
        }
        public void Test5MinuteWait()
        {
            String clientId = "failover" + DateTime.Now.Ticks;

            QpidConnectionInfo connectionInfo = new QpidConnectionInfo();

            connectionInfo.Username    = "******";
            connectionInfo.Password    = "******";
            connectionInfo.ClientName  = clientId;
            connectionInfo.VirtualHost = "/test";
            connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 9672, false));
            connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 9673, false));

            Init(connectionInfo);
            DoFailoverTest(5);
        }
        public void ValidateQpidConnectionInfoFromToString()
        {
            String url = "amqp://*****:*****@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";

            IConnectionInfo connectionInfo  = QpidConnectionInfo.FromUrl(url);
            IConnectionInfo connectionInfo1 = QpidConnectionInfo.FromUrl(connectionInfo.ToString());

            Console.WriteLine(connectionInfo.ToString());
            Console.WriteLine(connectionInfo1.ToString());

            Assert.AreEqual(connectionInfo.Username, connectionInfo1.Username);
            Assert.AreEqual(connectionInfo.Password, connectionInfo1.Password);
            Assert.AreEqual(connectionInfo.VirtualHost, connectionInfo1.VirtualHost);

            Assert.IsTrue((connectionInfo1.GetAllBrokerInfos().Count == 2));
            Assert.IsTrue(connectionInfo.GetBrokerInfo(0).Equals(connectionInfo1.GetBrokerInfo(0)));
            Assert.IsTrue(connectionInfo.GetBrokerInfo(1).Equals(connectionInfo1.GetBrokerInfo(1)));
        }
        /// <summary> Creates a topic listener using the specified broker URL. </summary>
        ///
        /// <param name="connectionUri">The broker URL to listen on.</param>
        TopicListener(string connectionUri)
        {
            LogDebug("TopicListener(string connectionUri = " + connectionUri + "): called");

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);

            connection = new AMQConnection(connectionInfo);

            // Establish a session on the broker.
            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

            // Set up a queue to listen for test messages on.
            string topicQueueName = channel.GenerateUniqueName();

            channel.DeclareQueue(topicQueueName, false, true, true);

            // Set this listener up to listen for incoming messages on the test topic queue.
            channel.Bind(topicQueueName, ExchangeNameDefaults.TOPIC, CONTROL_ROUTING_KEY);
            IMessageConsumer consumer = channel.CreateConsumerBuilder(topicQueueName)
                                        .Create();

            consumer.OnMessage += new MessageReceivedDelegate(OnMessage);

            // Set up this listener with a producer to send the reports on.
            publisher = channel.CreatePublisherBuilder()
                        .WithExchangeName(ExchangeNameDefaults.DIRECT)
                        .WithRoutingKey(RESPONSE_ROUTING_KEY)
                        .Create();

            connection.Start();
            Console.WriteLine("Waiting for messages...");
            while (true)
            {
                if (shutdownReceivedEvt.WaitOne(TIMEOUT, true))
                {
                    Console.WriteLine("message was received");
                }
                else
                {
                    Console.WriteLine("timeout elapsed");
                }
            }
        }
        public void SingleTransportUsernameBlankPasswordURL()
        {
            String url = "amqp://ritchiem:@default/temp?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals(""));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
        }
        public void SinglevmURL()
        {
            String url = "amqp://*****:*****@default/messages?brokerlist='vm://default:2'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/messages"));

            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.AreEqual(2, service.Port);
        }
        private static void SendMessages()
        {
            AMQConnection conn = new AMQConnection(QpidConnectionInfo.FromUrl(BaseMessagingTestFixture.connectionUri));

            conn.Start();
            IChannel          channel  = conn.CreateChannel(false, AcknowledgeMode.AutoAcknowledge);
            IMessagePublisher producer = channel.CreatePublisherBuilder().
                                         WithExchangeName(ExchangeNameDefaults.DIRECT).
                                         WithRoutingKey(TEST_ROUTING_KEY).
                                         Create();

            for (int i = 0; i < MESSAGE_COUNT; i++)
            {
                if ((i % 10) == 0)
                {
                    Console.WriteLine("Sending message " + i);
                }
                producer.Send(channel.CreateTextMessage("Msg" + i));
            }
        }
        public void SingleTransport1OptionURL()
        {
            String url = "amqp://*****:*****@default/temp?brokerlist='tcp://localhost:5672',routingkey='jim'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));


            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));

            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
            Assert.IsTrue(connectionurl.GetOption("routingkey").Equals("jim"));
        }
        /// <summary>
        /// Creates a topic publisher that will send the specifed number of messages and expect the specifed number of report back from test
        /// subscribers.
        /// </summary>
        ///
        /// <param name="connectionUri">The broker URL.</param>
        /// <param name="numMessages">The number of messages to send in each test.</param>
        /// <param name="numSubscribers">The number of subscribes that are expected to reply with a report.</param>
        TopicPublisher(string connectionUri, int numMessages, int numSubscribers)
        {
            log.Debug("TopicPublisher(string connectionUri = " + connectionUri + ", int numMessages = " + numMessages +
                      ", int numSubscribers = " + numSubscribers + "): called");

            // Create a connection to the broker.
            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri);

            connection = new AMQConnection(connectionInfo);

            // Establish a session on the broker.
            channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1);

            // Set up a queue to listen for reports on.
            string responseQueueName = channel.GenerateUniqueName();

            channel.DeclareQueue(responseQueueName, false, true, true);

            // Set this listener up to listen for reports on the response queue.
            channel.Bind(responseQueueName, ExchangeNameDefaults.DIRECT, RESPONSE_ROUTING_KEY);
            //channel.Bind(responseQueueName, "<<default>>", RESPONSE_ROUTING_KEY);
            IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName)
                                        .Create();

            consumer.OnMessage += new MessageReceivedDelegate(OnMessage);

            // Set up this listener with a producer to send the test messages and report requests on.
            publisher = channel.CreatePublisherBuilder()
                        .WithExchangeName(ExchangeNameDefaults.TOPIC)
                        .WithRoutingKey(CONTROL_ROUTING_KEY)
                        .Create();

            // Keep the test parameters.
            this.numMessages    = numMessages;
            this.numSubscribers = numSubscribers;

            connection.Start();
            Console.WriteLine("Sending messages and waiting for reports...");
        }
        public void SingleTransportWithClientURLURL()
        {
            String url = "amqp://*****:*****@clientname/temp?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);


            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));
            Assert.IsTrue(connectionurl.ClientName.Equals("clientname"));


            Assert.IsTrue(connectionurl.BrokerCount == 1);


            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
        }
        public void FailoverVMURL()
        {
            String url = "amqp://*****:*****@default/temp?brokerlist='vm://default:2;vm://default:3',failover='roundrobin'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod.Equals("roundrobin"));
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals("bob"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.AreEqual(2, connectionurl.BrokerCount);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.IsTrue(service.Port == 2);

            service = connectionurl.GetBrokerInfo(1);
            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.IsTrue(service.Port == 3);
        }
Beispiel #34
0
        static void Main(string[] args)
        {
             XmlConfigurator.Configure(new FileInfo("..\\..\\log.xml"));
            // DOMConfigurator.Configure()            

            string host = ConfigurationManager.AppSettings["Host"];
            int port = int.Parse(ConfigurationManager.AppSettings["Port"]);
            string virtualhost = ConfigurationManager.AppSettings["VirtualHost"];
            string username = ConfigurationManager.AppSettings["Username"];
            string password = ConfigurationManager.AppSettings["Password"];
            IConnectionInfo connectionInfo = new QpidConnectionInfo();
            connectionInfo.VirtualHost = virtualhost;
            //connectionInfo.host = host;
            //connectionInfo.port = port;
            connectionInfo.Username = username;
            connectionInfo.Password = password;

            //Client client = new Client();

            Console.WriteLine("Client created");
            //client.Connect(host, port, virtualhost, username, password);
            IConnection clientConnection = new AMQConnection(connectionInfo);
            Console.WriteLine("Connection established");

            IClientSession ssn = client.CreateSession(50000);

            Console.WriteLine("Session created");
            ssn.QueueDeclare("queue1", null, null);
            ssn.ExchangeBind("queue1", "amq.direct", "queue1", null);


            Object wl = new Object();
            ssn.AttachMessageListener(new MyListener(ssn, wl), "myDest");

            ssn.MessageSubscribe("queue1", "myDest", MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED, null,
                                 0, null);
            DateTime start = DateTime.Now;

            // issue credits     
            ssn.MessageSetFlowMode("myDest", MessageFlowMode.WINDOW);
            ssn.MessageFlow("myDest", MessageCreditUnit.BYTE, ClientSession.MESSAGE_FLOW_MAX_BYTES);
            ssn.MessageFlow("myDest", MessageCreditUnit.MESSAGE, 10000);
            ssn.Sync();


            for (int i = 0; i < 10000; i ++)
            {            
            ssn.MessageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
                                new Header(new DeliveryProperties().SetRoutingKey("queue1"),
                                           new MessageProperties().SetMessageId(UUID.RandomUuid())),
                                Encoding.UTF8.GetBytes("test: " + i));
            }

            lock(wl)
            {
                Monitor.Wait(wl);
            }
            DateTime now = DateTime.Now;
            Console.WriteLine("Start time " + start + " now: " + now);

            Console.WriteLine("Done time: " +  (now - start));
            lock (wl)
            {
                Monitor.Wait(wl, 30000);
            }
            client.Close();
        }
        public void EnsureVirtualHostStartsWithSlash()
        {
           IConnectionInfo connection = new QpidConnectionInfo();
           connection.VirtualHost = "test";
           Assert.AreEqual("/test", connection.VirtualHost);

           connection.VirtualHost = "/mytest";
           Assert.AreEqual("/mytest", connection.VirtualHost);

           connection.VirtualHost = "";
           Assert.AreEqual("/", connection.VirtualHost);

           connection.VirtualHost = null;
           Assert.AreEqual("/", connection.VirtualHost);
        }
Beispiel #36
0
        public void Test5MinuteWait()
	{
	    String clientId = "failover" + DateTime.Now.Ticks;

	    QpidConnectionInfo connectionInfo = new QpidConnectionInfo();
	    connectionInfo.Username = "******";
	    connectionInfo.Password = "******";
	    connectionInfo.ClientName = clientId;
	    connectionInfo.VirtualHost = "/test";
	    connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 9672, false));
	    connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 9673, false));
	    
	    Init(connectionInfo);
	    DoFailoverTest(5);
	}