首页 > 解决方案 > Yii2 - WebService API 和队列

问题描述

我正在使用 yiisoft/yii2-httpclient 扩展来使用 Web 服务。我有一个控制器可以在 web 服务中创建新记录。出于任何原因,操作创建可能会失败(超时、ws 已关闭等)如果记录失败,则将此操作创建放入队列(如 yiisoft/yii2-queue)中是正确的,在后台重试?

控制器.php

public function actionCreate()
    {
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('POST')
            ->setUrl('http://******/rooms')
            ->setData([
                'name' => $model->name,
                'date' => $model->date,
            ])
            ->send();
        if ($response->isOk) {
            return $this->redirect(['index']);
        }
    }

标签: phpyii2queuewebservice-client

解决方案


推荐阅读