Пример #1
0
        public void RemoveQueue(string topic, int queueId)
        {
            var   key = CreateQueueKey(topic, queueId);
            Queue queue;

            if (!_queueDict.TryGetValue(key, out queue))
            {
                return;
            }

            //检查队列状态是否是已禁用
            if (queue.Status != QueueStatus.Disabled)
            {
                throw new Exception("Queue status is not disabled, cannot be deleted.");
            }
            //检查是否有未消费完的消息
            if (queue.GetMessageRealCount() > 0L)
            {
                throw new Exception("Queue is not allowed to delete as there are messages exist in this queue.");
            }

            //删除队列消息
            _messageStore.DeleteQueueMessage(topic, queueId);

            //删除队列消费进度信息
            _offsetManager.DeleteQueueOffset(topic, queueId);

            //删除队列
            _queueStore.DeleteQueue(queue);

            //从内存移除队列
            _queueDict.Remove(key);
        }