protected function receiveInternal($subscriber_id = null, $limit = -1, $mode = self::GET_RESERVE)
    {
        $primaryKey = models\DbMessage::primaryKey();
        $trx = models\DbMessage::getDb()->transaction !== null ? null : models\DbMessage::getDb()->beginTransaction();
        $messages = models\DbMessage::find()
            ->withQueue($this->id)
            ->withSubscriber($subscriber_id)
            ->available($this->timeout)
            ->limit($limit)
            ->indexBy($primaryKey[0])
            ->all();
        if (!empty($messages)) {
            $now = new \DateTime('now', new \DateTimezone('UTC'));
            if ($mode === self::GET_DELETE) {
                $attributes = ['status' => Message::DELETED, 'deleted_on' => $now->format('Y-m-d H:i:s')];
            } elseif ($mode === self::GET_RESERVE) {
                $attributes = ['status' => Message::RESERVED, 'reserved_on' => $now->format('Y-m-d H:i:s')];
            }
            if (isset($attributes)) {
                models\DbMessage::updateAll($attributes, ['in', models\DbMessage::primaryKey(), array_keys($messages)]);
            }
        }
        if ($trx !== null) {
            $trx->commit();
        }

        return models\DbMessage::createMessages($messages);
    }