Manage MPS queues

Updated at:

An ApsaraVideo Media Processing (MPS) queue holds asynchronous jobs waiting to run. Jobs are processed in order of priority and submission time. This topic shows how to use MPS SDK for PHP V2.0 to create, query, update, and delete MPS queues.

Create an MPS queue

Call the AddPipeline operation to create an MPS queue.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\AddPipelineRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $addPipelineRequest = new AddPipelineRequest([
                // The name of the MPS queue.
                "name" => "test-pipeline",
                // The type of the MPS queue.
                "speed" => "Standard",
                // The speed level of the MPS queue.
                "speedLevel" => 1,
                // The Simple Message Queue (SMQ, formerly MNS) notification settings.
                "notifyConfig" => "{\"Topic\":\"mts-topic-1\"}",
                // The role that is assigned to the current Resource Access Management (RAM) user.
                "role" => "AliyunMTSDefaultRole"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to display the response of the API operation if necessary.
            $client->addPipelineWithOptions($addPipelineRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            var_dump($error->message);
            // The URL of the corresponding error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));

Query MPS queues in a specific state

Call the SearchPipeline operation to query MPS queues in a specific state.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SearchPipelineRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $searchPipelineRequest = new SearchPipelineRequest([
                // The state of the MPS queues that you want to query.
                "state" => "Paused",
                // The number of entries to return on each page.
                "pageSize" => 10,
                // The number of the current page.
                "pageNumber" => 1
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to display the response of the API operation if necessary.
            $client->searchPipelineWithOptions($searchPipelineRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            var_dump($error->message);
            // The URL of the corresponding error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));

Query MPS queues based on queue IDs

Call the QueryPipelineList operation to query MPS queues by their IDs.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QueryPipelineListRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $queryPipelineListRequest = new QueryPipelineListRequest([
                // The IDs of the MPS queues that you want to query.
                "pipelineIds" => "d1ce4d3efcb549419193f50f1fcd****,72dfa5e679ab4be9a3ed9974c736****"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to display the response of the API operation if necessary.
            $client->queryPipelineListWithOptions($queryPipelineListRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            var_dump($error->message);
            // The URL of the corresponding error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));

Update an MPS queue

Call the UpdatePipeline operation to update an MPS queue. You can update the queue name and state. Valid states are Active and Paused.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\UpdatePipelineRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $updatePipelineRequest = new UpdatePipelineRequest([
                // The ID of the MPS queue that you want to update.
                "pipelineId" => "d1ce4d3efcb549419193f50f1fcd****",
                // The new name of the MPS queue.
                "name" => "example-pipeline-****",
                // The new state of the MPS queue.
                "state" => "Paused",
                // The SMQ notification settings.
                "notifyConfig" => "{\"Topic\":\"example-topic-****\"}",
                // The role that is assigned to the current RAM user.
                "role" => "AliyunMTSDefaultRole"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to display the response of the API operation if necessary.
            $client->updatePipelineWithOptions($updatePipelineRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            var_dump($error->message);
            // The URL of the corresponding error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));

Delete an MPS queue

Call the DeletePipeline operation to delete an MPS queue.

<?php

namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\DeletePipelineRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class Sample {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize the client.
     * @return Mts Client
     */
    public static function createClient(){

        $config = new Config([
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                "accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                "accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
        ]);
        $config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
        return new Mts($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $deletePipelineRequest = new DeletePipelineRequest([
                // The ID of the MPS queue that you want to delete.
                "pipelineId" => "d1ce4d3efcb549419193f50f1fcd****"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // Write your own code to display the response of the API operation if necessary.
            $client->deletePipelineWithOptions($deletePipelineRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            var_dump($error->message);
            // The URL of the corresponding error diagnostics page.
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
        if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));

References