This topic provides examples on how to call API operations to create, update, delete, and query an ApsaraVideo Media Processing (MPS) queue. The API operations are encapsulated in MPS SDK for Java.

Prerequisites

MPS SDK for Java is initialized. For more information, see Initialization.

AddPipeline

Creates an MPS queue.
Note
  • For more information about MPS queue types, see Manage MPS queues.
  • If the error message "The resource "Pipeline" quota has been used up" is returned, MPS queue quota has been used up. You can submit a ticket to apply for the MPS queue quota.
  • For more information about how to configure parameters related to notifications, see NotifyConfig.
  • You can configure a Message Service (MNS) queue or topic to receive notifications. For more information, see Enable the notification feature for jobs or workflows.
/**
 * AddPipeline
 * @param client
 * @return
 * @throws Exception
 */
public static AddPipelineResponse addPipeline(DefaultAcsClient client) throws Exception {

    AddPipelineRequest request = new AddPipelineRequest();
    request.setName("test-pipeline");
    // The type of the MPS queue.
    request.setSpeed("Standard");
    //request.setSpeedLevel(1l);
    //request.setNotifyConfig("{\"Topic\":\"mts-topic-1\"}");

    return client.getAcsResponse(request);
}

UpdatePipeline

Updates an MPS queue.

/**
 * UpdatePipeline
 * @param client
 * @return
 * @throws Exception
 */
public static UpdatePipelineResponse updatePipeline(DefaultAcsClient client) throws Exception {

    UpdatePipelineRequest request = new UpdatePipelineRequest();
    // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
    request.setPipelineId("e03549d796fad2bcb32a****");
    request.setName("update name");
    // The status of the MPS queues. Valid values: Active and Paused. A value of Active indicates that the MPS queue is enabled. A value of Paused indicates that the MPS queue is disabled.
    request.setState("Active");
    //request.setNotifyConfig("{\"Topic\":\"mts-topic-1\"}");

    return client.getAcsResponse(request);
}

DeletePipeline

Deletes an MPS queue.

/**
 * DeletePipeline
 * @param client
 * @return
 * @throws Exception
 */
public static DeletePipelineResponse deletePipeline(DefaultAcsClient client) throws Exception {

    DeletePipelineRequest request = new DeletePipelineRequest();
    // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
    request.setPipelineId("e03549d796fadd82bcb32a****");

    return client.getAcsResponse(request);
}

QueryPipelineList

Queries one or more MPS queues based on the IDs of the MPS queues.

/**
 * QueryPipelineList
 * @param client
 * @return
 * @throws Exception
 */
public static QueryPipelineListResponse queryPipelineList(DefaultAcsClient client) throws Exception {

    QueryPipelineListRequest request = new QueryPipelineListRequest();
    // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
    // You can query up to 10 MPS queues at a time. Separate the IDs of MPS queues with commas (,).
    request.setPipelineIds("e03549d796fad2bcb32a****");

    return client.getAcsResponse(request);
}

SearchPipeline

Queries MPS queues in the specified state.

/**
 * SearchPipeline
 * @param client
 * @return
 * @throws Exception
 */
public static SearchPipelineResponse searchPipeline(DefaultAcsClient client) throws Exception {

    SearchPipelineRequest request = new SearchPipelineRequest();
    // The status of the MPS queues. Valid values: All, Active, and Paused. A value of All indicates all MPS queues. A value of Active indicates enabled MPS queues. A value of Paused indicates disabled MPS queues.
    request.setState("All");

    return client.getAcsResponse(request);
}

Sample code

import com.aliyun.mps.utils.InitClient;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.mts.model.v20140618.*;

/**
 * ***** Usage notes ******
 * This example shows basic operations on an MPS queue.
 *
 * ***** References ******
 * For more information about addPipeline, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/api-doc-mts-2014-06-18-api-doc-addpipeline.
 * For more information about updatePipeline, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/api-doc-mts-2014-06-18-api-doc-updatepipeline.
 * For more information about deletePipeline, see https:/www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/api-doc-mts-2014-06-18-api-doc-deletepipeline.
 * For more information about queryPipelineList, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/api-doc-mts-2014-06-18-api-doc-querypipelinelist.
 * For more information about searchPipeline, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/api-doc-mts-2014-06-18-api-doc-searchpipeline.
 *
 * For more information about the NotifyConfig parameter, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/parameter-details-a#section-ayf-324-y2b.
 * ***** main method ******
 * In this example, only addPipeline and updatePipeline are called. If you want to call another operation, set response to the API that you require.
 */
public class Pipeline {

    public static void main(String[] args) throws ClientException {

        // Initialize MPS SDK for Java.
        DefaultAcsClient client = InitClient.initMpsClient();

        AddPipelineResponse response;
        try {
            response = addPipeline(client);
            System.out.println("RequestId is:" + response.getRequestId());
            System.out.println("pipelineId is:" + response.getPipeline().getId());
        } catch (Exception e) {
            e.printStackTrace();
        }

//        UpdatePipelineResponse response;
//        try {
//            response = updatePipeline(client);
//            System.out.println("RequestId is:" + response.getRequestId());
//            System.out.println("Pipeline is:" + JSON.toJSON(response.getPipeline()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

    }

    /**
     * AddPipeline
     * @param client
     * @return
     * @throws Exception
     */
    public static AddPipelineResponse addPipeline(DefaultAcsClient client) throws Exception {

        AddPipelineRequest request = new AddPipelineRequest();
        request.setName("test-pipeline");
        // The type of the MPS queue.
        request.setSpeed("Standard");
        //request.setSpeedLevel(1l);
        //request.setNotifyConfig("{\"Topic\":\"mts-topic-1\"}");

        return client.getAcsResponse(request);
    }

    /**
     * UpdatePipeline
     * @param client
     * @return
     * @throws Exception
     */
    public static UpdatePipelineResponse updatePipeline(DefaultAcsClient client) throws Exception {

        UpdatePipelineRequest request = new UpdatePipelineRequest();
        // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
        request.setPipelineId("e03549796fad9d72bcb32a****");
        request.setName("update name");
        // The status of the MPS queues. Valid values: Active and Paused. A value of Active indicates that the MPS queue is enabled. A value of Paused indicates that the MPS queue is disabled.
        request.setState("Active");
        //request.setNotifyConfig("{\"Topic\":\"mts-topic-1\"}");

        return client.getAcsResponse(request);
    }

    /**
     * DeletePipeline
     * @param client
     * @return
     * @throws Exception
     */
    public static DeletePipelineResponse deletePipeline(DefaultAcsClient client) throws Exception {

        DeletePipelineRequest request = new DeletePipelineRequest();
        // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
        request.setPipelineId("e03549796fad9d7d82bcb32a****");

        return client.getAcsResponse(request);
    }

    /**
     * QueryPipelineList
     * @param client
     * @return
     * @throws Exception
     */
    public static QueryPipelineListResponse queryPipelineList(DefaultAcsClient client) throws Exception {

        QueryPipelineListRequest request = new QueryPipelineListRequest();
        // The ID of the MPS queue. To view the ID, log on to the MPS console and choose Global Settings > MPS Queue and Callback on the left-side pane. You can also create an MPS queue and obtain its ID by calling the addPipeline operation.
        // You can query up to 10 MPS queues at a time. Separate the IDs of MPS queues with commas (,).
        request.setPipelineIds("e03549d796fad2bcb32a****");

        return client.getAcsResponse(request);
    }

    /**
     * SearchPipeline
     * @param client
     * @return
     * @throws Exception
     */
    public static SearchPipelineResponse searchPipeline(DefaultAcsClient client) throws Exception {

        SearchPipelineRequest request = new SearchPipelineRequest();
        // The status of the MPS queues. Valid values: All, Active, and Paused. A value of All indicates all MPS queues. A value of Active indicates enabled MPS queues. A value of Paused indicates disabled MPS queues.
        request.setState("All");

        return client.getAcsResponse(request);
    }
}