Example #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);
        }
Example #2
0
 private void RemoveConsumer(MessageConsumer consumer)
 {
     Connection.RemoveDispatcher(consumer.ConsumerId);
     if (!_closing)
     {
         _consumers.Remove(consumer.ConsumerId);
     }
 }
Example #3
0
        private void AddConsumer(MessageConsumer consumer)
        {
            if (_closing)
            {
                return;
            }

            // Registered with Connection before we register at the broker.
            _consumers[consumer.ConsumerId] = consumer;
            Connection.AddDispatcher(consumer.ConsumerId, this);
        }
Example #4
0
        private void AddConsumer(MessageConsumer consumer)
        {
            if (_closing)
            {
                return;
            }

            // Registered with Connection before we register at the broker.
            _consumers.AddOrUpdate(consumer.ConsumerId, consumer, (k, v) => consumer);

            Connection.AddDispatcher(consumer.ConsumerId, this);
        }
Example #5
0
        private void RemoveConsumer(MessageConsumer consumer)
        {
            Connection.RemoveDispatcher(consumer.ConsumerId);
            if (_closing)
            {
                return;
            }

            if (!_consumers.TryRemove(consumer.ConsumerId, out _) && Tracer.IsWarnEnabled)
            {
                Tracer.Warn($"Failed to remove consumer with consumer id: '{consumer.ConsumerId}'.");
            }
        }
Example #6
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);
        }
Example #7
0
        private void Dispatch(MessageDispatch dispatch)
        {
            try
            {
                MessageConsumer consumer = null;

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

                // If the consumer is not available, just ignore the message.
                // Otherwise, dispatch the message to the consumer.
                consumer?.Dispatch(dispatch);
            }
            catch (Exception ex)
            {
                Tracer.WarnFormat("Caught Exception While Dispatching: {0}", ex.Message);
            }
        }
Example #8
0
 public ConsumerCloseSynchronization(MessageConsumer consumer)
 {
     _consumer = consumer;
 }
Example #9
0
 public MessageConsumerSynchronization(MessageConsumer consumer)
 {
     _consumer = consumer;
 }