Updated on 2024-07-05 GMT+08:00

Creating an Instance

Function

This API is used to create an instance, and pay-per-use and yearly/monthly billing modes are supported.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

engine

Yes

String

Message engine.

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Instance name.

An instance name can contain 4 to 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

description

No

String

Description of an instance.

The description supports up to 1024 characters.

NOTE:

The backslash () and quotation mark (") are special characters for JSON messages. When using these characters in a parameter value, add the escape character () before the characters, for example, \ and ".

engine

Yes

String

Message engine. Value: reliability.

engine_version

Yes

String

Version of the message engine. The value can be 4.8.0.

storage_space

Yes

Integer

Storage space.

vpc_id

Yes

String

VPC ID.

To obtain it, log in to the VPC console and view the VPC ID on the VPC details page.

subnet_id

Yes

String

Subnet information.

To obtain it, log in to VPC console and click the target subnet on the Subnets page. You can view the network ID on the displayed page.

security_group_id

Yes

String

ID of the security group to which the instance belongs.

To obtain it, log in to the VPC console and view the security group ID on the security group details page.

available_zones

Yes

Array of strings

ID of the AZ where instance brokers reside and which has available resources. Obtain the AZ ID by referring to Listing AZ Information.

The parameter value cannot be empty or null. Check whether resources exist in the AZs.

A RocketMQ instance can be deployed in 1 AZ or at least 3 AZs. When specifying AZs for brokers, use commas (,) to separate multiple AZs.

product_id

Yes

String

RocketMQ instance specifications.

  • c6.4u8g.cluster.small: Max. 2000 topics and 2000 consumer groups per broker

  • c6.4u8g.cluster: Max. 4000 topics and 4000 consumer groups per broker

  • c6.8u16g.cluster: Max. 8000 topics and 8000 consumer groups per broker

  • c6.12u24g.cluster: Max. 12,000 topics and 12,000 consumer groups per broker

  • c6.16u32g.cluster: Max. 16,000 topics and 16,000 consumer groups per broker

ssl_enable

No

Boolean

Whether to enable SSL encryption for access.

  • true: enable

  • false: disable

storage_spec_code

Yes

String

Storage I/O specification.

  • dms.physical.storage.high.v2: high I/O disk

  • dms.physical.storage.ultra.v2: ultra-high I/O disk

enterprise_project_id

No

String

Enterprise project ID. This parameter is mandatory for an enterprise project account.

enable_acl

No

Boolean

Whether to enable access control.

ipv6_enable

No

Boolean

Whether to support IPv6.

  • true: support

  • false: do not support

enable_publicip

No

Boolean

Whether to enable public access. By default, public access is disabled.

  • true: enable

  • false: disable

publicip_id

No

String

ID of the EIP bound to the instance.

Use commas (,) to separate multiple EIP IDs.

This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true).

broker_num

Yes

Integer

Number of brokers.

bss_param

No

BssParam object

Parameter related to the yearly/monthly billing mode.

If this parameter is left blank, the billing mode is pay-per-use by default. If this parameter is not left blank, the billing mode is yearly/monthly.

Table 3 BssParam

Parameter

Mandatory

Type

Description

is_auto_renew

No

Boolean

Whether auto renewal is enabled.

Options:

  • true: Auto renewal is enabled.

  • false: Auto renewal is not enabled.

By default, auto renewal is disabled.

charging_mode

No

String

Billing mode.

This parameter specifies a payment mode.

Options:

  • prePaid: yearly/monthly billing.

  • postPaid: pay-per-use billing.

The default value is postPaid.

is_auto_pay

No

Boolean

Specifies whether the order is automatically or manually paid.

Options:

  • true: The order will be automatically paid.

  • false: The order must be manually paid.

The default payment mode is manual.

period_type

No

String

Subscription period type.

Options:

  • month

  • year:

**This parameter is valid and mandatory only when chargingMode is set to prePaid. **

period_num

No

Integer

Subscribed periods.

Options:

  • If periodType is month, the value ranges from 1 to 9.

  • If periodType is year, the value ranges from 1 to 3.

**This parameter is valid and mandatory only when chargingMode is set to prePaid. **

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

instance_id

String

Instance ID.

Example Requests

Creating a pay-per-use RocketMQ instance with the 4 vCPUs | 8 GB x 1 specifications and 600 GB storage space

POST https://{endpoint}/v2/reliability/{project_id}/instances

{
  "name" : "reliability-1751840557",
  "description" : "",
  "engine" : "reliability",
  "engine_version" : "4.8.0",
  "storage_space" : 600,
  "vpc_id" : "3db8490c-4d6d-4d8f-8d3f-047b0de4c5cf",
  "subnet_id" : "0a0f1fcb-f019-458d-b9e5-301867394d50",
  "security_group_id" : "23c5977f-ff33-4b95-a73e-08d8a0bc4e6c",
  "available_zones" : [ "9f1c5806706d4c1fb0eb72f0a9b18c77" ],
  "product_id" : "c6.4u8g.cluster",
  "enterprise_project_id" : "0",
  "ssl_enable" : false,
  "storage_spec_code" : "dms.physical.storage.ultra.v2",
  "ipv6_enable" : false,
  "enable_publicip" : false,
  "publicip_id" : "",
  "broker_num" : 1
}

Example Responses

Status code: 200

Instance created successfully.

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

SDK Sample Code

The SDK sample code is as follows.

Creating a pay-per-use RocketMQ instance with the 4 vCPUs | 8 GB x 1 specifications and 600 GB storage space

 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
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.rocketmq.v2.region.RocketMQRegion;
import com.huaweicloud.sdk.rocketmq.v2.*;
import com.huaweicloud.sdk.rocketmq.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateInstanceByEngineSolution {

    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);

        RocketMQClient client = RocketMQClient.newBuilder()
                .withCredential(auth)
                .withRegion(RocketMQRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateInstanceByEngineRequest request = new CreateInstanceByEngineRequest();
        request.withEngine(CreateInstanceByEngineRequest.EngineEnum.fromValue("{engine}"));
        CreateInstanceByEngineReq body = new CreateInstanceByEngineReq();
        List<String> listbodyAvailableZones = new ArrayList<>();
        listbodyAvailableZones.add("9f1c5806706d4c1fb0eb72f0a9b18c77");
        body.withBrokerNum(1);
        body.withPublicipId("");
        body.withEnablePublicip(false);
        body.withIpv6Enable(false);
        body.withEnterpriseProjectId("0");
        body.withStorageSpecCode(CreateInstanceByEngineReq.StorageSpecCodeEnum.fromValue("dms.physical.storage.ultra.v2"));
        body.withSslEnable(false);
        body.withProductId(CreateInstanceByEngineReq.ProductIdEnum.fromValue("c6.4u8g.cluster"));
        body.withAvailableZones(listbodyAvailableZones);
        body.withSecurityGroupId("23c5977f-ff33-4b95-a73e-08d8a0bc4e6c");
        body.withSubnetId("0a0f1fcb-f019-458d-b9e5-301867394d50");
        body.withVpcId("3db8490c-4d6d-4d8f-8d3f-047b0de4c5cf");
        body.withStorageSpace(600);
        body.withEngineVersion(CreateInstanceByEngineReq.EngineVersionEnum.fromValue("4.8.0"));
        body.withEngine(CreateInstanceByEngineReq.EngineEnum.fromValue("reliability"));
        body.withDescription("");
        body.withName("reliability-1751840557");
        request.withBody(body);
        try {
            CreateInstanceByEngineResponse response = client.createInstanceByEngine(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());
        }
    }
}

Creating a pay-per-use RocketMQ instance with the 4 vCPUs | 8 GB x 1 specifications and 600 GB storage space

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkrocketmq.v2.region.rocketmq_region import RocketMQRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkrocketmq.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 = RocketMQClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(RocketMQRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateInstanceByEngineRequest()
        request.engine = "{engine}"
        listAvailableZonesbody = [
            "9f1c5806706d4c1fb0eb72f0a9b18c77"
        ]
        request.body = CreateInstanceByEngineReq(
            broker_num=1,
            publicip_id="",
            enable_publicip=False,
            ipv6_enable=False,
            enterprise_project_id="0",
            storage_spec_code="dms.physical.storage.ultra.v2",
            ssl_enable=False,
            product_id="c6.4u8g.cluster",
            available_zones=listAvailableZonesbody,
            security_group_id="23c5977f-ff33-4b95-a73e-08d8a0bc4e6c",
            subnet_id="0a0f1fcb-f019-458d-b9e5-301867394d50",
            vpc_id="3db8490c-4d6d-4d8f-8d3f-047b0de4c5cf",
            storage_space=600,
            engine_version="4.8.0",
            engine="reliability",
            description="",
            name="reliability-1751840557"
        )
        response = client.create_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)

Creating a pay-per-use RocketMQ instance with the 4 vCPUs | 8 GB x 1 specifications and 600 GB storage space

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    rocketmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rocketmq/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rocketmq/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rocketmq/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 := rocketmq.NewRocketMQClient(
        rocketmq.RocketMQClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateInstanceByEngineRequest{}
	request.Engine = model.GetCreateInstanceByEngineRequestEngineEnum().ENGINE
	var listAvailableZonesbody = []string{
        "9f1c5806706d4c1fb0eb72f0a9b18c77",
    }
	publicipIdCreateInstanceByEngineReq:= ""
	enablePublicipCreateInstanceByEngineReq:= false
	ipv6EnableCreateInstanceByEngineReq:= false
	enterpriseProjectIdCreateInstanceByEngineReq:= "0"
	sslEnableCreateInstanceByEngineReq:= false
	descriptionCreateInstanceByEngineReq:= ""
	request.Body = &model.CreateInstanceByEngineReq{
		BrokerNum: int32(1),
		PublicipId: &publicipIdCreateInstanceByEngineReq,
		EnablePublicip: &enablePublicipCreateInstanceByEngineReq,
		Ipv6Enable: &ipv6EnableCreateInstanceByEngineReq,
		EnterpriseProjectId: &enterpriseProjectIdCreateInstanceByEngineReq,
		StorageSpecCode: model.GetCreateInstanceByEngineReqStorageSpecCodeEnum().DMS_PHYSICAL_STORAGE_ULTRA,
		SslEnable: &sslEnableCreateInstanceByEngineReq,
		ProductId: model.GetCreateInstanceByEngineReqProductIdEnum().C6_4U8G_CLUSTER,
		AvailableZones: listAvailableZonesbody,
		SecurityGroupId: "23c5977f-ff33-4b95-a73e-08d8a0bc4e6c",
		SubnetId: "0a0f1fcb-f019-458d-b9e5-301867394d50",
		VpcId: "3db8490c-4d6d-4d8f-8d3f-047b0de4c5cf",
		StorageSpace: int32(600),
		EngineVersion: model.GetCreateInstanceByEngineReqEngineVersionEnum().E_4_8_0,
		Engine: model.GetCreateInstanceByEngineReqEngineEnum().RELIABILITY,
		Description: &descriptionCreateInstanceByEngineReq,
		Name: "reliability-1751840557",
	}
	response, err := client.CreateInstanceByEngine(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Instance created successfully.

Error Codes

See Error Codes.