public void Purge(IQueue queue)
        {
            Preconditions.CheckNotNull(queue, "queue");

            using (var channel = PersistentConnection.CreateModel())
            {
                channel.QueuePurge(queue.Name);
            }
        }
        public virtual void Subscribe(IQueue queue, Func <Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");

            if (disposed)
            {
                throw new Exception("This bus has been disposed");
            }

            var subscriptionAction = new SubscriptionAction(queue.IsSingleUse);

            subscriptionAction.Action = () =>
            {
                var channel = PersistentConnection.CreateModel();
                channel.ModelShutdown += (model, reason) => Logger.Debug(string.Format("Model Shutdown for queue: '{0}'", queue.Name));

                queue.Visit(new TopologyBuilder(channel));

                //channel.BasicQos(0, connectionConfiguration.PrefetchCount, false);
                channel.BasicQos(0, 50, false);

                var consumer = ConsumerFactory.CreateConsumer(subscriptionAction, channel, queue.IsSingleUse,
                                                              (consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body) =>
                {
                    var messageRecievedInfo = new MessageReceivedInfo
                    {
                        ConsumerTag = consumerTag,
                        DeliverTag  = deliveryTag,
                        Redelivered = redelivered,
                        Exchange    = exchange,
                        RoutingKey  = routingKey
                    };
                    MessageProperties messageProperties = new MessageProperties();
                    properties.CopyTo(messageProperties);
                    return(onMessage(body, messageProperties, messageRecievedInfo));
                });

                channel.BasicConsume(
                    queue.Name,             // queue
                    NoAck,                  // noAck
                    consumer.ConsumerTag,   // consumerTag
                    consumer);              // consumer

                Logger.Debug(string.Format("Declared Consumer. queue='{0}', prefetchcount={1}",
                                           queue.Name,
                                           _connectionConfiguration.PrefetchCount));
            };

            AddSubscriptionAction(subscriptionAction);
        }
        public virtual void Dispose()
        {
            if (disposed)
            {
                return;
            }

            ConsumerFactory.Dispose();
            PersistentConnection.Dispose();

            disposed = true;

            Logger.Debug("Connection disposed");
        }