All Products
Search
Document Center

ApsaraVideo Media Processing:Manage MPS queues

Last Updated:Nov 15, 2024

This topic provides examples on how to use ApsaraVideo Media Processing (MPS) SDK for Go V2.0 to manage MPS queues, including creating an MPS queue, updating an MPS queue, deleting an MPS queue, and querying MPS queues.

Prerequisites

An SDK client is initialized. For more information, see Initialize a client.

Create an MPS queue

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

Note
  • For more information about the types of MPS queues, see Create an MPS queue.

  • If the error message "The resource "Pipeline" quota has been used up" is returned, your quota for MPS queue is used up. You can submit a ticket to apply for a higher quota.

  • For more information about how to configure parameters related to notifications, see the NotifyConfig section of the "Parameter details" topic.

  • You can configure a Simple Message Queue (SMQ, formerly MNS) queue or topic to receive notifications. For more information, see Enable the notification feature for MPS jobs or workflows.

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
//
// Use your AccessKey ID and AccessKey secret to initialize a client.
//
// @return Client
//
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }
  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  addPipelineRequest := &mts20140618.AddPipelineRequest{
    // The name of the MPS queue.
    Name: tea.String("test-pipeline"),
    // The type of the MPS queue.
    Speed: tea.String("Standard"),
    // The speed level of the MPS queue.
    SpeedLevel: tea.Int64(1),
    // The SMQ notification settings.
    NotifyConfig: tea.String("{\"Topic\":\"mts-topic-1\"}"),
    // The role that is assigned to the current Resource Access Management (RAM) user.
    Role: tea.String("AliyunMTSDefaultRole"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.AddPipelineWithOptions(addPipelineRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.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.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

Update an MPS queue

You can call the UpdatePipeline operation to update an MPS queue.

// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// Use your AccessKey ID and AccessKey secret to initialize a client.
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }

  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  updatePipelineRequest := &mts20140618.UpdatePipelineRequest{
    PipelineId: tea.String("d1ce4d3efcb549419193f50f1fcd****"),
    Name: tea.String("example-pipeline-****"),
    State: tea.String("Paused"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.UpdatePipelineWithOptions(updatePipelineRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.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.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

Delete an MPS queue

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

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
//
// Use your AccessKey ID and AccessKey secret to initialize a client.
//
// @return Client
//
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }

  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  deletePipelineRequest := &mts20140618.DeletePipelineRequest{
    // The ID of the MPS queue to be deleted.
    PipelineId: tea.String("d1ce4d3efcb549419193f50f1fcd****"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.DeletePipelineWithOptions(deletePipelineRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.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.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

Query MPS queues based on MPS queue IDs

You can call the QueryPipelineList operation to query one or more MPS queues based on MPS queue IDs.

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
// 
// Use your AccessKey ID and AccessKey secret to initialize a client.
// 
// @return Client
// 
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }
  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  queryPipelineListRequest := &mts20140618.QueryPipelineListRequest{
    // The IDs of the MPS queues to be queried.
    PipelineIds: tea.String("d1ce4d3efcb549419193f50f1fcd****,72dfa5e679ab4be9a3ed9974c736****"),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.QueryPipelineListWithOptions(queryPipelineListRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.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.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}

Query MPS queues based on the status of MPS queues

You can call the SearchPipeline operation to query MPS queues in the specified state.

package main

import (
  "encoding/json"
  "strings"
  "fmt"
  "os"
  mts20140618  "github.com/alibabacloud-go/mts-20140618/v6/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  util  "github.com/alibabacloud-go/tea-utils/v2/service"
  "github.com/alibabacloud-go/tea/tea"
)


// Description:
//
// Use your AccessKey ID and AccessKey secret to initialize a client.
//
// @return Client
//
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {

  config := &openapi.Config{
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
    AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
    // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
    AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
  }

  config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
  _result = &mts20140618.Client{}
  _result, _err = mts20140618.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient()
  if _err != nil {
    return _err
  }

  searchPipelineRequest := &mts20140618.SearchPipelineRequest{
    // The state of the MPS queues that you want to query.
    State: tea.String("Paused"),
    // The number of entries to return on each page.
    PageSize: tea.Int64(10),
    // The number of the current page.
    PageNumber: tea.Int64(1),
  }
  runtime := &util.RuntimeOptions{}
  tryErr := func()(_e error) {
    defer func() {
      if r := tea.Recover(recover()); r != nil {
        _e = r
      }
    }()
    // Write your own code to display the response of the API operation if necessary.
    _, _err = client.SearchPipelineWithOptions(searchPipelineRequest, runtime)
    if _err != nil {
      return _err
    }

    return nil
  }()

  if tryErr != nil {
    var error = &tea.SDKError{}
    if _t, ok := tryErr.(*tea.SDKError); ok {
      error = _t
    } else {
      error.Message = tea.String(tryErr.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.
    fmt.Println(tea.StringValue(error.Message))
    // The URL of the corresponding error diagnostics page.
    var data interface{}
    d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
    d.Decode(&data)
    if m, ok := data.(map[string]interface{}); ok {
      recommend, _ := m["Recommend"]
      fmt.Println(recommend)
    }
    _, _err = util.AssertAsString(error.Message)
    if _err != nil {
      return _err
    }
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}