Exemplo n.º 1
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, String name, String selector, Boolean noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            MessageConsumer consumer = null;

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

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

                throw;
            }

            return(consumer);
        }
Exemplo n.º 2
0
        public IMessageConsumer CreateConsumer(IDestination destination, String selector, Boolean noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            var prefetchSize = Connection.PrefetchPolicy.DurableTopicPrefetch;

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

            MessageConsumer consumer = null;

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

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

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

                throw;
            }

            return(consumer);
        }