文档

管道管理

更新时间:

管道是任务的队列。当您提交异步任务后,任务会进入管道中进行排队,根据优先级和提交顺序依次被调度执行。本文提供了PHP SDK管道相关功能的API调用示例,包含添加管道、更新管道、删除管道、查询管道。

创建管道

可以通过AddPipeline接口创建管道。

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = addPipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function addPipeline($client) {
    $request = new Mts\AddPipelineRequest();
    $request->setName("test-pipeline");
    $request->setSpeed('Standard');
    return $client->getAcsResponse($request);
}

搜索管道

可以直接通过SearchPipeline接口搜索管道信息。

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = searchPipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function searchPipeline($client) {
    $request = new Mts\SearchPipelineRequest();
    $request->setState("Paused");
    $request->setAcceptFormat('JSON');
    return $client->getAcsResponse($request);
}

查询管道

如果已经知道pipelineId,可以通过pipelineId调用QueryPipelineList接口查询管道信息。

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = queryPipelineList($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function queryPipelineList($client) {
    $request = new Mts\QueryPipelineListRequest();
    # 管道ID,多个管道用','分隔
    $request->setPipelineIds("0ba6fb1ab75271a2e1293******");
    return $client->getAcsResponse($request);
}

更新管道

通过UpdatePipeline更新管道信息,包括更新管道名称,状态。管道的状态包括Active、Paused。

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = updatePipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function updatePipeline($client) {
    $request = new Mts\UpdatePipelineRequest();
    $request->setPipelineId("0ba6fb15271a2e1293*******");
    $request->setName("update name");
    $request->setState("Paused");
    return $client->getAcsResponse($request);
}

删除管道

可以调用DeletePipeline接口删除管道。

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}


try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = deletePipeline($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function deletePipeline($client) {
    $request = new Mts\DeletePipelineRequest();
    $request->setPipelineId("0ba6fb1ab771a2e1293******");
    return $client->getAcsResponse($request);
}

相关文档