An object capable of receiving messages from some destination
Inheritance: IMessageConsumer, IDispatcher
Ejemplo n.º 1
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ConsumerInfo command    = CreateConsumerInfo(destination, selector);
            ConsumerId   consumerId = command.ConsumerId;

            command.SubscriptionName = name;
            command.NoLocal          = noLocal;
            MessageConsumer consumer = null;

            try
            {
                consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
                // lets register the consumer first in case we start dispatching messages immediately
                consumers[consumerId] = consumer;
                this.DoSend(command);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 2
0
        private MessageConsumer CreateConsumer()
        {
            this.browseDone.Value = false;
            BrowsingMessageConsumer consumer = null;

            try
            {
                consumer = new BrowsingMessageConsumer(
                    this, session, this.consumerId, this.destination, null, this.selector,
                    this.session.Connection.PrefetchPolicy.QueueBrowserPrefetch,
                    this.session.Connection.PrefetchPolicy.MaximumPendingMessageLimit,
                    false, true, this.dispatchAsync);

                this.session.AddConsumer(consumer);
                this.session.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.session.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.session.RemoveConsumer(consumer.ConsumerId);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 3
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            ConsumerInfo command = CreateConsumerInfo(destination, selector);

            command.NoLocal             = noLocal;
            command.AcknowledgementMode = this.AcknowledgementMode;

            ConsumerId      consumerId = command.ConsumerId;
            MessageConsumer consumer   = null;

            try
            {
                consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
                // lets register the consumer first in case we start dispatching messages immediately
                consumers[consumerId] = consumer;
                this.DoSend(command);
                return(consumer);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }
        }
        public async System.Threading.Tasks.Task DispatchAsync(MessageDispatch dispatch)
        {
            try
            {
                MessageConsumer consumer = null;

                lock (this.consumers.SyncRoot)
                {
                    if (this.consumers.Contains(dispatch.ConsumerId))
                    {
                        consumer = this.consumers[dispatch.ConsumerId] as MessageConsumer;
                    }
                }

                // If the consumer is not available, just ignore the message.
                // Otherwise, dispatch the message to the consumer.
                if (consumer != null)
                {
                    await consumer.Dispatch_Async(dispatch).Await();
                }
            }
            catch (Exception ex)
            {
                Tracer.DebugFormat("Caught Exception While Dispatching: {0}", ex.Message);
            }
        }
Ejemplo n.º 5
0
        public void Dispatch(MessageDispatch dispatch)
        {
            try
            {
                MessageConsumer consumer = null;

                lock (this.consumers.SyncRoot)
                {
                    if (this.consumers.Contains(dispatch.ConsumerId))
                    {
                        consumer = this.consumers[dispatch.ConsumerId] as MessageConsumer;
                    }
                }

                // If the consumer is not available, just ignore the message.
                // Otherwise, dispatch the message to the consumer.
                if (consumer != null)
                {
                    consumer.Dispatch(dispatch);
                }
            }
            catch (Exception ex)
            {
                Tracer.DebugFormat("Caught Exception While Dispatching: {0}", ex.Message);
            }
        }
Ejemplo n.º 6
0
        public void AddConsumer(MessageConsumer consumer)
        {
            ConsumerId id = consumer.ConsumerId;

            // Registered with Connection before we register at the broker.
            consumers[id] = consumer;
            connection.addDispatcher(id, this);
        }
Ejemplo n.º 7
0
		internal QueueBrowser(Session session, ConsumerId consumerId, ActiveMQDestination destination, string selector, bool dispatchAsync)
		{
			this.session = session;
			this.consumerId = consumerId;
			this.destination = destination;
			this.selector = selector;
			this.dispatchAsync = dispatchAsync;
			this.consumer = CreateConsumer();
		}
Ejemplo n.º 8
0
        public void Reset()
        {
            if (consumer != null)
            {
                DestroyConsumer();
            }

            consumer = CreateConsumerAsync().GetAsyncResult();
        }
Ejemplo n.º 9
0
        public void Reset()
        {
            if (consumer != null)
            {
                DestroyConsumer();
            }

            consumer = CreateConsumer();
        }
Ejemplo n.º 10
0
 public void RemoveConsumer(MessageConsumer consumer)
 {
     connection.RemoveDispatcher(consumer.ConsumerId);
     if (!this.closing)
     {
         consumers.Remove(consumer.ConsumerId);
     }
     connection.RemoveDispatcher(consumer);
 }
Ejemplo n.º 11
0
 internal QueueBrowser(Session session, ConsumerId consumerId, ActiveMQDestination destination, string selector, bool dispatchAsync)
 {
     this.session       = session;
     this.consumerId    = consumerId;
     this.destination   = destination;
     this.selector      = selector;
     this.dispatchAsync = dispatchAsync;
     this.consumer      = CreateConsumer();
 }
Ejemplo n.º 12
0
        private static void ClearMessages(object value)
        {
            MessageConsumer consumer = value as MessageConsumer;

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("Performing Async Clear of In Progress Messages on Consumer: " + consumer.ConsumerId);
            }

            consumer.ClearMessagesInProgress();
        }
Ejemplo n.º 13
0
        public bool DispatchMessage(ConsumerId consumerId, Message message)
        {
            bool            dispatched = false;
            MessageConsumer consumer   = (MessageConsumer)consumers[consumerId];

            if (consumer != null)
            {
                consumer.Dispatch((ActiveMQMessage)message);
                dispatched = true;
            }

            return(dispatched);
        }
Ejemplo n.º 14
0
        public IEnumerator GetEnumerator()
        {
            CheckClosed();

            lock (myLock)
            {
                if (this.consumer == null)
                {
                    this.consumer = CreateConsumer();
                }
            }

            return(this);
        }
Ejemplo n.º 15
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest = ActiveMQDestination.Transform(destination);
            int prefetchSize         = this.Connection.PrefetchPolicy.DurableTopicPrefetch;

            if (dest.IsTopic)
            {
                prefetchSize = this.connection.PrefetchPolicy.TopicPrefetch;
            }
            else if (dest.IsQueue)
            {
                prefetchSize = this.connection.PrefetchPolicy.QueuePrefetch;
            }

            MessageConsumer consumer = null;

            try
            {
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), dest, null, selector, prefetchSize,
                                                   this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                                   noLocal);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 16
0
        public void AddConsumer(MessageConsumer consumer)
        {
            if (!this.closing)
            {
                ConsumerId id = consumer.ConsumerId;

                // Registered with Connection before we register at the broker.
                using (consumersLock.Lock())
                {
                    consumers[id] = consumer;
                }
                connection.AddDispatcher(id, this);
            }
        }
Ejemplo n.º 17
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            if (IsIndividualAcknowledge)
            {
                throw new NMSException("Cannot create a durable consumer for a session that is using " +
                                       "Individual Acknowledgement mode.");
            }

            ActiveMQDestination dest     = ActiveMQDestination.Transform(destination);
            MessageConsumer     consumer = null;

            try
            {
                consumer = DoCreateMessageConsumer(GetNextConsumerId(), dest, name, selector,
                                                   this.connection.PrefetchPolicy.DurableTopicPrefetch,
                                                   this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                                   noLocal);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 18
0
        private void DestroyConsumer()
        {
            if (consumer == null)
            {
                return;
            }

            try
            {
                consumer.Close();
                consumer = null;
            }
            catch (NMSException e)
            {
                Tracer.Debug(e.StackTrace.ToString());
            }
        }
Ejemplo n.º 19
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ConsumerInfo command    = CreateConsumerInfo(destination, selector);
            ConsumerId   consumerId = command.ConsumerId;

            command.SubscriptionName = name;
            command.NoLocal          = noLocal;
            command.PrefetchSize     = this.connection.PrefetchPolicy.DurableTopicPrefetch;
            MessageConsumer consumer = null;

            // Registered with Connection before we register at the broker.
            connection.addDispatcher(consumerId, this);

            try
            {
                consumer = new MessageConsumer(this, command);
                // lets register the consumer first in case we start dispatching messages immediately
                consumers[consumerId] = consumer;

                if (this.Started)
                {
                    consumer.Start();
                }

                this.connection.SyncRequest(command);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 20
0
        private MessageConsumer CreateConsumer()
        {
            this.browseDone.Value = false;
            BrowsingMessageConsumer consumer = null;

            if (this.session.Connection.PrefetchPolicy.QueueBrowserPrefetch == 0)
            {
                Tracer.Warn("Attempted to create a Queue Browser with Zero sized prefetch buffer.");
                throw new NMSException("Cannot create a Queue Browser with Zero sized prefetch buffer");
            }

            try
            {
                consumer = new BrowsingMessageConsumer(
                    this, session, this.consumerId, this.destination, null, this.selector,
                    this.session.Connection.PrefetchPolicy.QueueBrowserPrefetch,
                    this.session.Connection.PrefetchPolicy.MaximumPendingMessageLimit,
                    false, true, this.dispatchAsync);

                this.session.AddConsumer(consumer);
                this.session.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.session.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.session.RemoveConsumer(consumer);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 21
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest     = ActiveMQDestination.Transform(destination);
            MessageConsumer     consumer = null;

            try
            {
                consumer = new MessageConsumer(this, GetNextConsumerId(), dest, name, selector,
                                               this.connection.PrefetchPolicy.DurableTopicPrefetch,
                                               this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                               noLocal, false, this.connection.DispatchAsync);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if (this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    this.RemoveConsumer(consumer.ConsumerId);
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Ejemplo n.º 22
0
        private void DestroyConsumer()
        {
            if (consumer == null)
            {
                return;
            }

            try
            {
                if (session.IsTransacted && session.TransactionContext.InLocalTransaction)
                {
                    session.Commit();
                }

                consumer.Close();
                consumer = null;
            }
            catch (NMSException e)
            {
                Tracer.Debug(e.StackTrace.ToString());
            }
        }
Ejemplo n.º 23
0
			public MessageConsumerSynchronization(MessageConsumer consumer)
			{
				this.consumer = consumer;
			}
Ejemplo n.º 24
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if(destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ActiveMQDestination dest = ActiveMQDestination.Transform(destination);
            MessageConsumer consumer = null;

            try
            {
                consumer = new MessageConsumer(this, GetNextConsumerId(), dest, name, selector,
                                               this.connection.PrefetchPolicy.DurableTopicPrefetch,
                                               this.connection.PrefetchPolicy.MaximumPendingMessageLimit,
                                               noLocal, false, this.connection.DispatchAsync);

                consumer.ConsumerTransformer = this.ConsumerTransformer;

                this.AddConsumer(consumer);
                this.Connection.SyncRequest(consumer.ConsumerInfo);

                if(this.Connection.IsStarted)
                {
                    consumer.Start();
                }
            }
            catch(Exception)
            {
                if(consumer != null)
                {
                    this.RemoveConsumer(consumer.ConsumerId);
                    consumer.Close();
                }

                throw;
            }

            return consumer;
        }
Ejemplo n.º 25
0
        public void AddConsumer(MessageConsumer consumer)
        {
            if(!this.closing)
            {
                ConsumerId id = consumer.ConsumerId;

                // Registered with Connection before we register at the broker.
                consumers[id] = consumer;
                connection.addDispatcher(id, this);
            }
        }
Ejemplo n.º 26
0
		private void DestroyConsumer()
		{
			if(consumer == null)
			{
				return;
			}

			try
			{
            	if(session.IsTransacted && session.TransactionContext.InLocalTransaction)
				{
                	session.Commit();
            	}
				
				consumer.Close();
				consumer = null;
			}
			catch(NMSException e)
			{
				Tracer.Debug(e.StackTrace.ToString());
			}
		}
Ejemplo n.º 27
0
		public IEnumerator GetEnumerator()
		{
			CheckClosed();

			lock(myLock)
			{
				if(this.consumer == null)
				{
					this.consumer = CreateConsumer();
				}
			}

			return this;
		}
Ejemplo n.º 28
0
 public ConsumerCloseSynchronization(MessageConsumer consumer)
 {
     this.consumer = consumer;
 }
Ejemplo n.º 29
0
 public MessageConsumerSynchronization(MessageConsumer consumer)
 {
     this.consumer = consumer;
 }
Ejemplo n.º 30
0
		public void Reset()
		{
			if(consumer != null)
			{
				DestroyConsumer();
			}

			consumer = CreateConsumer();
		}
Ejemplo n.º 31
0
 public NmsConsumer(ISession session, MessageConsumer consumer)
 {
     this.session  = session;
     this.consumer = consumer;
 }
Ejemplo n.º 32
0
		private MessageConsumer CreateConsumer()
		{
			this.browseDone.Value = false;
			BrowsingMessageConsumer consumer = null;

			try
			{
				consumer = new BrowsingMessageConsumer(
					this, session, this.consumerId, this.destination, null, this.selector,
					this.session.Connection.PrefetchPolicy.QueueBrowserPrefetch,
					this.session.Connection.PrefetchPolicy.MaximumPendingMessageLimit,
					false, true, this.dispatchAsync);

				this.session.AddConsumer(consumer);
				this.session.Connection.SyncRequest(consumer.ConsumerInfo);

				if(this.session.Connection.IsStarted)
				{
					consumer.Start();
				}
			}
			catch(Exception)
			{
				if(consumer != null)
				{
					this.session.RemoveConsumer(consumer.ConsumerId);
					consumer.Close();
				}

				throw;
			}

			return consumer;
		}
Ejemplo n.º 33
0
 public MessageConsumerSynchronization(MessageConsumer consumer, Message message)
 {
     this.message  = message;
     this.consumer = consumer;
 }
Ejemplo n.º 34
0
			public ConsumerCloseSynchronization(MessageConsumer consumer)
			{
				this.consumer = consumer;
			}