public function pop()
    {
        $keys = array_keys($this->queues);

        for ($this->queueCounter; isset($keys[$this->queueCounter]); $this->queueCounter++) {
            $queue = $this->queues[$keys[$this->queueCounter]];

            $message = $queue->pop();

            if ($message !== null) {
                $this->queueCounter++;
                $this->processedMessages++;
                return $message;
            }

            // After the last queue has been popped
            if ((count($this->queues) -1) === $this->queueCounter) {
                $this->queueCounter = 0;

                if ($this->processedMessages === 0) {
                    return null;
                }

                $this->processedMessages = 0;
            }
        }

        return null;
    }