Esempio 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");
            }

            MessageConsumer consumer = null;

            try
            {
                Destination dest = destination as Destination;
                consumer = new MessageConsumer(this, GetNextConsumerId(), dest, name, selector, this.connection.PrefetchPolicy.DurableTopicPrefetch, noLocal);
                consumer.ConsumerTransformer = this.ConsumerTransformer;
                this.AddConsumer(consumer);
                this.connection.SyncRequest(consumer.ConsumerInfo);

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

                throw;
            }

            return(consumer);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
 public void RemoveConsumer(MessageConsumer consumer)
 {
     connection.removeDispatcher(consumer.ConsumerId);
     if (!this.closing)
     {
         consumers.Remove(consumer.ConsumerId);
     }
 }
Esempio n. 4
0
 public void AddConsumer(MessageConsumer consumer)
 {
     if (!this.closing)
     {
         // Registered with Connection before we register at the broker.
         consumers[consumer.ConsumerId] = consumer;
         connection.addDispatcher(consumer.ConsumerId, this);
     }
 }
        private void ClearMessages(object value)
        {
            MessageConsumer consumer = value as MessageConsumer;

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

            consumer.ClearMessagesInProgress();
        }
Esempio n. 6
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            int prefetchSize = this.Connection.PrefetchPolicy.DurableTopicPrefetch;

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

            MessageConsumer consumer = null;

            try
            {
                Destination dest = destination as Destination;
                consumer = new MessageConsumer(this, GetNextConsumerId(), dest, null, selector, prefetchSize, noLocal);
                consumer.ConsumerTransformer = this.ConsumerTransformer;
                this.AddConsumer(consumer);

                // lets register the consumer first in case we start dispatching messages immediately
                this.Connection.SyncRequest(consumer.ConsumerInfo);

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

                throw;
            }

            return(consumer);
        }
        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);
                consumer.ConsumerTransformer = this.ConsumerTransformer;
                consumers[consumerId]        = consumer;

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

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

                throw;
            }

            return(consumer);
        }
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ConsumerInfo command = CreateConsumerInfo(destination, selector);

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

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

            try
            {
                consumer = new MessageConsumer(this, command);
                consumer.ConsumerTransformer = this.ConsumerTransformer;
                consumers[consumerId]        = consumer;

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

                // lets register the consumer first in case we start dispatching messages immediately
                this.Connection.SyncRequest(command);

                return(consumer);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }
        }
Esempio n. 9
0
 public ConsumerCloseSynchronization(MessageConsumer consumer)
 {
     this.consumer = consumer;
 }
Esempio n. 10
0
 public MessageConsumerSynchronization(MessageConsumer consumer)
 {
     this.consumer = consumer;
 }