更新时间:2025-08-15 GMT+08:00

创建实例

功能介绍

创建实例,该接口支持创建按需和包周期计费方式的实例。

调用方法

请参见如何调用API

URI

POST /v2/{engine}/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

engine

String

参数解释

消息引擎。

约束限制

不涉及。

取值范围

rabbitmq:RabbitMQ引擎。

默认取值

不涉及。

project_id

String

参数解释

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

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

name

String

参数解释

实例名称。

约束限制

由英文字符开头,只能由英文字母、数字、中划线、下划线组成,长度为4~64的字符。

取值范围

不涉及。

默认取值

不涉及。

description

String

参数解释

实例的描述信息。

约束限制

长度不超过1024的字符串。

\与"在json报文中属于特殊字符,如果参数值中需要显示\或者"字符,请在字符前增加转义字符\,比如\\或者\"。

取值范围

不涉及。

默认取值

不涉及。

engine

String

参数解释

消息引擎。

约束限制

不涉及

取值范围

rabbitmq:RabbitMQ引擎。

默认取值

不涉及。

engine_version

String

参数解释

消息引擎的版本。

约束限制

不涉及

取值范围

  • 3.8.35

  • AMQP-0-9-1

默认取值

不涉及。

enable_acl

Boolean

参数解释

ACL访问控制

约束限制

仅AMQP版本支持此参数。

取值范围

  • true:开启ACL访问控制。

  • false:不开启ACL访问控制。

默认取值

不涉及。

storage_space

Integer

参数解释

消息存储空间,单位GB。

约束限制

不涉及

取值范围

  • 单机RabbitMQ实例的存储空间的取值范围100GB~30000GB。

  • 集群RabbitMQ实例的存储空间的取值范围为100GB节点数~30000GB节点数。

默认取值

不涉及。

access_user

String

参数解释

认证用户名。

约束限制

只能由英文字母开头且由英文字母、数字、中划线、下划线组成,长度为4~64的字符。当ssl_enable为true时,该参数必选,ssl_enable为false时,该参数无效。

取值范围

不涉及。

默认取值

不涉及。

password

String

参数解释

实例的认证密码。

约束限制

  • 输入长度为8到32位的字符串。

  • 必须包含如下四种字符中的三种组合:

    • 小写字母

    • 大写字母

    • 数字

    • 特殊字符包括(`~!@#$%^&*()-_=+|[{}]:'",<.>/?)和空格,并且不能以-开头

  • 当ssl_enable为true时,该参数必选,ssl_enable为false时,该参数无效。

取值范围

不涉及。

默认取值

不涉及。

vpc_id

String

参数解释

虚拟私有云ID。获取方法如下:参考《虚拟私有云 API参考》,调用“查询VPC列表”接口,从响应体中获取VPC ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

security_group_id

String

参数解释

指定实例所属的安全组。获取方法如下:参考《虚拟私有云 API参考》,调用“查询安全组列表”接口,从响应体中获取安全组ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

subnet_id

String

参数解释

子网信息。获取方法如下:参考《虚拟私有云 API参考》,调用“查询子网列表”接口,从响应体中获取子网ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

available_zones

Array of strings

参数解释

创建节点到指定且有资源的可用区ID。请参考查询可用区信息获取可用区ID。

约束限制

该参数不能为空数组或者数组的值为空。

创建RabbitMQ实例,节点需要部署在1个或3个及以上可用区中。如果部署在多个可用区中,以英文逗号隔开多个可用区ID。

product_id

String

参数解释

产品ID。产品ID可以从查询产品规格列表获取。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

broker_num

Integer

参数解释

代理个数。

约束限制

当产品为单机类型,代理个数只能为1;当产品为集群类型,可选3、5、7个代理个数。

取值范围

  • 1

  • 3

  • 5

  • 7

默认取值

不涉及。

maintain_begin

String

参数解释

维护时间窗开始时间。

约束限制

格式为HH:mm。

取值范围

不涉及。

默认取值

不涉及。

maintain_end

String

参数解释

维护时间窗结束时间。

约束限制

格式为HH:mm。

取值范围

不涉及。

默认取值

不涉及。

enable_publicip

Boolean

参数解释

是否开启公网访问功能。

约束限制

不涉及。

取值范围

  • true:开启

  • false:不开启

默认取值

false。

publicip_id

String

参数解释

实例绑定的弹性IP地址的ID。

约束限制

以英文逗号隔开多个弹性IP地址的ID。

如果开启了公网访问功能(即enable_publicip为true),该字段为必选。

取值范围

不涉及。

默认取值

不涉及。

ssl_enable

Boolean

参数解释

是否开启SSL加密访问。

约束限制

不涉及。

取值范围

  • true:开启SSL加密访问。

  • false:关闭SSL加密访问。

默认取值

不涉及。

storage_spec_code

String

参数解释

存储IO规格。

如何选择磁盘类型请参考磁盘类型及性能介绍

约束限制

不涉及。

取值范围

  • dms.physical.storage.high.v2:高IO云硬盘。

  • dms.physical.storage.ultra.v2:超高IO云硬盘。

  • dms.physical.storage.general:通用型SSD云硬盘。

  • dms.physical.storage.extreme:极速型SSD云硬盘。

默认取值

不涉及。

enterprise_project_id

String

参数解释

企业项目ID。

约束限制

若为企业项目账号,该参数必填。

取值范围

不涉及。

默认取值

不涉及。

tags

Array of TagEntity objects

参数解释

标签列表。

约束限制

一个RabbitMQ实例最多添加20个标签。

bss_param

BssParam object

参数解释

表示包周期计费模式的相关参数。

约束限制

不涉及。

表3 TagEntity

参数

是否必选

参数类型

描述

key

String

参数解释

标签键。

取值范围

不涉及。

value

String

参数解释

标签值。

取值范围

不涉及。

表4 BssParam

参数

是否必选

参数类型

描述

is_auto_renew

Boolean

参数解释

是否自动续订。

约束限制

不涉及。

取值范围

  • true:自动续订。

  • false:不自动续订。

默认取值

false

charging_mode

String

参数解释

计费模式。

约束限制

不涉及。

取值范围

  • prePaid:预付费,即包年包月。

  • postPaid:后付费,即按需付费。

默认取值

postPaid。

is_auto_pay

Boolean

参数解释

下单订购后,是否自动从客户的账户中支付,而不需要客户手动去进行支付。

约束限制

不涉及。

取值范围

  • true:是(自动支付)

  • false:否(需要客户手动支付)

默认取值

false

period_type

String

参数解释

订购周期类型。

约束限制

chargingMode为prePaid时生效且为必选值。

取值范围

  • month:月。

  • year:年。

默认取值

不涉及。

period_num

Integer

参数解释

订购周期数。

约束限制

chargingMode为prePaid时生效且为必选值。

取值范围

  • periodType=month(周期类型为月)时,取值为[1,9]。

  • periodType=year(周期类型为年)时,取值为[1,3]。

默认取值

不涉及。

响应参数

状态码:200

表5 响应Body参数

参数

参数类型

描述

instance_id

String

参数解释

实例ID。

取值范围

不涉及。

请求示例

  • 创建一个按需付费的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

    POST https://{endpoint}/v2/{engine}/{project_id}/instances
    
    {
      "name" : "rabbitmq-demo",
      "description" : "",
      "engine" : "RabbitMQ",
      "engine_version" : "3.8.35",
      "storage_space" : 100,
      "access_user" : "******",
      "password" : "******",
      "vpc_id" : "1e93f86e-13af-46c8-97d6-d40fa62b76c2",
      "security_group_id" : "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
      "subnet_id" : "b5fa806c-35e7-4299-b659-b39398dd4718",
      "available_zones" : [ "d573142f24894ef3bd3664de068b44b0" ],
      "product_id" : "c6.2u4g.single",
      "ssl_enable" : false,
      "enable_publicip" : false,
      "publicip_id" : "",
      "storage_spec_code" : "dms.physical.storage.high.v2"
    }
  • 创建一个包年包月的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

    POST https://{endpoint}/v2/{engine}/{project_id}/instances
    
    {
      "name" : "rabbitmq-demo",
      "description" : "",
      "engine" : "RabbitMQ",
      "engine_version" : "3.8.35",
      "storage_space" : 100,
      "access_user" : "******",
      "password" : "******",
      "vpc_id" : "1e93f86e-13af-46c8-97d6-d40fa62b76c2",
      "security_group_id" : "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
      "subnet_id" : "b5fa806c-35e7-4299-b659-b39398dd4718",
      "available_zones" : [ "d573142f24894ef3bd3664de068b44b0" ],
      "product_id" : "c6.2u4g.single",
      "ssl_enable" : false,
      "enable_publicip" : false,
      "publicip_id" : "",
      "storage_spec_code" : "dms.physical.storage.high.v2",
      "bss_param" : {
        "charging_mode" : "prePaid",
        "period_type" : "month",
        "period_num" : 1,
        "is_auto_pay" : true
      }
    }
  • 创建一个RabbitMQ实例,版本为AMQP-0-9-1,规格为amqp.b1.large.1,100GB的存储空间。

    POST https://{endpoint}/v2/{engine}/{project_id}/instances
    
    {
      "name" : "rabbitmq-aor-demo",
      "description" : "",
      "engine" : "RabbitMQ",
      "engine_version" : "AMQP-0-9-1",
      "storage_space" : 100,
      "vpc_id" : "05590544-f553-4158-be38-c791589ad303",
      "security_group_id" : "030f635d-b407-4ffb-b530-6b4eaf8edc03",
      "subnet_id" : "89c1cb26-787b-4d66-a6e4-1bd887f19183",
      "available_zones" : [ "9f1c5806706d4c1fb0eb72f0a9b18c77" ],
      "product_id" : "amqp.b1.large.1",
      "broker_num" : 1,
      "ssl_enable" : false,
      "enable_publicip" : false,
      "storage_spec_code" : "dms.physical.storage.high.v2",
      "enable_acl" : true,
      "enterprise_project_id" : 0
    }

响应示例

状态码:200

创建实例成功。

{
  "instance_id" : "8959ab1c-7n1a-yyb1-a05t-93dfc361b32d"
}

SDK代码示例

SDK代码示例如下。

  • 创建一个按需付费的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    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 CreatePostPaidInstanceByEngineSolution {
    
        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();
            CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest();
            request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}"));
            CreateInstanceReq body = new CreateInstanceReq();
            List<String> listbodyAvailableZones = new ArrayList<>();
            listbodyAvailableZones.add("d573142f24894ef3bd3664de068b44b0");
            body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2"));
            body.withSslEnable(false);
            body.withPublicipId("");
            body.withEnablePublicip(false);
            body.withProductId("c6.2u4g.single");
            body.withAvailableZones(listbodyAvailableZones);
            body.withSubnetId("b5fa806c-35e7-4299-b659-b39398dd4718");
            body.withSecurityGroupId("0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8");
            body.withVpcId("1e93f86e-13af-46c8-97d6-d40fa62b76c2");
            body.withPassword("******");
            body.withAccessUser("******");
            body.withStorageSpace(100);
            body.withEngineVersion("3.8.35");
            body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ"));
            body.withDescription("");
            body.withName("rabbitmq-demo");
            request.withBody(body);
            try {
                CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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());
            }
        }
    }
    
  • 创建一个包年包月的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    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 CreatePostPaidInstanceByEngineSolution {
    
        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();
            CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest();
            request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}"));
            CreateInstanceReq body = new CreateInstanceReq();
            BssParam bssParambody = new BssParam();
            bssParambody.withChargingMode(BssParam.ChargingModeEnum.fromValue("prePaid"))
                .withIsAutoPay(true)
                .withPeriodType(BssParam.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(1);
            List<String> listbodyAvailableZones = new ArrayList<>();
            listbodyAvailableZones.add("d573142f24894ef3bd3664de068b44b0");
            body.withBssParam(bssParambody);
            body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2"));
            body.withSslEnable(false);
            body.withPublicipId("");
            body.withEnablePublicip(false);
            body.withProductId("c6.2u4g.single");
            body.withAvailableZones(listbodyAvailableZones);
            body.withSubnetId("b5fa806c-35e7-4299-b659-b39398dd4718");
            body.withSecurityGroupId("0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8");
            body.withVpcId("1e93f86e-13af-46c8-97d6-d40fa62b76c2");
            body.withPassword("******");
            body.withAccessUser("******");
            body.withStorageSpace(100);
            body.withEngineVersion("3.8.35");
            body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ"));
            body.withDescription("");
            body.withName("rabbitmq-demo");
            request.withBody(body);
            try {
                CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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());
            }
        }
    }
    
  • 创建一个RabbitMQ实例,版本为AMQP-0-9-1,规格为amqp.b1.large.1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    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 CreatePostPaidInstanceByEngineSolution {
    
        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();
            CreatePostPaidInstanceByEngineRequest request = new CreatePostPaidInstanceByEngineRequest();
            request.withEngine(CreatePostPaidInstanceByEngineRequest.EngineEnum.fromValue("{engine}"));
            CreateInstanceReq body = new CreateInstanceReq();
            List<String> listbodyAvailableZones = new ArrayList<>();
            listbodyAvailableZones.add("9f1c5806706d4c1fb0eb72f0a9b18c77");
            body.withEnterpriseProjectId("0");
            body.withStorageSpecCode(CreateInstanceReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.high.v2"));
            body.withSslEnable(false);
            body.withEnablePublicip(false);
            body.withBrokerNum(CreateInstanceReq.BrokerNumEnum.NUMBER_1);
            body.withProductId("amqp.b1.large.1");
            body.withAvailableZones(listbodyAvailableZones);
            body.withSubnetId("89c1cb26-787b-4d66-a6e4-1bd887f19183");
            body.withSecurityGroupId("030f635d-b407-4ffb-b530-6b4eaf8edc03");
            body.withVpcId("05590544-f553-4158-be38-c791589ad303");
            body.withStorageSpace(100);
            body.withEnableAcl(true);
            body.withEngineVersion("AMQP-0-9-1");
            body.withEngine(CreateInstanceReq.EngineEnum.fromValue("RabbitMQ"));
            body.withDescription("");
            body.withName("rabbitmq-aor-demo");
            request.withBody(body);
            try {
                CreatePostPaidInstanceByEngineResponse response = client.createPostPaidInstanceByEngine(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());
            }
        }
    }
    
  • 创建一个按需付费的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    # 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 = CreatePostPaidInstanceByEngineRequest()
            request.engine = "{engine}"
            listAvailableZonesbody = [
                "d573142f24894ef3bd3664de068b44b0"
            ]
            request.body = CreateInstanceReq(
                storage_spec_code="dms.physical.storage.high.v2",
                ssl_enable=False,
                publicip_id="",
                enable_publicip=False,
                product_id="c6.2u4g.single",
                available_zones=listAvailableZonesbody,
                subnet_id="b5fa806c-35e7-4299-b659-b39398dd4718",
                security_group_id="0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
                vpc_id="1e93f86e-13af-46c8-97d6-d40fa62b76c2",
                password="******",
                access_user="******",
                storage_space=100,
                engine_version="3.8.35",
                engine="RabbitMQ",
                description="",
                name="rabbitmq-demo"
            )
            response = client.create_post_paid_instance_by_engine(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个包年包月的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    57
    58
    59
    60
    # 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 = CreatePostPaidInstanceByEngineRequest()
            request.engine = "{engine}"
            bssParambody = BssParam(
                charging_mode="prePaid",
                is_auto_pay=True,
                period_type="month",
                period_num=1
            )
            listAvailableZonesbody = [
                "d573142f24894ef3bd3664de068b44b0"
            ]
            request.body = CreateInstanceReq(
                bss_param=bssParambody,
                storage_spec_code="dms.physical.storage.high.v2",
                ssl_enable=False,
                publicip_id="",
                enable_publicip=False,
                product_id="c6.2u4g.single",
                available_zones=listAvailableZonesbody,
                subnet_id="b5fa806c-35e7-4299-b659-b39398dd4718",
                security_group_id="0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
                vpc_id="1e93f86e-13af-46c8-97d6-d40fa62b76c2",
                password="******",
                access_user="******",
                storage_space=100,
                engine_version="3.8.35",
                engine="RabbitMQ",
                description="",
                name="rabbitmq-demo"
            )
            response = client.create_post_paid_instance_by_engine(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个RabbitMQ实例,版本为AMQP-0-9-1,规格为amqp.b1.large.1,100GB的存储空间。

     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
    # 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 = CreatePostPaidInstanceByEngineRequest()
            request.engine = "{engine}"
            listAvailableZonesbody = [
                "9f1c5806706d4c1fb0eb72f0a9b18c77"
            ]
            request.body = CreateInstanceReq(
                enterprise_project_id="0",
                storage_spec_code="dms.physical.storage.high.v2",
                ssl_enable=False,
                enable_publicip=False,
                broker_num=1,
                product_id="amqp.b1.large.1",
                available_zones=listAvailableZonesbody,
                subnet_id="89c1cb26-787b-4d66-a6e4-1bd887f19183",
                security_group_id="030f635d-b407-4ffb-b530-6b4eaf8edc03",
                vpc_id="05590544-f553-4158-be38-c791589ad303",
                storage_space=100,
                enable_acl=True,
                engine_version="AMQP-0-9-1",
                engine="RabbitMQ",
                description="",
                name="rabbitmq-aor-demo"
            )
            response = client.create_post_paid_instance_by_engine(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建一个按需付费的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    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.CreatePostPaidInstanceByEngineRequest{}
    	request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE
    	var listAvailableZonesbody = []string{
            "d573142f24894ef3bd3664de068b44b0",
        }
    	sslEnableCreateInstanceReq:= false
    	publicipIdCreateInstanceReq:= ""
    	enablePublicipCreateInstanceReq:= false
    	passwordCreateInstanceReq:= "******"
    	accessUserCreateInstanceReq:= "******"
    	descriptionCreateInstanceReq:= ""
    	request.Body = &model.CreateInstanceReq{
    		StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH,
    		SslEnable: &sslEnableCreateInstanceReq,
    		PublicipId: &publicipIdCreateInstanceReq,
    		EnablePublicip: &enablePublicipCreateInstanceReq,
    		ProductId: "c6.2u4g.single",
    		AvailableZones: listAvailableZonesbody,
    		SubnetId: "b5fa806c-35e7-4299-b659-b39398dd4718",
    		SecurityGroupId: "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
    		VpcId: "1e93f86e-13af-46c8-97d6-d40fa62b76c2",
    		Password: &passwordCreateInstanceReq,
    		AccessUser: &accessUserCreateInstanceReq,
    		StorageSpace: int32(100),
    		EngineVersion: "3.8.35",
    		Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ,
    		Description: &descriptionCreateInstanceReq,
    		Name: "rabbitmq-demo",
    	}
    	response, err := client.CreatePostPaidInstanceByEngine(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个包年包月的RabbitMQ实例,版本为3.8.35,规格为2U4G*1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    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.CreatePostPaidInstanceByEngineRequest{}
    	request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE
    	chargingModeBssParam:= model.GetBssParamChargingModeEnum().PRE_PAID
    	isAutoPayBssParam:= true
    	periodTypeBssParam:= model.GetBssParamPeriodTypeEnum().MONTH
    	periodNumBssParam:= int32(1)
    	bssParambody := &model.BssParam{
    		ChargingMode: &chargingModeBssParam,
    		IsAutoPay: &isAutoPayBssParam,
    		PeriodType: &periodTypeBssParam,
    		PeriodNum: &periodNumBssParam,
    	}
    	var listAvailableZonesbody = []string{
            "d573142f24894ef3bd3664de068b44b0",
        }
    	sslEnableCreateInstanceReq:= false
    	publicipIdCreateInstanceReq:= ""
    	enablePublicipCreateInstanceReq:= false
    	passwordCreateInstanceReq:= "******"
    	accessUserCreateInstanceReq:= "******"
    	descriptionCreateInstanceReq:= ""
    	request.Body = &model.CreateInstanceReq{
    		BssParam: bssParambody,
    		StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH,
    		SslEnable: &sslEnableCreateInstanceReq,
    		PublicipId: &publicipIdCreateInstanceReq,
    		EnablePublicip: &enablePublicipCreateInstanceReq,
    		ProductId: "c6.2u4g.single",
    		AvailableZones: listAvailableZonesbody,
    		SubnetId: "b5fa806c-35e7-4299-b659-b39398dd4718",
    		SecurityGroupId: "0aaa0033-bf7f-4c41-a6c2-18cd04cad2c8",
    		VpcId: "1e93f86e-13af-46c8-97d6-d40fa62b76c2",
    		Password: &passwordCreateInstanceReq,
    		AccessUser: &accessUserCreateInstanceReq,
    		StorageSpace: int32(100),
    		EngineVersion: "3.8.35",
    		Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ,
    		Description: &descriptionCreateInstanceReq,
    		Name: "rabbitmq-demo",
    	}
    	response, err := client.CreatePostPaidInstanceByEngine(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建一个RabbitMQ实例,版本为AMQP-0-9-1,规格为amqp.b1.large.1,100GB的存储空间。

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    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.CreatePostPaidInstanceByEngineRequest{}
    	request.Engine = model.GetCreatePostPaidInstanceByEngineRequestEngineEnum().ENGINE
    	var listAvailableZonesbody = []string{
            "9f1c5806706d4c1fb0eb72f0a9b18c77",
        }
    	enterpriseProjectIdCreateInstanceReq:= "0"
    	sslEnableCreateInstanceReq:= false
    	enablePublicipCreateInstanceReq:= false
    	brokerNumCreateInstanceReq:= model.GetCreateInstanceReqBrokerNumEnum().E_1
    	enableAclCreateInstanceReq:= true
    	descriptionCreateInstanceReq:= ""
    	request.Body = &model.CreateInstanceReq{
    		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceReq,
    		StorageSpecCode: model.GetCreateInstanceReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_HIGH,
    		SslEnable: &sslEnableCreateInstanceReq,
    		EnablePublicip: &enablePublicipCreateInstanceReq,
    		BrokerNum: &brokerNumCreateInstanceReq,
    		ProductId: "amqp.b1.large.1",
    		AvailableZones: listAvailableZonesbody,
    		SubnetId: "89c1cb26-787b-4d66-a6e4-1bd887f19183",
    		SecurityGroupId: "030f635d-b407-4ffb-b530-6b4eaf8edc03",
    		VpcId: "05590544-f553-4158-be38-c791589ad303",
    		StorageSpace: int32(100),
    		EnableAcl: &enableAclCreateInstanceReq,
    		EngineVersion: "AMQP-0-9-1",
    		Engine: model.GetCreateInstanceReqEngineEnum().RABBIT_MQ,
    		Description: &descriptionCreateInstanceReq,
    		Name: "rabbitmq-aor-demo",
    	}
    	response, err := client.CreatePostPaidInstanceByEngine(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

创建实例成功。

错误码

请参见错误码