예제 #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);
        }
예제 #2
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);
        }
예제 #3
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);
                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);
        }
예제 #4
0
        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;
            }
        }