All Products
Search
Document Center

ApsaraVideo Media Processing:Manage MPS queues

Last Updated:Nov 15, 2024

An ApsaraVideo Media Processing (MPS) queue is a queue for processing jobs. After you submit asynchronous jobs, the jobs are queued for running based on the job priorities and the sequence in which the jobs are submitted. This topic provides examples on how to use MPS SDK for Node.js V2.0 to manage MPS queues, including creating, updating, deleting, and querying MPS queues.

Create an MPS queue

You can also call the AddPipeline operation to create an MPS queue.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let addPipelineRequest = new Mts20140618.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',
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.addPipelineWithOptions(addPipelineRequest, runtime);
        } catch (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.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));

Search for MPS queues

You can also call the SearchPipeline operation to search for MPS queues in a specific state.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let searchPipelineRequest = new Mts20140618.SearchPipelineRequest({
                // The state of the MPS queues that you want to search for.
                state: 'Paused',
                // The number of entries to return on each page.
                pageSize: 10,
                // The number of the current page.
                pageNumber: 1,
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.searchPipelineWithOptions(searchPipelineRequest, runtime);
        } catch (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.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));

Query MPS queues based on queue IDs

You can also call the QueryPipelineList operation to query MPS queues based on queue IDs.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let queryPipelineListRequest = new Mts20140618.QueryPipelineListRequest({
                // The IDs of the MPS queues that you want to query.
                pipelineIds: 'd1ce4d3efcb549419193f50f1fcd****,72dfa5e679ab4be9a3ed9974c736****',
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.queryPipelineListWithOptions(queryPipelineListRequest, runtime);
        } catch (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.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));

Update an MPS queue

You can also call the UpdatePipeline operation to update an MPS queue, including the name and status of an MPS queue. The states of an MPS queue include Active and Paused.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let updatePipelineRequest = new Mts20140618.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',
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.updatePipelineWithOptions(updatePipelineRequest, runtime);
        } catch (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.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));

Delete an MPS queue

You can call the DeletePipeline operation to delete an MPS queue.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let deletePipelineRequest = new Mts20140618.DeletePipelineRequest({
                // The ID of the MPS queue that you want to delete.
                pipelineId: 'd1ce4d3efcb549419193f50f1fcd****',
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.deletePipelineWithOptions(deletePipelineRequest, runtime);
        } catch (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.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));

References