分布式消息服务 RabbitMQ
| 产品详情
  • 生命周期管理
    • 批量删除实例BatchRestartOrDeleteInstances
    • 创建实例CreatePostPaidInstanceByEngine
    • 删除指定的实例DeleteInstance
    • 开启RabbitMQ实例域名访问能力EnableDns
    • 查询所有实例列表ListInstancesDetails
    • 查询指定实例ShowInstance
    • 修改实例信息UpdateInstance
  • 实例管理
    • 查询插件列表ListPlugins
    • 重置密码ResetPassword
    • 开启或关闭插件UpdatePlugins
  • 规格变更管理
    • 新规格实例的规格变更ResizeEngineInstance
    • 查询新规格可扩容规格列表ShowEngineInstanceExtendProductInfo
  • Vhost管理
    • 批量删除指定VhostBatchDeleteVhosts
    • 创建VhostCreateVhost
    • 查询Vhost列表ListVhosts
  • Exchange管理
    • 批量删除指定ExchangeBatchDeleteExchanges
    • 创建ExchangeCreateExchange
    • 查询Exchange列表ListExchanges
  • Queue管理
    • 批量删除指定QueueBatchDeleteQueues
    • 创建QueueCreateQueue
    • 清空Queue消息DeleteQueueInfo
    • 查询所属Vhost下Queue的列表ListQueues
    • 查询指定Queue详情ShowQueueDetails
  • Binding管理
    • 添加绑定CreateBinding
    • 删除绑定DeleteBinding
    • 查询Exchange绑定信息列表ListBindings
  • 用户管理
    • 创建用户CreateUser
    • 删除用户DeleteUser
    • 查询用户列表ListUser
    • 修改用户参数UpdateUser
  • 后台任务管理
    • 删除后台任务管理中的指定记录DeleteBackgroundTask
    • 查询实例的后台任务列表ListBackgroundTasks
    • 查询后台任务管理中的指定记录ShowBackgroundTask
  • 标签管理
    • 批量添加或删除实例标签BatchCreateOrDeleteRabbitMqTag
    • 查询项目标签ShowRabbitMqProjectTags
    • 查询实例标签ShowRabbitMqTags
  • 其他接口
    • 查询可用区信息ListAvailableZones
    • 查询产品规格列表ListEngineProducts
    • 查询实例在CES的监控层级关系ShowCesHierarchy
    • 查询维护时间窗时间段ShowMaintainWindows

BatchRestartOrDeleteInstances

批量删除实例

POST
https://dms.af-south-1.myhuaweicloud.com/v2/{project_id}/instances/action
高级设置
只看必填项
填写默认值
密文显示特定参数
*
Region
Parameters
*
project_id
Body
*{
*
instances
: [
+Add
*]
*
action
:
*
all_failure
:
}

功能介绍

批量删除实例。

实例删除后,实例中原有的数据将被删除,且没有备份,请谨慎操作。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/instances/action

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方式请参见获取项目ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

instances

Array of strings

实例的ID列表。

action

String

对实例的操作:delete

all_failure

String

是否批量删除创建失败的实例。

当参数值为“rabbitmq”时,删除租户所有创建失败的实例,此时请求参数instances可为空。

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

results

Array of results objects

修改实例的结果。

表4 results

参数

参数类型

描述

result

String

操作结果:

  • success: 操作成功

  • failed: 操作失败

instance

String

实例ID。

请求示例

  • 批量删除实例。

    POST https://{endpoint}/v2/{project_id}/instances/action
    
    {
      "action" : "delete",
      "instances" : [ "54602a9d-5e22-4239-9123-77e350df4a34", "7166cdea-dbad-4d79-9610-7163e6f8b640" ]
    }
  • 删除所有创建失败的实例。

    POST https://{endpoint}/v2/{project_id}/instances/action
    
    {
      "action" : "delete",
      "all_failure" : "rabbitmq"
    }

响应示例

状态码:200

批量删除实例成功。

{
  "results" : [ {
    "result" : "success",
    "instance" : "019cacb7-4ff0-4d3c-9f33-f5f7b7fdc0e6"
  } ]
}

SDK代码示例

SDK代码示例如下。

  • 批量删除实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.rabbitmq.v2.region.RabbitMQRegion;
    import com.huaweicloud.sdk.rabbitmq.v2.*;
    import com.huaweicloud.sdk.rabbitmq.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class BatchRestartOrDeleteInstancesSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            RabbitMQClient client = RabbitMQClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(RabbitMQRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchRestartOrDeleteInstancesRequest request = new BatchRestartOrDeleteInstancesRequest();
            BatchRestartOrDeleteInstanceReq body = new BatchRestartOrDeleteInstanceReq();
            List<String> listbodyInstances = new ArrayList<>();
            listbodyInstances.add("54602a9d-5e22-4239-9123-77e350df4a34");
            listbodyInstances.add("7166cdea-dbad-4d79-9610-7163e6f8b640");
            body.withAction(BatchRestartOrDeleteInstanceReq.ActionEnum.fromValue("delete"));
            body.withInstances(listbodyInstances);
            request.withBody(body);
            try {
                BatchRestartOrDeleteInstancesResponse response = client.batchRestartOrDeleteInstances(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 删除所有创建失败的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.rabbitmq.v2.region.RabbitMQRegion;
    import com.huaweicloud.sdk.rabbitmq.v2.*;
    import com.huaweicloud.sdk.rabbitmq.v2.model.*;
    
    
    public class BatchRestartOrDeleteInstancesSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            RabbitMQClient client = RabbitMQClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(RabbitMQRegion.valueOf("<YOUR REGION>"))
                    .build();
            BatchRestartOrDeleteInstancesRequest request = new BatchRestartOrDeleteInstancesRequest();
            BatchRestartOrDeleteInstanceReq body = new BatchRestartOrDeleteInstanceReq();
            body.withAllFailure(BatchRestartOrDeleteInstanceReq.AllFailureEnum.fromValue("rabbitmq"));
            body.withAction(BatchRestartOrDeleteInstanceReq.ActionEnum.fromValue("delete"));
            request.withBody(body);
            try {
                BatchRestartOrDeleteInstancesResponse response = client.batchRestartOrDeleteInstances(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 批量删除实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkrabbitmq.v2.region.rabbitmq_region import RabbitMQRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkrabbitmq.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = RabbitMQClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(RabbitMQRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = BatchRestartOrDeleteInstancesRequest()
            listInstancesbody = [
                "54602a9d-5e22-4239-9123-77e350df4a34",
                "7166cdea-dbad-4d79-9610-7163e6f8b640"
            ]
            request.body = BatchRestartOrDeleteInstanceReq(
                action="delete",
                instances=listInstancesbody
            )
            response = client.batch_restart_or_delete_instances(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 删除所有创建失败的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkrabbitmq.v2.region.rabbitmq_region import RabbitMQRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkrabbitmq.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = RabbitMQClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(RabbitMQRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = BatchRestartOrDeleteInstancesRequest()
            request.body = BatchRestartOrDeleteInstanceReq(
                all_failure="rabbitmq",
                action="delete"
            )
            response = client.batch_restart_or_delete_instances(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 批量删除实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        rabbitmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := rabbitmq.NewRabbitMQClient(
            rabbitmq.RabbitMQClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.BatchRestartOrDeleteInstancesRequest{}
    	var listInstancesbody = []string{
            "54602a9d-5e22-4239-9123-77e350df4a34",
    	    "7166cdea-dbad-4d79-9610-7163e6f8b640",
        }
    	request.Body = &model.BatchRestartOrDeleteInstanceReq{
    		Action: model.GetBatchRestartOrDeleteInstanceReqActionEnum().DELETE,
    		Instances: &listInstancesbody,
    	}
    	response, err := client.BatchRestartOrDeleteInstances(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 删除所有创建失败的实例。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        rabbitmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rabbitmq/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := rabbitmq.NewRabbitMQClient(
            rabbitmq.RabbitMQClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.BatchRestartOrDeleteInstancesRequest{}
    	allFailureBatchRestartOrDeleteInstanceReq:= model.GetBatchRestartOrDeleteInstanceReqAllFailureEnum().RABBITMQ
    	request.Body = &model.BatchRestartOrDeleteInstanceReq{
    		AllFailure: &allFailureBatchRestartOrDeleteInstanceReq,
    		Action: model.GetBatchRestartOrDeleteInstanceReqActionEnum().DELETE,
    	}
    	response, err := client.BatchRestartOrDeleteInstances(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

批量删除实例成功。

204

删除所有创建失败的RabbitMQ实例成功。

错误码

请参见错误码

变更历史
2023-08-17
批量重启或删除实例
POST
   BatchRestartOrDeleteInstances
修改
变更参数
2023-05-25
批量重启或删除实例
POST
   BatchRestartOrDeleteInstances
修改
变更参数

本文导读

功能介绍
调用方法
URI
请求参数
响应参数
请求示例
响应示例
SDK代码示例
状态码
错误码
变更历史