public void OnAccept(IDelivery delivery) { Interlocked.Increment(ref numAcceptedMessages); modelReference.Execute( m => m.BasicAck(delivery.Tag, false)); }
public void Visit(IQueue queue) { VisitOnce(queue, () => { if (queue.HasName) { var args = new Dictionary <string, object>(); if (queue.QueueAutoExpire.HasValue) { args.Add("x-expires", queue.QueueAutoExpire.Value.TotalMilliseconds); } if (!string.IsNullOrEmpty(queue.DeadLetterExchange)) { args.Add("x-dead-letter-exchange", queue.DeadLetterExchange); } if (queue.MessageTimeToLive.HasValue) { args.Add("x-message-ttl", (int)queue.MessageTimeToLive.Value.TotalMilliseconds); } model.Execute(m => m.QueueDeclare( queue.Name, queue.Durability == Durability.Durable, // durable queue.IsExclusive, // exclusive queue.IsAutoDelete, // auto-delete args)); } else { var declared = model.Execute(m => m.QueueDeclare()); queue.Name = declared.QueueName; } }); }
public override void Dispose() { logger.DebugFormat("Shutting down subscription: {0}", this); if (isDisposing) { var message = string.Format("Subscription already disposing: {0}", this); throw new ObjectDisposedException(message); } // 1. we're disposing, let everyone know isDisposing = true; // 2. tell the channel to stop receiving new messages logger.Info("SHUTDOWN: Stopping channel flow"); modelReference.Execute(m => m.ChannelFlow(false)); // 3. we've disposed of the current subscription so wait for the // listener thread to to finish doing what it's doing, it might // dispatch something to the delivery strategy. once we're done // with this then we'll stop accepting any new messages logger.Info("SHUTDOWN: Waiting for listener thread to terminate"); if (listenerThread != null && listenerThread.IsAlive) { listenerThread.Join(); } // 4. stop the delivery strategy, this will wait for any work currently // running to finish logger.Info("SHUTDOWN: Stopping delivery strategy"); deliveryStrategy.Stop(); // 5. finally we can dispose of the model reference, this will close // the model and cancel any consumers that are outstanding logger.Info("SHUTDOWN: disposing of model reference"); modelReference.Dispose(); base.Dispose(); }