Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
DataArts Fabric
IoT
IoT Device Access
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
Huawei Cloud Astro Canvas
Huawei Cloud Astro Zero
CodeArts Governance
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance (CCI)
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Cloud Transformation
Well-Architected Framework
Cloud Adoption Framework
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Metadata Migration Task

Function

This API is used to create a metadata migration task.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/instances/{instance_id}/metadata

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

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

instance_id

Yes

String

Instance ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

overwrite

Yes

String

true: Configurations in the metadata file with the same name as the uploaded file will be overwritten. false: An error is reported when a topic or group already exists.

name

Yes

String

Migration task name. For details about the naming rules, see the API for creating an instance.

type

Yes

String

Migration task type. The value can be rocketmq or rabbitToRocket.

Request Parameters

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

topicConfigTable

No

Map<String,MigrationRocketMqTopicConfig>

RocketMQ instance topic metadata. The topic name is the key and the topic configuration is the value. This parameter is mandatory for rocketmq migration tasks (from self-built RocketMQ instances to DMS for RocketMQ).

subscriptionGroupTable

No

Map<String,MigrationRocketMqSubscriptionGroup>

RocketMQ consumer group metadata. The consumer group name is the key and the configuration is the value. This parameter is mandatory for rocketmq migration tasks (from self-built RocketMQ instances to DMS for RocketMQ).

vhosts

No

Array of MigrationRabbitVhostMetadata objects

RabbitMQ virtual host metadata list. This parameter is mandatory for rabbitToRocket migration tasks (from self-built RabbitMQ instances to DMS for RocketMQ).

queues

No

Array of MigrationRabbitQueueMetadata objects

RabbitMQ queue metadata list. This parameter is mandatory for rabbitToRocket migration tasks (from self-built RabbitMQ instances to DMS for RocketMQ).

exchanges

No

Array of MigrationRabbitExchangeMetadata objects

RabbitMQ exchange metadata list. This parameter is mandatory for rabbitToRocket migration tasks (from self-built RabbitMQ instances to DMS for RocketMQ).

bindings

No

Array of MigrationRabbitBindingMetadata objects

RabbitMQ binding metadata list. This parameter is mandatory for rabbitToRocket migration tasks (from self-built RabbitMQ instances to DMS for RocketMQ).

Table 4 MigrationRocketMqTopicConfig

Parameter

Mandatory

Type

Description

topicName

No

String

Topic name.

topic_name

No

String

Topic name.

order

No

Boolean

Indicates whether a message is an ordered message.

perm

No

Integer

Topic permission.

readQueueNums

No

Integer

Number of read queues.

read_queue_nums

No

Integer

Number of read queues.

writeQueueNums

No

Integer

Number of write queues.

write_queue_nums

No

Integer

Number of write queues.

topicFilterType

No

String

Topic filtering type.

  • SINGLE_TAG: single tag

  • MULTI_TAG: multiple tags

topic_filter_type

No

String

Topic filtering type.

  • SINGLE_TAG: single tag

  • MULTI_TAG: multiple tags

topicSysFlag

No

Integer

Topic system flag.

topic_sys_flag

No

Integer

Topic system flag.

Table 5 MigrationRocketMqSubscriptionGroup

Parameter

Mandatory

Type

Description

groupName

No

String

Consumer group name.

group_name

No

String

Consumer group name.

consumeBroadcastEnable

No

Boolean

Indicates whether to enable broadcast.

consume_broadcast_enable

No

Boolean

Indicates whether to enable broadcast.

consumeEnable

No

Boolean

Indicates whether to enable consumption.

consume_enable

No

Boolean

Indicates whether to enable consumption.

consumeFromMinEnable

No

Boolean

Indicates whether to enable consumption from the earliest offset.

consume_from_min_enable

No

Boolean

Indicates whether to enable consumption from the earliest offset.

notifyConsumerIdsChangedEnable

No

Boolean

Indicates whether to notify consumer ID changes.

notify_consumer_ids_changed_enable

No

Boolean

Indicates whether to notify consumer ID changes.

retryMaxTimes

No

Integer

Maximum number of consumption retries.

retry_max_times

No

Integer

Maximum number of consumption retries.

retryQueueNums

No

Integer

Number of retry queues.

retry_queue_nums

No

Integer

Number of retry queues.

whichBrokerWhenConsumeSlow

No

Long

ID of the broker selected for slow consumption.

which_broker_when_consume_slow

No

Long

ID of the broker selected for slow consumption.

Table 6 MigrationRabbitVhostMetadata

Parameter

Mandatory

Type

Description

name

No

String

Virtual host name.

Table 7 MigrationRabbitQueueMetadata

Parameter

Mandatory

Type

Description

vhost

No

String

Virtual host name.

name

No

String

Queue name.

durable

No

Boolean

Indicates whether to enable data persistence.

Table 8 MigrationRabbitExchangeMetadata

Parameter

Mandatory

Type

Description

vhost

No

String

Virtual host name.

name

No

String

Switch name.

type

No

String

Exchange type.

durable

No

Boolean

Indicates whether to enable data persistence.

Table 9 MigrationRabbitBindingMetadata

Parameter

Mandatory

Type

Description

vhost

No

String

Virtual host name.

source

No

String

Message source.

destination

No

String

Message target.

destination_type

No

String

Message target type.

routing_key

No

String

Routing key.

Response Parameters

Status code: 200

Table 10 Response body parameters

Parameter

Type

Description

task_id

String

Task ID.

Example Requests

  • Creating a metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

    POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/metadata?overwrite=true&name=task-123&type=rocketmq
    
    {
      "topicConfigTable" : {
        "topic-test1" : {
          "order" : false,
          "perm" : 6,
          "readQueueNums" : 3,
          "topicFilterType" : "SINGLE_TAG",
          "topicName" : "topic-test1",
          "topicSysFlag" : 0,
          "writeQueueNums" : 3
        }
      },
      "subscriptionGroupTable" : {
        "group-test1" : {
          "consumeBroadcastEnable" : true,
          "consumeEnable" : true,
          "consumeFromMinEnable" : true,
          "groupName" : "group-test1",
          "notifyConsumerIdsChangedEnable" : true,
          "retryMaxTimes" : 2,
          "retryQueueNums" : 1,
          "whichBrokerWhenConsumeSlow" : 1
        }
      }
    }
  • Creating a metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

    POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/metadata?overwrite=true&name=task-123&type=rabbitToRocket
    
    {
      "vhosts" : [ {
        "name" : "DeleteVhost123"
      } ],
      "queues" : [ {
        "name" : "test-001",
        "vhost" : "/",
        "durable" : false
      } ],
      "exchanges" : [ {
        "name" : "direct",
        "vhost" : "/",
        "type" : "topic",
        "durable" : false
      } ],
      "bindings" : [ {
        "source" : "direct",
        "vhost" : "/",
        "destination" : "test-001",
        "destination_type" : "queue",
        "routing_key" : "test-001"
      } ]
    }

Example Responses

Status code: 200

Successful

{
  "task_id" : "6cf4dcd3-8471-4139-8b5b-8a3a71f704c7"
}

SDK Sample Code

The SDK sample code is as follows.

  • Creating a metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    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.Map;
    import java.util.HashMap;
    
    public class CreateRocketMqMigrationTaskSolution {
    
        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();
            CreateRocketMqMigrationTaskRequest request = new CreateRocketMqMigrationTaskRequest();
            request.withInstanceId("{instance_id}");
            CreateRocketMqMigrationTaskReq body = new CreateRocketMqMigrationTaskReq();
            MigrationRocketMqSubscriptionGroup subscriptionGroupTableSubscriptionGroupTable = new MigrationRocketMqSubscriptionGroup();
            subscriptionGroupTableSubscriptionGroupTable.withGroupName("group-test1")
                .withConsumeBroadcastEnable(true)
                .withConsumeEnable(true)
                .withConsumeFromMinEnable(true)
                .withNotifyConsumerIdsChangedEnable(true)
                .withRetryMaxTimes(2)
                .withRetryQueueNums(1)
                .withWhichBrokerWhenConsumeSlow(1L);
            Map<String, MigrationRocketMqSubscriptionGroup> listbodySubscriptionGroupTable = new HashMap<>();
            listbodySubscriptionGroupTable.put("group-test1", subscriptionGroupTableSubscriptionGroupTable);
            MigrationRocketMqTopicConfig topicConfigTableTopicConfigTable = new MigrationRocketMqTopicConfig();
            topicConfigTableTopicConfigTable.withTopicName("topic-test1")
                .withOrder(false)
                .withPerm(6)
                .withReadQueueNums(3)
                .withWriteQueueNums(3)
                .withTopicFilterType("SINGLE_TAG")
                .withTopicSysFlag(0);
            Map<String, MigrationRocketMqTopicConfig> listbodyTopicConfigTable = new HashMap<>();
            listbodyTopicConfigTable.put("topic-test1", topicConfigTableTopicConfigTable);
            body.withSubscriptionGroupTable(listbodySubscriptionGroupTable);
            body.withTopicConfigTable(listbodyTopicConfigTable);
            request.withBody(body);
            try {
                CreateRocketMqMigrationTaskResponse response = client.createRocketMqMigrationTask(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 metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    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 CreateRocketMqMigrationTaskSolution {
    
        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();
            CreateRocketMqMigrationTaskRequest request = new CreateRocketMqMigrationTaskRequest();
            request.withInstanceId("{instance_id}");
            CreateRocketMqMigrationTaskReq body = new CreateRocketMqMigrationTaskReq();
            List<MigrationRabbitBindingMetadata> listbodyBindings = new ArrayList<>();
            listbodyBindings.add(
                new MigrationRabbitBindingMetadata()
                    .withVhost("/")
                    .withSource("direct")
                    .withDestination("test-001")
                    .withDestinationType("queue")
                    .withRoutingKey("test-001")
            );
            List<MigrationRabbitExchangeMetadata> listbodyExchanges = new ArrayList<>();
            listbodyExchanges.add(
                new MigrationRabbitExchangeMetadata()
                    .withVhost("/")
                    .withName("direct")
                    .withType("topic")
                    .withDurable(false)
            );
            List<MigrationRabbitQueueMetadata> listbodyQueues = new ArrayList<>();
            listbodyQueues.add(
                new MigrationRabbitQueueMetadata()
                    .withVhost("/")
                    .withName("test-001")
                    .withDurable(false)
            );
            List<MigrationRabbitVhostMetadata> listbodyVhosts = new ArrayList<>();
            listbodyVhosts.add(
                new MigrationRabbitVhostMetadata()
                    .withName("DeleteVhost123")
            );
            body.withBindings(listbodyBindings);
            body.withExchanges(listbodyExchanges);
            body.withQueues(listbodyQueues);
            body.withVhosts(listbodyVhosts);
            request.withBody(body);
            try {
                CreateRocketMqMigrationTaskResponse response = client.createRocketMqMigrationTask(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 metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    # 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 = CreateRocketMqMigrationTaskRequest()
            request.instance_id = "{instance_id}"
            subscriptionGroupTableSubscriptionGroupTable = MigrationRocketMqSubscriptionGroup(
                group_name="group-test1",
                consume_broadcast_enable=True,
                consume_enable=True,
                consume_from_min_enable=True,
                notify_consumer_ids_changed_enable=True,
                retry_max_times=2,
                retry_queue_nums=1,
                which_broker_when_consume_slow=1
            )
            listSubscriptionGroupTablebody = {
                "group-test1": subscriptionGroupTableSubscriptionGroupTable
            }
            topicConfigTableTopicConfigTable = MigrationRocketMqTopicConfig(
                topic_name="topic-test1",
                order=False,
                perm=6,
                read_queue_nums=3,
                write_queue_nums=3,
                topic_filter_type="SINGLE_TAG",
                topic_sys_flag=0
            )
            listTopicConfigTablebody = {
                "topic-test1": topicConfigTableTopicConfigTable
            }
            request.body = CreateRocketMqMigrationTaskReq(
                subscription_group_table=listSubscriptionGroupTablebody,
                topic_config_table=listTopicConfigTablebody
            )
            response = client.create_rocket_mq_migration_task(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 metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    # 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 = CreateRocketMqMigrationTaskRequest()
            request.instance_id = "{instance_id}"
            listBindingsbody = [
                MigrationRabbitBindingMetadata(
                    vhost="/",
                    source="direct",
                    destination="test-001",
                    destination_type="queue",
                    routing_key="test-001"
                )
            ]
            listExchangesbody = [
                MigrationRabbitExchangeMetadata(
                    vhost="/",
                    name="direct",
                    type="topic",
                    durable=False
                )
            ]
            listQueuesbody = [
                MigrationRabbitQueueMetadata(
                    vhost="/",
                    name="test-001",
                    durable=False
                )
            ]
            listVhostsbody = [
                MigrationRabbitVhostMetadata(
                    name="DeleteVhost123"
                )
            ]
            request.body = CreateRocketMqMigrationTaskReq(
                bindings=listBindingsbody,
                exchanges=listExchangesbody,
                queues=listQueuesbody,
                vhosts=listVhostsbody
            )
            response = client.create_rocket_mq_migration_task(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 metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    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.CreateRocketMqMigrationTaskRequest{}
    	request.InstanceId = "{instance_id}"
    	groupNameSubscriptionGroupTable:= "group-test1"
    	consumeBroadcastEnableSubscriptionGroupTable:= true
    	consumeEnableSubscriptionGroupTable:= true
    	consumeFromMinEnableSubscriptionGroupTable:= true
    	notifyConsumerIdsChangedEnableSubscriptionGroupTable:= true
    	retryMaxTimesSubscriptionGroupTable:= int32(2)
    	retryQueueNumsSubscriptionGroupTable:= int32(1)
    	whichBrokerWhenConsumeSlowSubscriptionGroupTable:= int64(1)
    	subscriptionGroupTableSubscriptionGroupTable := model.MigrationRocketMqSubscriptionGroup{
    		GroupName: &groupNameSubscriptionGroupTable,
    		ConsumeBroadcastEnable: &consumeBroadcastEnableSubscriptionGroupTable,
    		ConsumeEnable: &consumeEnableSubscriptionGroupTable,
    		ConsumeFromMinEnable: &consumeFromMinEnableSubscriptionGroupTable,
    		NotifyConsumerIdsChangedEnable: &notifyConsumerIdsChangedEnableSubscriptionGroupTable,
    		RetryMaxTimes: &retryMaxTimesSubscriptionGroupTable,
    		RetryQueueNums: &retryQueueNumsSubscriptionGroupTable,
    		WhichBrokerWhenConsumeSlow: &whichBrokerWhenConsumeSlowSubscriptionGroupTable,
    	}
    	var listSubscriptionGroupTablebody = map[string](model.MigrationRocketMqSubscriptionGroup){
            "group-test1": subscriptionGroupTableSubscriptionGroupTable,
        }
    	topicNameTopicConfigTable:= "topic-test1"
    	orderTopicConfigTable:= false
    	permTopicConfigTable:= int32(6)
    	readQueueNumsTopicConfigTable:= int32(3)
    	writeQueueNumsTopicConfigTable:= int32(3)
    	topicFilterTypeTopicConfigTable:= "SINGLE_TAG"
    	topicSysFlagTopicConfigTable:= int32(0)
    	topicConfigTableTopicConfigTable := model.MigrationRocketMqTopicConfig{
    		TopicName: &topicNameTopicConfigTable,
    		Order: &orderTopicConfigTable,
    		Perm: &permTopicConfigTable,
    		ReadQueueNums: &readQueueNumsTopicConfigTable,
    		WriteQueueNums: &writeQueueNumsTopicConfigTable,
    		TopicFilterType: &topicFilterTypeTopicConfigTable,
    		TopicSysFlag: &topicSysFlagTopicConfigTable,
    	}
    	var listTopicConfigTablebody = map[string](model.MigrationRocketMqTopicConfig){
            "topic-test1": topicConfigTableTopicConfigTable,
        }
    	request.Body = &model.CreateRocketMqMigrationTaskReq{
    		SubscriptionGroupTable: listSubscriptionGroupTablebody,
    		TopicConfigTable: listTopicConfigTablebody,
    	}
    	response, err := client.CreateRocketMqMigrationTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Creating a metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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.CreateRocketMqMigrationTaskRequest{}
    	request.InstanceId = "{instance_id}"
    	vhostBindings:= "/"
    	sourceBindings:= "direct"
    	destinationBindings:= "test-001"
    	destinationTypeBindings:= "queue"
    	routingKeyBindings:= "test-001"
    	var listBindingsbody = []model.MigrationRabbitBindingMetadata{
            {
                Vhost: &vhostBindings,
                Source: &sourceBindings,
                Destination: &destinationBindings,
                DestinationType: &destinationTypeBindings,
                RoutingKey: &routingKeyBindings,
            },
        }
    	vhostExchanges:= "/"
    	nameExchanges:= "direct"
    	typeExchanges:= "topic"
    	durableExchanges:= false
    	var listExchangesbody = []model.MigrationRabbitExchangeMetadata{
            {
                Vhost: &vhostExchanges,
                Name: &nameExchanges,
                Type: &typeExchanges,
                Durable: &durableExchanges,
            },
        }
    	vhostQueues:= "/"
    	nameQueues:= "test-001"
    	durableQueues:= false
    	var listQueuesbody = []model.MigrationRabbitQueueMetadata{
            {
                Vhost: &vhostQueues,
                Name: &nameQueues,
                Durable: &durableQueues,
            },
        }
    	nameVhosts:= "DeleteVhost123"
    	var listVhostsbody = []model.MigrationRabbitVhostMetadata{
            {
                Name: &nameVhosts,
            },
        }
    	request.Body = &model.CreateRocketMqMigrationTaskReq{
    		Bindings: &listBindingsbody,
    		Exchanges: &listExchangesbody,
    		Queues: &listQueuesbody,
    		Vhosts: &listVhostsbody,
    	}
    	response, err := client.CreateRocketMqMigrationTask(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.

  • Creating a metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    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.Map;
    import java.util.HashMap;
    
    public class CreateRocketMqMigrationTaskSolution {
    
        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();
            CreateRocketMqMigrationTaskRequest request = new CreateRocketMqMigrationTaskRequest();
            request.withInstanceId("{instance_id}");
            CreateRocketMqMigrationTaskReq body = new CreateRocketMqMigrationTaskReq();
            MigrationRocketMqSubscriptionGroup subscriptionGroupTableSubscriptionGroupTable = new MigrationRocketMqSubscriptionGroup();
            subscriptionGroupTableSubscriptionGroupTable.withGroupName("group-test1")
                .withConsumeBroadcastEnable(true)
                .withConsumeEnable(true)
                .withConsumeFromMinEnable(true)
                .withNotifyConsumerIdsChangedEnable(true)
                .withRetryMaxTimes(2)
                .withRetryQueueNums(1)
                .withWhichBrokerWhenConsumeSlow(1L);
            Map<String, MigrationRocketMqSubscriptionGroup> listbodySubscriptionGroupTable = new HashMap<>();
            listbodySubscriptionGroupTable.put("group-test1", subscriptionGroupTableSubscriptionGroupTable);
            MigrationRocketMqTopicConfig topicConfigTableTopicConfigTable = new MigrationRocketMqTopicConfig();
            topicConfigTableTopicConfigTable.withTopicName("topic-test1")
                .withOrder(false)
                .withPerm(6)
                .withReadQueueNums(3)
                .withWriteQueueNums(3)
                .withTopicFilterType("SINGLE_TAG")
                .withTopicSysFlag(0);
            Map<String, MigrationRocketMqTopicConfig> listbodyTopicConfigTable = new HashMap<>();
            listbodyTopicConfigTable.put("topic-test1", topicConfigTableTopicConfigTable);
            body.withSubscriptionGroupTable(listbodySubscriptionGroupTable);
            body.withTopicConfigTable(listbodyTopicConfigTable);
            request.withBody(body);
            try {
                CreateRocketMqMigrationTaskResponse response = client.createRocketMqMigrationTask(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 metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    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 CreateRocketMqMigrationTaskSolution {
    
        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();
            CreateRocketMqMigrationTaskRequest request = new CreateRocketMqMigrationTaskRequest();
            request.withInstanceId("{instance_id}");
            CreateRocketMqMigrationTaskReq body = new CreateRocketMqMigrationTaskReq();
            List<MigrationRabbitBindingMetadata> listbodyBindings = new ArrayList<>();
            listbodyBindings.add(
                new MigrationRabbitBindingMetadata()
                    .withVhost("/")
                    .withSource("direct")
                    .withDestination("test-001")
                    .withDestinationType("queue")
                    .withRoutingKey("test-001")
            );
            List<MigrationRabbitExchangeMetadata> listbodyExchanges = new ArrayList<>();
            listbodyExchanges.add(
                new MigrationRabbitExchangeMetadata()
                    .withVhost("/")
                    .withName("direct")
                    .withType("topic")
                    .withDurable(false)
            );
            List<MigrationRabbitQueueMetadata> listbodyQueues = new ArrayList<>();
            listbodyQueues.add(
                new MigrationRabbitQueueMetadata()
                    .withVhost("/")
                    .withName("test-001")
                    .withDurable(false)
            );
            List<MigrationRabbitVhostMetadata> listbodyVhosts = new ArrayList<>();
            listbodyVhosts.add(
                new MigrationRabbitVhostMetadata()
                    .withName("DeleteVhost123")
            );
            body.withBindings(listbodyBindings);
            body.withExchanges(listbodyExchanges);
            body.withQueues(listbodyQueues);
            body.withVhosts(listbodyVhosts);
            request.withBody(body);
            try {
                CreateRocketMqMigrationTaskResponse response = client.createRocketMqMigrationTask(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 metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    # 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 = CreateRocketMqMigrationTaskRequest()
            request.instance_id = "{instance_id}"
            subscriptionGroupTableSubscriptionGroupTable = MigrationRocketMqSubscriptionGroup(
                group_name="group-test1",
                consume_broadcast_enable=True,
                consume_enable=True,
                consume_from_min_enable=True,
                notify_consumer_ids_changed_enable=True,
                retry_max_times=2,
                retry_queue_nums=1,
                which_broker_when_consume_slow=1
            )
            listSubscriptionGroupTablebody = {
                "group-test1": subscriptionGroupTableSubscriptionGroupTable
            }
            topicConfigTableTopicConfigTable = MigrationRocketMqTopicConfig(
                topic_name="topic-test1",
                order=False,
                perm=6,
                read_queue_nums=3,
                write_queue_nums=3,
                topic_filter_type="SINGLE_TAG",
                topic_sys_flag=0
            )
            listTopicConfigTablebody = {
                "topic-test1": topicConfigTableTopicConfigTable
            }
            request.body = CreateRocketMqMigrationTaskReq(
                subscription_group_table=listSubscriptionGroupTablebody,
                topic_config_table=listTopicConfigTablebody
            )
            response = client.create_rocket_mq_migration_task(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 metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    # 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 = CreateRocketMqMigrationTaskRequest()
            request.instance_id = "{instance_id}"
            listBindingsbody = [
                MigrationRabbitBindingMetadata(
                    vhost="/",
                    source="direct",
                    destination="test-001",
                    destination_type="queue",
                    routing_key="test-001"
                )
            ]
            listExchangesbody = [
                MigrationRabbitExchangeMetadata(
                    vhost="/",
                    name="direct",
                    type="topic",
                    durable=False
                )
            ]
            listQueuesbody = [
                MigrationRabbitQueueMetadata(
                    vhost="/",
                    name="test-001",
                    durable=False
                )
            ]
            listVhostsbody = [
                MigrationRabbitVhostMetadata(
                    name="DeleteVhost123"
                )
            ]
            request.body = CreateRocketMqMigrationTaskReq(
                bindings=listBindingsbody,
                exchanges=listExchangesbody,
                queues=listQueuesbody,
                vhosts=listVhostsbody
            )
            response = client.create_rocket_mq_migration_task(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 metadata migration task to migrate the metadata from other vendors' or self-built RocketMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    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.CreateRocketMqMigrationTaskRequest{}
    	request.InstanceId = "{instance_id}"
    	groupNameSubscriptionGroupTable:= "group-test1"
    	consumeBroadcastEnableSubscriptionGroupTable:= true
    	consumeEnableSubscriptionGroupTable:= true
    	consumeFromMinEnableSubscriptionGroupTable:= true
    	notifyConsumerIdsChangedEnableSubscriptionGroupTable:= true
    	retryMaxTimesSubscriptionGroupTable:= int32(2)
    	retryQueueNumsSubscriptionGroupTable:= int32(1)
    	whichBrokerWhenConsumeSlowSubscriptionGroupTable:= int64(1)
    	subscriptionGroupTableSubscriptionGroupTable := model.MigrationRocketMqSubscriptionGroup{
    		GroupName: &groupNameSubscriptionGroupTable,
    		ConsumeBroadcastEnable: &consumeBroadcastEnableSubscriptionGroupTable,
    		ConsumeEnable: &consumeEnableSubscriptionGroupTable,
    		ConsumeFromMinEnable: &consumeFromMinEnableSubscriptionGroupTable,
    		NotifyConsumerIdsChangedEnable: &notifyConsumerIdsChangedEnableSubscriptionGroupTable,
    		RetryMaxTimes: &retryMaxTimesSubscriptionGroupTable,
    		RetryQueueNums: &retryQueueNumsSubscriptionGroupTable,
    		WhichBrokerWhenConsumeSlow: &whichBrokerWhenConsumeSlowSubscriptionGroupTable,
    	}
    	var listSubscriptionGroupTablebody = map[string](model.MigrationRocketMqSubscriptionGroup){
            "group-test1": subscriptionGroupTableSubscriptionGroupTable,
        }
    	topicNameTopicConfigTable:= "topic-test1"
    	orderTopicConfigTable:= false
    	permTopicConfigTable:= int32(6)
    	readQueueNumsTopicConfigTable:= int32(3)
    	writeQueueNumsTopicConfigTable:= int32(3)
    	topicFilterTypeTopicConfigTable:= "SINGLE_TAG"
    	topicSysFlagTopicConfigTable:= int32(0)
    	topicConfigTableTopicConfigTable := model.MigrationRocketMqTopicConfig{
    		TopicName: &topicNameTopicConfigTable,
    		Order: &orderTopicConfigTable,
    		Perm: &permTopicConfigTable,
    		ReadQueueNums: &readQueueNumsTopicConfigTable,
    		WriteQueueNums: &writeQueueNumsTopicConfigTable,
    		TopicFilterType: &topicFilterTypeTopicConfigTable,
    		TopicSysFlag: &topicSysFlagTopicConfigTable,
    	}
    	var listTopicConfigTablebody = map[string](model.MigrationRocketMqTopicConfig){
            "topic-test1": topicConfigTableTopicConfigTable,
        }
    	request.Body = &model.CreateRocketMqMigrationTaskReq{
    		SubscriptionGroupTable: listSubscriptionGroupTablebody,
    		TopicConfigTable: listTopicConfigTablebody,
    	}
    	response, err := client.CreateRocketMqMigrationTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Creating a metadata migration task to migrate the metadata of RabbitMQ instances to DMS for RocketMQ.

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    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.CreateRocketMqMigrationTaskRequest{}
    	request.InstanceId = "{instance_id}"
    	vhostBindings:= "/"
    	sourceBindings:= "direct"
    	destinationBindings:= "test-001"
    	destinationTypeBindings:= "queue"
    	routingKeyBindings:= "test-001"
    	var listBindingsbody = []model.MigrationRabbitBindingMetadata{
            {
                Vhost: &vhostBindings,
                Source: &sourceBindings,
                Destination: &destinationBindings,
                DestinationType: &destinationTypeBindings,
                RoutingKey: &routingKeyBindings,
            },
        }
    	vhostExchanges:= "/"
    	nameExchanges:= "direct"
    	typeExchanges:= "topic"
    	durableExchanges:= false
    	var listExchangesbody = []model.MigrationRabbitExchangeMetadata{
            {
                Vhost: &vhostExchanges,
                Name: &nameExchanges,
                Type: &typeExchanges,
                Durable: &durableExchanges,
            },
        }
    	vhostQueues:= "/"
    	nameQueues:= "test-001"
    	durableQueues:= false
    	var listQueuesbody = []model.MigrationRabbitQueueMetadata{
            {
                Vhost: &vhostQueues,
                Name: &nameQueues,
                Durable: &durableQueues,
            },
        }
    	nameVhosts:= "DeleteVhost123"
    	var listVhostsbody = []model.MigrationRabbitVhostMetadata{
            {
                Name: &nameVhosts,
            },
        }
    	request.Body = &model.CreateRocketMqMigrationTaskReq{
    		Bindings: &listBindingsbody,
    		Exchanges: &listExchangesbody,
    		Queues: &listQueuesbody,
    		Vhosts: &listVhostsbody,
    	}
    	response, err := client.CreateRocketMqMigrationTask(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

Successful

Error Codes

See Error Codes.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback