Пример #1
0
        public void TestZeroMaximumNumberOfRedeliveries()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                IRedeliveryPolicy policy = connection.RedeliveryPolicy;
                policy.InitialRedeliveryDelay = 100;
                policy.UseExponentialBackOff  = false;
                //let's set the maximum redeliveries to 0
                policy.MaximumRedeliveries = 0;

                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination     destination = session.CreateTemporaryQueue();
                IMessageProducer producer    = session.CreateProducer(destination);

                IMessageConsumer consumer = session.CreateConsumer(destination);

                // Send the messages
                producer.Send(session.CreateTextMessage("1st"));
                producer.Send(session.CreateTextMessage("2nd"));
                session.Commit();

                ITextMessage m;
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                //the 1st  message should not be redelivered since maximumRedeliveries is set to 0
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("2nd", m.Text);
                session.Commit();
            }
        }
Пример #2
0
 // Constructor internal to prevent clients from creating an instance.
 internal MessageConsumer(Session session, ConsumerInfo info)
 {
     this.session               = session;
     this.info                  = info;
     this.redeliveryPolicy      = this.session.Connection.RedeliveryPolicy;
     this.messageTransformation = this.session.Connection.MessageTransformation;
 }
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
                                 String name, String selector, int prefetch, int maxPendingMessageCount,
                                 bool noLocal, bool browser, bool dispatchAsync)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }

            this.session          = session;
            this.redeliveryPolicy = this.session.Connection.RedeliveryPolicy;

            this.info                            = new ConsumerInfo();
            this.info.ConsumerId                 = id;
            this.info.Destination                = destination;
            this.info.SubscriptionName           = name;
            this.info.Selector                   = selector;
            this.info.PrefetchSize               = prefetch;
            this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
            this.info.NoLocal                    = noLocal;
            this.info.Browser                    = browser;
            this.info.DispatchAsync              = dispatchAsync;
            this.info.Retroactive                = session.Retroactive;
            this.info.Exclusive                  = session.Exclusive;
            this.info.Priority                   = session.Priority;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if (destination.Options != null)
            {
                URISupport.SetProperties(this.info, destination.Options, "consumer.");
            }
        }
Пример #4
0
        public void TestNornalRedeliveryPolicyOnRollbackUntilTimeToLiveCallback()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                IRedeliveryPolicy policy = connection.RedeliveryPolicy;
                policy.MaximumRedeliveries    = -1;
                policy.InitialRedeliveryDelay = 500;
                policy.UseExponentialBackOff  = false;

                connection.Start();
                ISession     session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination destination = session.CreateTemporaryQueue();

                IMessageProducer producer = session.CreateProducer(destination);
                IMessageConsumer consumer = session.CreateConsumer(destination);
                CallbackClass    cc       = new CallbackClass(session);
                consumer.Listener += new MessageListener(cc.consumer_Listener);

                // Send the messages
                ITextMessage textMessage = session.CreateTextMessage("1st");
                textMessage.NMSTimeToLive = TimeSpan.FromMilliseconds(800.0);
                producer.Send(textMessage, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.FromMilliseconds(800.0));
                session.Commit();

                // sends normal message, then immediate retry, then retry after 500 ms, then expire.
                Thread.Sleep(2000);
                Assert.AreEqual(3, cc.numReceived);
            }
        }
Пример #5
0
        public void TestDLQHandling()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                IRedeliveryPolicy policy = connection.RedeliveryPolicy;
                policy.InitialRedeliveryDelay = 100;
                policy.UseExponentialBackOff  = false;
                policy.MaximumRedeliveries    = 2;

                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination     destination = session.CreateTemporaryQueue();
                IMessageProducer producer    = session.CreateProducer(destination);

                session.DeleteDestination(new ActiveMQQueue("ActiveMQ.DLQ"));

                IMessageConsumer consumer    = session.CreateConsumer(destination);
                IMessageConsumer dlqConsumer = session.CreateConsumer(new ActiveMQQueue("ActiveMQ.DLQ"));

                // Purge any messages already in the DLQ.
                while (dlqConsumer.ReceiveNoWait() != null)
                {
                    session.Commit();
                }

                // Send the messages
                producer.Send(session.CreateTextMessage("1st"));
                producer.Send(session.CreateTextMessage("2nd"));
                session.Commit();

                ITextMessage m;
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                // The last Rollback should cause the 1st message to get sent to the DLQ
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("2nd", m.Text);
                session.Commit();

                // We should be able to get the message off the DLQ now.
                m = (ITextMessage)dlqConsumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Commit();
            }
        }
        private bool IsMessageRedeliveryExceeded(IMessageDelivery delivery)
        {
            Message.Message   message = delivery.Message;
            IRedeliveryPolicy policy  = this.Session.Connection.RedeliveryPolicy;

            if (policy != null && policy.MaximumRedeliveries >= 0)
            {
                IMessageCloak msgCloak = message.GetMessageCloak();
                return(msgCloak.RedeliveryCount > policy.MaximumRedeliveries);
            }
            return(false);
        }
        private bool IsRedeliveryExceeded(InboundMessageDispatch envelope)
        {
            Tracer.DebugFormat("Checking envelope with {0} redeliveries", envelope.RedeliveryCount);
            IRedeliveryPolicy redeliveryPolicy = Session.Connection.RedeliveryPolicy;

            if (redeliveryPolicy != null && redeliveryPolicy.MaximumRedeliveries >= 0)
            {
                return(envelope.RedeliveryCount > redeliveryPolicy.MaximumRedeliveries);
            }

            return(false);
        }
Пример #8
0
        public void TestExponentialRedeliveryPolicyDelaysDeliveryOnRollback()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                IRedeliveryPolicy policy = connection.RedeliveryPolicy;
                policy.InitialRedeliveryDelay = 500;
                policy.BackOffMultiplier      = 2;
                policy.UseExponentialBackOff  = true;
                policy.UseCollisionAvoidance  = false;

                connection.Start();
                ISession         session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination     destination = session.CreateTemporaryQueue();
                IMessageProducer producer    = session.CreateProducer(destination);

                IMessageConsumer consumer = session.CreateConsumer(destination);

                // Send the messages
                producer.Send(session.CreateTextMessage("1st"));
                producer.Send(session.CreateTextMessage("2nd"));
                session.Commit();

                ITextMessage m;
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                // No delay on first Rollback..
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(100));
                Assert.IsNotNull(m);
                session.Rollback();

                // Show subsequent re-delivery delay is incrementing.
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(100));
                Assert.IsNull(m);

                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(700));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                // Show re-delivery delay is incrementing exponentially
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(100));
                Assert.IsNull(m);
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(500));
                Assert.IsNull(m);
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(700));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
            }
        }
Пример #9
0
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
                                 String name, String selector, int prefetch, int maxPendingMessageCount,
                                 bool noLocal, bool browser, bool dispatchAsync)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }

            this.session               = session;
            this.redeliveryPolicy      = this.session.Connection.RedeliveryPolicy;
            this.messageTransformation = this.session.Connection.MessageTransformation;

            if (session.Connection.MessagePrioritySupported)
            {
                this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
            }
            else
            {
                this.unconsumedMessages = new FifoMessageDispatchChannel();
            }

            this.info                            = new ConsumerInfo();
            this.info.ConsumerId                 = id;
            this.info.Destination                = destination;
            this.info.SubscriptionName           = name;
            this.info.Selector                   = selector;
            this.info.PrefetchSize               = prefetch;
            this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
            this.info.NoLocal                    = noLocal;
            this.info.Browser                    = browser;
            this.info.DispatchAsync              = dispatchAsync;
            this.info.Retroactive                = session.Retroactive;
            this.info.Exclusive                  = session.Exclusive;
            this.info.Priority                   = session.Priority;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if (destination.Options != null)
            {
                // Get options prefixed with "consumer.*"
                StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
                // Extract out custom extension options "consumer.nms.*"
                StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

                URISupport.SetProperties(this.info, options);
                URISupport.SetProperties(this, customConsumerOptions, "nms.");
            }
        }
Пример #10
0
        public void TestNornalRedeliveryPolicyOnRollbackUntilTimeToLive()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                IRedeliveryPolicy policy = connection.RedeliveryPolicy;
                policy.MaximumRedeliveries    = -1;
                policy.InitialRedeliveryDelay = 500;
                policy.UseExponentialBackOff  = false;

                connection.Start();
                ISession     session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination destination = session.CreateTemporaryQueue();

                IMessageProducer producer = session.CreateProducer(destination);
                IMessageConsumer consumer = session.CreateConsumer(destination);

                // Send the messages
                ITextMessage textMessage = session.CreateTextMessage("1st");
                textMessage.NMSTimeToLive = TimeSpan.FromMilliseconds(800.0);
                producer.Send(textMessage);
                session.Commit();

                ITextMessage m;
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(1000));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                // No delay on first Rollback..
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(100));
                Assert.IsNotNull(m);
                session.Rollback();

                // Show subsequent re-delivery delay is incrementing.
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(100));
                Assert.IsNull(m);
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(700));
                Assert.IsNotNull(m);
                Assert.AreEqual("1st", m.Text);
                session.Rollback();

                // The message gets redelivered after 500 ms every time since
                // we are not using exponential backoff.
                m = (ITextMessage)consumer.Receive(TimeSpan.FromMilliseconds(700));
                Assert.IsNull(m);
            }
        }
Пример #11
0
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, Destination destination, string name, string selector, int prefetch, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }

            this.session               = session;
            this.redeliveryPolicy      = this.session.Connection.RedeliveryPolicy;
            this.messageTransformation = this.session.Connection.MessageTransformation;

            this.info                            = new ConsumerInfo();
            this.info.ConsumerId                 = id;
            this.info.Destination                = Destination.Transform(destination);
            this.info.SubscriptionName           = name;
            this.info.Selector                   = selector;
            this.info.PrefetchSize               = prefetch;
            this.info.MaximumPendingMessageLimit = session.Connection.PrefetchPolicy.MaximumPendingMessageLimit;
            this.info.NoLocal                    = noLocal;
            this.info.DispatchAsync              = session.DispatchAsync;
            this.info.Retroactive                = session.Retroactive;
            this.info.Exclusive                  = session.Exclusive;
            this.info.Priority                   = session.Priority;
            this.info.AckMode                    = session.AcknowledgementMode;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if (destination.Options != null)
            {
                // Get options prefixed with "consumer.*"
                StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
                // Extract out custom extension options "consumer.nms.*"
                StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

                URISupport.SetProperties(this.info, options);
                URISupport.SetProperties(this, customConsumerOptions, "nms.");
            }
        }
Пример #12
0
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
                                 String name, String selector, int prefetch, int maxPendingMessageCount,
                                 bool noLocal, bool browser, bool dispatchAsync)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }
            else if (destination.PhysicalName == null)
            {
                throw new InvalidDestinationException("The destination object was not given a physical name.");
            }
            else if (destination.IsTemporary)
            {
                String physicalName = destination.PhysicalName;

                if (String.IsNullOrEmpty(physicalName))
                {
                    throw new InvalidDestinationException("Physical name of Destination should be valid: " + destination);
                }

                String connectionID = session.Connection.ConnectionId.Value;

                if (physicalName.IndexOf(connectionID) < 0)
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination from another Connection");
                }

                if (!session.Connection.IsTempDestinationActive(destination as ActiveMQTempDestination))
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination that has been deleted");
                }
            }

            this.session               = session;
            this.redeliveryPolicy      = this.session.Connection.RedeliveryPolicy;
            this.messageTransformation = this.session.Connection.MessageTransformation;

            if (session.Connection.MessagePrioritySupported)
            {
                this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
            }
            else
            {
                this.unconsumedMessages = new FifoMessageDispatchChannel();
            }

            this.info                            = new ConsumerInfo();
            this.info.ConsumerId                 = id;
            this.info.Destination                = destination;
            this.info.SubscriptionName           = name;
            this.info.Selector                   = selector;
            this.info.PrefetchSize               = prefetch;
            this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
            this.info.NoLocal                    = noLocal;
            this.info.Browser                    = browser;
            this.info.DispatchAsync              = dispatchAsync;
            this.info.Retroactive                = session.Retroactive;
            this.info.Exclusive                  = session.Exclusive;
            this.info.Priority                   = session.Priority;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if (destination.Options != null)
            {
                // Get options prefixed with "consumer.*"
                StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
                // Extract out custom extension options "consumer.nms.*"
                StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

                URISupport.SetProperties(this.info, options);
                URISupport.SetProperties(this, customConsumerOptions, "nms.");
            }
        }
Пример #13
0
        public void TestRepeatedRedeliveryOnMessageNoCommit()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                connection.Start();
                ISession     dlqSession  = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IDestination destination = dlqSession.GetQueue("TestRepeatedRedeliveryOnMessageNoCommit");
                IDestination dlq         = dlqSession.GetQueue("ActiveMQ.DLQ");
                connection.DeleteDestination(destination);
                connection.DeleteDestination(dlq);
                IMessageProducer producer    = dlqSession.CreateProducer(destination);
                IMessageConsumer dlqConsumer = dlqSession.CreateConsumer(dlq);

                producer.Send(dlqSession.CreateTextMessage("1st"));

                const int    maxRedeliveries = 4;
                Atomic <int> receivedCount   = new Atomic <int>(0);

                for (int i = 0; i <= maxRedeliveries + 1; i++)
                {
                    using (Connection loopConnection = (Connection)CreateConnection())
                    {
                        IRedeliveryPolicy policy = loopConnection.RedeliveryPolicy;
                        policy.InitialRedeliveryDelay = 0;
                        policy.UseExponentialBackOff  = false;
                        policy.MaximumRedeliveries    = maxRedeliveries;

                        loopConnection.Start();
                        ISession                  session  = loopConnection.CreateSession(AcknowledgementMode.Transactional);
                        IMessageConsumer          consumer = session.CreateConsumer(destination);
                        OnMessageNoCommitCallback callback = new OnMessageNoCommitCallback(receivedCount);
                        consumer.Listener += new MessageListener(callback.consumer_Listener);

                        if (i <= maxRedeliveries)
                        {
                            Assert.IsTrue(callback.Await(), "listener should have dispatched a message");
                        }
                        else
                        {
                            // final redlivery gets poisoned before dispatch
                            Assert.IsFalse(callback.Await(), "listener should not have dispatched after max redliveries");
                        }
                    }
                }

                // We should be able to get the message off the DLQ now.
                ITextMessage msg = dlqConsumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
                Assert.IsNotNull(msg, "Got message from DLQ");
                Assert.AreEqual("1st", msg.Text);
                String cause = msg.Properties.GetString(DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
                if (cause != null)
                {
                    Tracer.DebugFormat("Rollback Cause = {0}", cause);
                    Assert.IsTrue(cause.Contains("RedeliveryPolicy"), "cause exception has no policy ref");
                }
                else
                {
                    Tracer.Debug("DLQ'd message has no cause tag.");
                }
            }
        }
Пример #14
0
        public void TestRepeatedRedeliveryReceiveNoCommit()
        {
            using (Connection connection = (Connection)CreateConnection())
            {
                connection.Start();

                ISession     dlqSession  = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IDestination destination = dlqSession.GetQueue("TestRepeatedRedeliveryReceiveNoCommit");
                IDestination dlq         = dlqSession.GetQueue("ActiveMQ.DLQ");
                connection.DeleteDestination(destination);
                connection.DeleteDestination(dlq);
                IMessageProducer producer = dlqSession.CreateProducer(destination);
                producer.Send(dlqSession.CreateTextMessage("1st"));
                IMessageConsumer dlqConsumer = dlqSession.CreateConsumer(dlq);

                const int maxRedeliveries = 4;
                for (int i = 0; i <= maxRedeliveries + 1; i++)
                {
                    using (Connection loopConnection = (Connection)CreateConnection())
                    {
                        // Receive a message with the JMS API
                        IRedeliveryPolicy policy = loopConnection.RedeliveryPolicy;
                        policy.InitialRedeliveryDelay = 0;
                        policy.UseExponentialBackOff  = false;
                        policy.MaximumRedeliveries    = maxRedeliveries;

                        loopConnection.Start();
                        ISession         session  = loopConnection.CreateSession(AcknowledgementMode.Transactional);
                        IMessageConsumer consumer = session.CreateConsumer(destination);

                        ActiveMQTextMessage m = consumer.Receive(TimeSpan.FromMilliseconds(4000)) as ActiveMQTextMessage;
                        if (m != null)
                        {
                            Tracer.DebugFormat("Received Message: {0} delivery count = {1}", m.Text, m.RedeliveryCounter);
                        }

                        if (i <= maxRedeliveries)
                        {
                            Assert.IsNotNull(m);
                            Assert.AreEqual("1st", m.Text);
                            Assert.AreEqual(i, m.RedeliveryCounter);
                        }
                        else
                        {
                            Assert.IsNull(m, "null on exceeding redelivery count");
                        }
                    }
                }

                // We should be able to get the message off the DLQ now.
                ITextMessage msg = dlqConsumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
                Assert.IsNotNull(msg, "Got message from DLQ");
                Assert.AreEqual("1st", msg.Text);
                String cause = msg.Properties.GetString(DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
                if (cause != null)
                {
                    Tracer.DebugFormat("Rollback Cause = {0}", cause);
                    Assert.IsTrue(cause.Contains("RedeliveryPolicy"), "cause exception has no policy ref");
                }
                else
                {
                    Tracer.Debug("DLQ'd message has no cause tag.");
                }
            }
        }
Пример #15
0
		// Constructor internal to prevent clients from creating an instance.
		internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
								 String name, String selector, int prefetch, int maxPendingMessageCount,
								 bool noLocal, bool browser, bool dispatchAsync )
		{
			if(destination == null)
			{
				throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }
            else if(destination.PhysicalName == null)
            {
                throw new InvalidDestinationException("The destination object was not given a physical name.");
            }
            else if (destination.IsTemporary)
            {
                String physicalName = destination.PhysicalName;

                if(String.IsNullOrEmpty(physicalName))
                {
                    throw new InvalidDestinationException("Physical name of Destination should be valid: " + destination);
                }
    
                String connectionID = session.Connection.ConnectionId.Value;

                if(physicalName.IndexOf(connectionID) < 0)
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination from another Connection");
                }
    
                if(!session.Connection.IsTempDestinationActive(destination as ActiveMQTempDestination))
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination that has been deleted");
                }
            }

			this.session = session;
			this.redeliveryPolicy = this.session.Connection.RedeliveryPolicy;
			this.messageTransformation = this.session.Connection.MessageTransformation;

			if(session.Connection.MessagePrioritySupported)
			{
				this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
			}
			else
			{
				this.unconsumedMessages = new FifoMessageDispatchChannel();
			}

			this.info = new ConsumerInfo();
			this.info.ConsumerId = id;
			this.info.Destination = destination;
			this.info.SubscriptionName = name;
			this.info.Selector = selector;
			this.info.PrefetchSize = prefetch;
			this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
			this.info.NoLocal = noLocal;
			this.info.Browser = browser;
			this.info.DispatchAsync = dispatchAsync;
			this.info.Retroactive = session.Retroactive;
			this.info.Exclusive = session.Exclusive;
			this.info.Priority = session.Priority;

			// If the destination contained a URI query, then use it to set public properties
			// on the ConsumerInfo
			if(destination.Options != null)
			{
				// Get options prefixed with "consumer.*"
				StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
				// Extract out custom extension options "consumer.nms.*"
				StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

				URISupport.SetProperties(this.info, options);
				URISupport.SetProperties(this, customConsumerOptions, "nms.");
			}
		}
Пример #16
0
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
								 String name, String selector, int prefetch, int maxPendingMessageCount,
								 bool noLocal, bool browser, bool dispatchAsync )
        {
            if(destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }

            this.session = session;
            this.redeliveryPolicy = this.session.Connection.RedeliveryPolicy;
            this.messageTransformation = this.session.Connection.MessageTransformation;

            if(session.Connection.MessagePrioritySupported)
            {
                this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
            }
            else
            {
                this.unconsumedMessages = new FifoMessageDispatchChannel();
            }

            this.info = new ConsumerInfo();
            this.info.ConsumerId = id;
            this.info.Destination = destination;
            this.info.SubscriptionName = name;
            this.info.Selector = selector;
            this.info.PrefetchSize = prefetch;
            this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
            this.info.NoLocal = noLocal;
            this.info.Browser = browser;
            this.info.DispatchAsync = dispatchAsync;
            this.info.Retroactive = session.Retroactive;
            this.info.Exclusive = session.Exclusive;
            this.info.Priority = session.Priority;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if(destination.Options != null)
            {
                // Get options prefixed with "consumer.*"
                StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
                // Extract out custom extension options "consumer.nms.*"
                StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

                URISupport.SetProperties(this.info, options);
                URISupport.SetProperties(this, customConsumerOptions, "nms.");
            }
        }