Summary description for ActiveMQQueue.
Inheritance: ActiveMQDestination, IQueue
Exemple #1
0
        /**
         * @param destination
         */
        public static ActiveMQDestination Transform(IDestination destination)
        {
            ActiveMQDestination result = null;

            if (destination != null)
            {
                if (destination is ActiveMQDestination)
                {
                    result = (ActiveMQDestination)destination;
                }
                else
                {
                    if (destination is ITemporaryQueue)
                    {
                        result = new ActiveMQTempQueue(((IQueue)destination).QueueName);
                    }
                    else if (destination is ITemporaryTopic)
                    {
                        result = new ActiveMQTempTopic(((ITopic)destination).TopicName);
                    }
                    else if (destination is IQueue)
                    {
                        result = new ActiveMQQueue(((IQueue)destination).QueueName);
                    }
                    else if (destination is ITopic)
                    {
                        result = new ActiveMQTopic(((ITopic)destination).TopicName);
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        /**
         * Create a Destination
         * @param type
         * @param pyhsicalName
         * @return
         */
        public static ActiveMQDestination CreateDestination(int type, String pyhsicalName)
        {
            ActiveMQDestination result = null;

            if (pyhsicalName == null)
            {
                return(null);
            }
            else if (type == ACTIVEMQ_TOPIC)
            {
                result = new ActiveMQTopic(pyhsicalName);
            }
            else if (type == ACTIVEMQ_TEMPORARY_TOPIC)
            {
                result = new ActiveMQTempTopic(pyhsicalName);
            }
            else if (type == ACTIVEMQ_QUEUE)
            {
                result = new ActiveMQQueue(pyhsicalName);
            }
            else
            {
                result = new ActiveMQTempQueue(pyhsicalName);
            }
            return(result);
        }
        public void CachedMessageConsumer()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection connection = new TestConnection();

            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();

            mocks.ReplayAll();

            CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
            cachingConnectionFactory.TargetConnectionFactory = connectionFactory;
            IConnection con1 = cachingConnectionFactory.CreateConnection();

            ISession sessionA = con1.CreateSession(AcknowledgementMode.Transactional);
            IDestination destination = new ActiveMQQueue("test.dest");
            IMessageConsumer consumerA = sessionA.CreateConsumer(destination);
            TestMessageConsumer tmpA = GetTestMessageConsumer(consumerA);

            sessionA.Close();

            ISession sessionB = con1.CreateSession(AcknowledgementMode.Transactional);
            IMessageConsumer consumerB = sessionB.CreateConsumer(destination);
            TestMessageConsumer tmpB = GetTestMessageConsumer(consumerB);

            Assert.AreSame(tmpA, tmpB);
            mocks.VerifyAll();
        }
Exemple #4
0
        /// <summary>
        /// Create a Destination
        /// </summary>
        /// <param name="type"></param>
        /// <param name="pyhsicalName"></param>
        /// <returns></returns>
        public static ActiveMQDestination CreateDestination(int type, String pyhsicalName)
        {
            ActiveMQDestination result = null;

            if (pyhsicalName == null)
            {
                return(null);
            }
            else
            {
                switch (type)
                {
                case ACTIVEMQ_TOPIC:
                    result = new ActiveMQTopic(pyhsicalName);
                    break;

                case ACTIVEMQ_TEMPORARY_TOPIC:
                    result = new ActiveMQTempTopic(pyhsicalName);
                    break;

                case ACTIVEMQ_QUEUE:
                    result = new ActiveMQQueue(pyhsicalName);
                    break;

                default:
                    result = new ActiveMQTempQueue(pyhsicalName);
                    break;
                }
            }
            return(result);
        }
        public void purgeQueue(IConnection conn, ActiveMQQueue queue)
        {
            ISession session = conn.CreateSession();
            IMessageConsumer consumer = session.CreateConsumer(queue);
            while(consumer.Receive(TimeSpan.FromMilliseconds(500)) != null)
            {
            }

            consumer.Close();
            session.Close();
        }
Exemple #6
0
        public ActiveProducer(IConnection amqConnection, ISession amqSession, String amqQueueName, EasyNetQ.IBus rabbitBus)
        {
            _rabbitBus = rabbitBus;

            ActiveMQQueue topic = new ActiveMQQueue(amqQueueName);
            _amqProducer = amqSession.CreateProducer(topic);
            countOfMessages = 0;
            _timProducer = new Timer(2000);
            _timProducer.Elapsed += _timProducer_Elapsed;
            _timProducer.Enabled = true;
            log.Info("Producer Connected to Queue '" + amqQueueName + "'");
        }
Exemple #7
0
        public override Object Clone()
        {
            // Since we are a derived class use the base's Clone()
            // to perform the shallow copy. Since it is shallow it
            // will include our derived class. Since we are derived,
            // this method is an override.
            ActiveMQQueue o = (ActiveMQQueue)base.Clone();

            // Now do the deep work required
            // If any new variables are added then this routine will
            // likely need updating

            return(o);
        }
        public void TestExclusiveConsumerSelectedCreatedAfter()
        {
            IConnection conn = createConnection(true);

            ISession exclusiveSession = null;
            ISession fallbackSession = null;
            ISession senderSession = null;

            purgeQueue(conn, new ActiveMQQueue("TEST.QUEUE5"));

            try
            {
                exclusiveSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                fallbackSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                senderSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);

                ActiveMQQueue fallbackQueue = new ActiveMQQueue("TEST.QUEUE5");
                IMessageConsumer fallbackConsumer = fallbackSession.CreateConsumer(fallbackQueue);

                ActiveMQQueue exclusiveQueue = new ActiveMQQueue("TEST.QUEUE5?consumer.exclusive=true");
                IMessageConsumer exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);

                ActiveMQQueue senderQueue = new ActiveMQQueue("TEST.QUEUE5");

                IMessageProducer producer = senderSession.CreateProducer(senderQueue);

                IMessage msg = senderSession.CreateTextMessage("test");
                producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
                producer.Send(msg);
                Thread.Sleep(500);

                // Verify exclusive consumer receives the message.
                Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
            }
            finally
            {
                fallbackSession.Close();
                senderSession.Close();
                conn.Close();
            }
        }
        private static IMapMessage GetBrokerStatistics()
        {
            lock (LockObj)
            {
                ConnectionFactory cf = new ConnectionFactory(SimulationParams.FromConfig().Broker1Address, "Stats")
                    {
                        RequestTimeout = 2000,
                        WatchTopicAdvisories = false,
                        AsyncSend = true,
                    };

                using (var connection = (Connection)cf.CreateConnection())
                {
                    connection.Start();
                    using (var session = connection.CreateSession())
                    using (var producer = session.CreateProducer())
                    {
                        IQueue replyTo = session.CreateTemporaryQueue();
                        using (var consumer = session.CreateConsumer(replyTo))
                        {
                            IQueue brokerStatsQueue = new ActiveMQQueue("ActiveMQ.Statistics.Broker");

                            IMessage msg = session.CreateMessage();
                            msg.NMSReplyTo = replyTo;

                            producer.Send(brokerStatsQueue, msg);

                            IMapMessage brokerStatistics = consumer.Receive(TimeSpan.FromSeconds(1)) as IMapMessage ?? new ActiveMQMapMessage();

                            consumer.Dispose();

                            connection.DeleteTemporaryDestination(replyTo); // due to https://issues.apache.org/jira/browse/AMQNET-378

                            return brokerStatistics;
                        }
                    }
                }
            }
        }
Exemple #10
0
        public ActiveConsumer(IConnection amqConnection, ISession amqSession, String amqQueueName, EasyNetQ.IBus rabbitBus)
        {
            try
            {
                _rabbitBus = rabbitBus;
                ActiveMQQueue topic = new ActiveMQQueue(amqQueueName);

                _amqConsumer = amqSession.CreateConsumer(topic);
                _amqConsumer.Listener +=_amqConsumer_Listener;

               _rabbitBus.Subscribe<CorpMessage>(amqQueueName, _rabbitMQConsumer_Listener);

               log.Info("Consumer Connected to Queue '" + amqQueueName + "'");
            }
            catch(Exception e)
            {
                log.Info(e.ToString());
                log.Debug(e.ToString());
            }
            finally
            {

            }
        }
        public void TestFallbackToExclusiveConsumer()
        {
            IConnection conn = createConnection(true);

            ISession exclusiveSession = null;
            ISession fallbackSession = null;
            ISession senderSession = null;

            purgeQueue(conn, new ActiveMQQueue("TEST.QUEUE4"));

            try
            {
                exclusiveSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                fallbackSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
                senderSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);

                // This creates the exclusive consumer first which avoids AMQ-1024
                // bug.
                ActiveMQQueue exclusiveQueue = new ActiveMQQueue("TEST.QUEUE4?consumer.exclusive=true");
                IMessageConsumer exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);

                ActiveMQQueue fallbackQueue = new ActiveMQQueue("TEST.QUEUE4");
                IMessageConsumer fallbackConsumer = fallbackSession.CreateConsumer(fallbackQueue);

                ActiveMQQueue senderQueue = new ActiveMQQueue("TEST.QUEUE4");

                IMessageProducer producer = senderSession.CreateProducer(senderQueue);
                producer.DeliveryMode = MsgDeliveryMode.NonPersistent;

                IMessage msg = senderSession.CreateTextMessage("test");
                producer.Send(msg);
                Thread.Sleep(500);

                // Verify exclusive consumer receives the message.
                Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));

                // Close the exclusive consumer to verify the non-exclusive consumer
                // takes over
                exclusiveConsumer.Close();

                producer.Send(msg);

                // Verify other non-exclusive consumer receices the message.
                Assert.IsNotNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));

                // Create exclusive consumer to determine if it will start receiving
                // the messages.
                exclusiveConsumer = exclusiveSession.CreateConsumer(exclusiveQueue);

                producer.Send(msg);
                Assert.IsNotNull(exclusiveConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(fallbackConsumer.Receive(TimeSpan.FromMilliseconds(1000)));
            }
            finally
            {
                fallbackSession.Close();
                senderSession.Close();
                conn.Close();
            }
        }
		/// <summary>
		/// Create a Destination
		/// </summary>
		/// <param name="type"></param>
		/// <param name="pyhsicalName"></param>
		/// <returns></returns>
		public static ActiveMQDestination CreateDestination(int type, String pyhsicalName)
		{
			ActiveMQDestination result = null;
			if(pyhsicalName == null)
			{
				return null;
			}
			else switch(type)
			{
			    case ACTIVEMQ_TOPIC:
			        result = new ActiveMQTopic(pyhsicalName);
			        break;
			    case ACTIVEMQ_TEMPORARY_TOPIC:
			        result = new ActiveMQTempTopic(pyhsicalName);
			        break;
			    case ACTIVEMQ_QUEUE:
			        result = new ActiveMQQueue(pyhsicalName);
			        break;
			    default:
			        result = new ActiveMQTempQueue(pyhsicalName);
			        break;
			}
			return result;
		}
		/// <summary>
		/// </summary>
		/// <param name="destination"></param>
		/// <returns></returns>
		public static ActiveMQDestination Transform(IDestination destination)
		{
			ActiveMQDestination result = null;
			if(destination != null)
			{
				if(destination is ActiveMQDestination)
				{
					result = (ActiveMQDestination) destination;
				}
				else
				{
					if(destination is ITemporaryQueue)
					{
						result = new ActiveMQTempQueue(((IQueue) destination).QueueName);
					}
					else if(destination is ITemporaryTopic)
					{
						result = new ActiveMQTempTopic(((ITopic) destination).TopicName);
					}
					else if(destination is IQueue)
					{
						result = new ActiveMQQueue(((IQueue) destination).QueueName);
					}
					else if(destination is ITopic)
					{
						result = new ActiveMQTopic(((ITopic) destination).TopicName);
					}
				}
			}
			return result;
		}