Use the Go SDK V2.0 to add, update, delete, and query MPS pipelines.
Prerequisites
An SDK client is initialized. For more information, see Initialize a client.
Create a pipeline
Call the AddPipeline operation to create a pipeline.
-
For more information about pipeline types, see Enable a pipeline.
-
If you receive the 'The resource "Pipeline" quota has been used up' error message when you add a pipeline, your pipeline quota is exhausted. You can submit a ticket to request a pipeline quota increase.
-
To configure NotifyConfig for pipeline messages, see NotifyConfig details.
-
Pipelines support message configurations in queue or topic mode. For more information, see Configure message notifications.
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 an AccessKey pair to initialize the 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 set.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
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 pipeline.
Name: tea.String("test-pipeline"),
// The type of the pipeline.
Speed: tea.String("Standard"),
// The level of the pipeline.
SpeedLevel: tea.Int64(1),
// The MNS notification configuration.
NotifyConfig: tea.String("{\"Topic\":\"mts-topic-1\"}"),
// The role.
Role: tea.String("AliyunMTSDefaultRole"),
}
runtime := &util.RuntimeOptions{}
tryErr := func()(_e error) {
defer func() {
if r := tea.Recover(recover()); r != nil {
_e = r
}
}()
// If you copy the code to run, print the return value of the API call.
_, _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())
}
// The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// The error message.
fmt.Println(tea.StringValue(error.Message))
// The diagnosis URL.
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 a pipeline configuration
Call the UpdatePipeline operation to update a pipeline configuration.
// 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 an AccessKey pair to initialize the 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 set.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
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
}
}()
// If you copy the code to run, print the return value of the API call.
_, _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())
}
// The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// The error message.
fmt.Println(tea.StringValue(error.Message))
// The diagnosis URL.
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 a pipeline
Call the DeletePipeline operation to delete a pipeline.
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 an AccessKey pair to initialize the 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 set.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
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 pipeline to delete.
PipelineId: tea.String("d1ce4d3efcb549419193f50f1fcd****"),
}
runtime := &util.RuntimeOptions{}
tryErr := func()(_e error) {
defer func() {
if r := tea.Recover(recover()); r != nil {
_e = r
}
}()
// If you copy the code to run, print the return value of the API call.
_, _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())
}
// The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// The error message.
fmt.Println(tea.StringValue(error.Message))
// The diagnosis URL.
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 pipelines by ID
Call the QueryPipelineList operation to query pipelines by ID.
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 an AccessKey pair to initialize the 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 set.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
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{
// A list of pipeline IDs to query.
PipelineIds: tea.String("d1ce4d3efcb549419193f50f1fcd****,72dfa5e679ab4be9a3ed9974c736****"),
}
runtime := &util.RuntimeOptions{}
tryErr := func()(_e error) {
defer func() {
if r := tea.Recover(recover()); r != nil {
_e = r
}
}()
// If you copy the code to run, print the return value of the API call.
_, _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())
}
// The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// The error message.
fmt.Println(tea.StringValue(error.Message))
// The diagnosis URL.
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 pipelines by state
Call the SearchPipeline operation to query pipelines by 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 an AccessKey pair to initialize the 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 set.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
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 pipelines to search for.
State: tea.String("Paused"),
// The number of entries to return on each page for a paged query.
PageSize: tea.Int64(10),
// The current page number.
PageNumber: tea.Int64(1),
}
runtime := &util.RuntimeOptions{}
tryErr := func()(_e error) {
defer func() {
if r := tea.Recover(recover()); r != nil {
_e = r
}
}()
// If you copy the code to run, print the return value of the API call.
_, _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())
}
// The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project.
// The error message.
fmt.Println(tea.StringValue(error.Message))
// The diagnosis URL.
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)
}
}