An ApsaraVideo Media Processing (MPS) queue schedules asynchronous jobs based on priority and submission order. The following examples show how to use MPS SDK for Node.js V2.0 to create, query, update, and delete MPS queues.
Create an MPS queue
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
Call the SearchPipeline operation to search for MPS queues by 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
Call the QueryPipelineList operation to query MPS queues by queue ID.
'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
Call the UpdatePipeline operation to update the name or state of an MPS queue. Valid states: 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
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
该文章对您有帮助吗?