Ejemplo n.º 1
0
        public void TestProducers(
            [Values("queue://ZMQTestQueue", "topic://ZMQTestTopic", "temp-queue://ZMQTempQueue", "temp-topic://ZMQTempTopic")]
            string destination)
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost:5556"));

            Assert.IsNotNull(factory, "Error creating connection factory.");
            using (IConnection connection = factory.CreateConnection())
            {
                Assert.IsNotNull(connection, "Problem creating connection class. Usually problem with libzmq and clrzmq ");
                using (ISession session = connection.CreateSession())
                {
                    Assert.IsNotNull(session, "Error creating session.");
                    using (IDestination testDestination = session.GetDestination(destination))
                    {
                        Assert.IsNotNull(testDestination, "Error creating test destination: {0}", destination);
                        using (IMessageProducer producer = session.CreateProducer(testDestination))
                        {
                            Assert.IsNotNull(producer, "Error creating producer on {0}", destination);
                            Assert.IsInstanceOf <MessageProducer>(producer, "Wrong producer type.");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void TestFactory()
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost:5556"));

            Assert.IsNotNull(factory, "Error creating connection factory.");
            Assert.IsInstanceOf <ConnectionFactory>(factory, "Wrong factory type.");
            Assert.AreEqual(factory.BrokerUri.Port, 5556, "Wrong port.");
        }
Ejemplo n.º 3
0
        public ActiveMQConnection(Uri uri, string destinationName, string userName, string password)
        {
            var connectionFactory = NMSConnectionFactory.CreateConnectionFactory(uri);

            _connection  = connectionFactory.CreateConnection(userName, password);
            _session     = _connection.CreateSession();
            _destination = _session.GetDestination(destinationName);
        }
Ejemplo n.º 4
0
        public void TestConnection()
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost:5556"));

            Assert.IsNotNull(factory, "Error creating connection factory.");
            using (IConnection connection = factory.CreateConnection())
            {
                Assert.IsNotNull(connection, "Problem creating connection class. Usually problem with libzmq and clrzmq ");
                Assert.IsInstanceOf <Connection>(connection, "Wrong connection type.");
            }
        }
Ejemplo n.º 5
0
        public void TestDestinations(
            [Values("queue://ZMQTestQueue", "topic://ZMQTestTopic", "temp-queue://ZMQTempQueue", "temp-topic://ZMQTempTopic")]
            string destination,
            [Values(typeof(Queue), typeof(Topic), typeof(TemporaryQueue), typeof(TemporaryTopic))]
            Type destinationType)
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost:5556"));

            Assert.IsNotNull(factory, "Error creating connection factory.");
            using (IConnection connection = factory.CreateConnection())
            {
                Assert.IsNotNull(connection, "Problem creating connection class. Usually problem with libzmq and clrzmq ");
                using (ISession session = connection.CreateSession())
                {
                    Assert.IsNotNull(session, "Error creating session.");
                    using (IDestination testDestination = session.GetDestination(destination))
                    {
                        Assert.IsNotNull(testDestination, "Error creating test destination: {0}", destination);
                        Assert.IsInstanceOf(destinationType, testDestination, "Wrong destintation type.");
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void TestFactoryUriMissingPort()
 {
     IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost"));
 }
 public PooledConnectionFactory(Uri brokerUri)
 {
     this.factory = NMSConnectionFactory.CreateConnectionFactory(brokerUri, null);
 }
 public PooledConnectionFactory()
 {
     this.factory = NMSConnectionFactory.CreateConnectionFactory(null, null);
 }
Ejemplo n.º 9
0
        public void TestSendReceive(
            // inproc, ipc, tcp, pgm, or epgm
            [Values("zmq:tcp://localhost:5556", "zmq:inproc://localhost:5557")]
            string connectionName,
            [Values("queue://ZMQTestQueue", "topic://ZMQTestTopic", "temp-queue://ZMQTempQueue", "temp-topic://ZMQTempTopic")]
            string destinationName)
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri(connectionName));

            Assert.IsNotNull(factory, "Error creating connection factory.");

            this.receivedMsgCount = 0;
            using (IConnection connection = factory.CreateConnection())
            {
                Assert.IsNotNull(connection, "Problem creating connection class. Usually problem with libzmq and clrzmq ");
                using (ISession session = connection.CreateSession())
                {
                    Assert.IsNotNull(session, "Error creating Session.");
                    using (IDestination testDestination = session.GetDestination(destinationName))
                    {
                        Assert.IsNotNull(testDestination, "Error creating test destination: {0}", destinationName);
                        using (IMessageConsumer consumer = session.CreateConsumer(testDestination))
                        {
                            Assert.IsNotNull(consumer, "Error creating consumer on {0}", destinationName);
                            int sendMsgCount = 0;
                            try
                            {
                                consumer.Listener += OnMessage;
                                using (IMessageProducer producer = session.CreateProducer(testDestination))
                                {
                                    Assert.IsNotNull(consumer, "Error creating producer on {0}", destinationName);
                                    ITextMessage testMsg = producer.CreateTextMessage("Zero Message.");
                                    Assert.IsNotNull(testMsg, "Error creating test message.");

                                    // Wait for the message
                                    DateTime startWaitTime = DateTime.Now;
                                    TimeSpan maxWaitTime   = TimeSpan.FromSeconds(5);

                                    // Continually send the message to compensate for the
                                    // slow joiner problem inherent to spinning up the
                                    // internal dispatching threads in ZeroMQ.
                                    while (this.receivedMsgCount < 1)
                                    {
                                        ++sendMsgCount;
                                        producer.Send(testMsg);
                                        if ((DateTime.Now - startWaitTime) > maxWaitTime)
                                        {
                                            Assert.Fail("Timeout waiting for message receive.");
                                        }

                                        Thread.Sleep(1);
                                    }
                                }
                            }
                            finally
                            {
                                consumer.Listener -= OnMessage;
                                Console.WriteLine("Sent {0} msgs.\nReceived {1} msgs", sendMsgCount, this.receivedMsgCount);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void TestMultipleProducersConsumer(
            [Values("queue://ZMQTestQueue", "topic://ZMQTestTopic", "temp-queue://ZMQTempQueue", "temp-topic://ZMQTempTopic")]
            string destination,
            [Values(1, 3)]
            int numProducers,
            [Values(1, 3)]
            int numConsumers)
        {
            IConnectionFactory factory = NMSConnectionFactory.CreateConnectionFactory(new Uri("zmq:tcp://localhost:5556"));

            Assert.IsNotNull(factory, "Error creating connection factory.");

            using (IConnection connection = factory.CreateConnection())
            {
                Assert.IsNotNull(connection, "Problem creating connection class. Usually problem with libzmq and clrzmq ");
                using (ISession session = connection.CreateSession())
                {
                    Assert.IsNotNull(session, "Error creating Session.");
                    using (IDestination testDestination = session.GetDestination(destination))
                    {
                        Assert.IsNotNull(testDestination, "Error creating test destination: {0}", destination);

                        // Track the number of messages we should receive
                        this.totalMsgCountToReceive = numProducers * numConsumers;

                        ConsumerTracker[]  consumerTrackers = null;
                        IMessageProducer[] producers        = null;

                        try
                        {
                            // Create the consumers
                            consumerTrackers = new ConsumerTracker[numConsumers];
                            for (int index = 0; index < numConsumers; index++)
                            {
                                ConsumerTracker tracker = new ConsumerTracker(session, testDestination);
                                tracker.Listener += (message) =>
                                {
                                    Assert.IsInstanceOf <TextMessage>(message, "Wrong message type received.");
                                    ITextMessage textMsg = (ITextMessage)message;
                                    Assert.AreEqual(textMsg.Text, "Zero Message.");
                                    tracker.msgCount++;
                                };
                                consumerTrackers[index] = tracker;
                            }

                            // Create the producers
                            producers = new IMessageProducer[numProducers];
                            for (int index = 0; index < numProducers; index++)
                            {
                                producers[index] = session.CreateProducer(testDestination);
                                Assert.IsNotNull(producers[index], "Error creating producer #{0} on {1}", index, destination);
                            }

                            // Send the messages
                            for (int index = 0; index < numProducers; index++)
                            {
                                ITextMessage testMsg = session.CreateTextMessage("Zero Message.");
                                Assert.IsNotNull(testMsg, "Error creating test message for producer #{0}.", index);
                                producers[index].Send(testMsg);
                            }

                            // Wait for the message
                            DateTime startWaitTime = DateTime.Now;
                            TimeSpan maxWaitTime   = TimeSpan.FromSeconds(5);

                            while (GetNumMsgsReceived(consumerTrackers) < this.totalMsgCountToReceive)
                            {
                                if ((DateTime.Now - startWaitTime) > maxWaitTime)
                                {
                                    Assert.Fail("Timeout waiting for message receive.");
                                }

                                Thread.Sleep(5);
                            }

                            // Sleep for an extra 2 seconds to see if any extra messages get delivered
                            Thread.Sleep(2 * 1000);
                            Assert.AreEqual(this.totalMsgCountToReceive, GetNumMsgsReceived(consumerTrackers), "Received too many messages.");
                        }
                        finally
                        {
                            // Clean up the producers
                            if (null != producers)
                            {
                                foreach (IMessageProducer producer in producers)
                                {
                                    producer.Dispose();
                                }
                            }

                            // Clean up the consumers
                            if (null != consumerTrackers)
                            {
                                foreach (ConsumerTracker tracker in consumerTrackers)
                                {
                                    tracker.Dispose();
                                }
                            }
                        }
                    }
                }
            }
        }