An object capable of receiving messages from some destination
상속: IMessageConsumer, IDispatcher
예제 #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);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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();
		}
예제 #8
0
        public void Reset()
        {
            if (consumer != null)
            {
                DestroyConsumer();
            }

            consumer = CreateConsumerAsync().GetAsyncResult();
        }
예제 #9
0
        public void Reset()
        {
            if (consumer != null)
            {
                DestroyConsumer();
            }

            consumer = CreateConsumer();
        }
예제 #10
0
 public void RemoveConsumer(MessageConsumer consumer)
 {
     connection.RemoveDispatcher(consumer.ConsumerId);
     if (!this.closing)
     {
         consumers.Remove(consumer.ConsumerId);
     }
     connection.RemoveDispatcher(consumer);
 }
예제 #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();
 }
예제 #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();
        }
예제 #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);
        }
예제 #14
0
        public IEnumerator GetEnumerator()
        {
            CheckClosed();

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

            return(this);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #18
0
        private void DestroyConsumer()
        {
            if (consumer == null)
            {
                return;
            }

            try
            {
                consumer.Close();
                consumer = null;
            }
            catch (NMSException e)
            {
                Tracer.Debug(e.StackTrace.ToString());
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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());
            }
        }
예제 #23
0
			public MessageConsumerSynchronization(MessageConsumer consumer)
			{
				this.consumer = consumer;
			}
예제 #24
0
파일: Session.cs 프로젝트: Redi0/meijing-ui
        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;
        }
예제 #25
0
파일: Session.cs 프로젝트: Redi0/meijing-ui
        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);
            }
        }
예제 #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());
			}
		}
예제 #27
0
		public IEnumerator GetEnumerator()
		{
			CheckClosed();

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

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

			consumer = CreateConsumer();
		}
예제 #31
0
 public NmsConsumer(ISession session, MessageConsumer consumer)
 {
     this.session  = session;
     this.consumer = consumer;
 }
예제 #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;
		}
예제 #33
0
 public MessageConsumerSynchronization(MessageConsumer consumer, Message message)
 {
     this.message  = message;
     this.consumer = consumer;
 }
예제 #34
0
			public ConsumerCloseSynchronization(MessageConsumer consumer)
			{
				this.consumer = consumer;
			}