文档首页/ 分布式消息服务RocketMQ版/ API参考/ API V2(推荐)/ 元数据迁移/ 新建元数据迁移任务 - CreateRocketMqMigrationTask
更新时间:2026-01-23 GMT+08:00

新建元数据迁移任务 - CreateRocketMqMigrationTask

功能介绍

新建元数据迁移任务。

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    dms:instance:createMetadataMigrationTask

    Write

    rocketmq *

    • g:ResourceTag/<tag-key>

    • g:EnterpriseProjectId

    -

    -

URI

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

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

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

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

instance_id

String

参数解释

实例ID。获取方法如下:调用“查询所有实例列表”接口,从响应体中获取实例ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

表2 Query参数

参数

是否必选

参数类型

描述

overwrite

String

参数解释

true开启同名覆盖,会对已有的同名元数据的配置进行修改,false时当Topic或group已存在则会报错。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

name

String

参数解释

迁移任务名称,名称规则参考创建实例。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

type

String

参数解释

迁移任务类型,分为自建RocketMQ上云(rocketmq)、自建RabbitMQ上云(rabbitToRocket)

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

请求参数

表3 请求Body参数

参数

是否必选

参数类型

描述

topic_config_table

Map<String,MigrationRocketMqTopicConfig>

参数解释

RocketMQ Topic 元数据,键为Topic名,值为topic配置,迁移任务类型为自建RocketMQ上云(rocketmq)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

subscription_group_table

Map<String,MigrationRocketMqSubscriptionGroup>

参数解释

RocketMQ消费组元数据,键为消费组名,值为消费组配置,迁移任务类型为自建RocketMQ上云(rocketmq)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

vhosts

Array of MigrationRabbitVhostMetadata objects

参数解释

RabbitMQ vhost元数据列表,迁移任务类型为自建RabbitMQ上云(rabbitToRocket)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

queues

Array of MigrationRabbitQueueMetadata objects

参数解释

RabbitMQ队列元数据列表,迁移任务类型为自建RabbitMQ上云(rabbitToRocket)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

exchanges

Array of MigrationRabbitExchangeMetadata objects

参数解释

RabbitMQ交换机元数据列表,迁移任务类型为自建RabbitMQ上云(rabbitToRocket)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

bindings

Array of MigrationRabbitBindingMetadata objects

参数解释

RabbitMQ binding元数据列表,迁移任务类型为自建RabbitMQ上云(rabbitToRocket)时必填。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

表4 MigrationRocketMqTopicConfig

参数

是否必选

参数类型

描述

topic_name

String

参数解释

Topic名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

order

Boolean

参数解释

是否有序消息。

约束限制

不涉及。

取值范围

  • true:有序消息。

  • false:无序消息。

默认取值

false。

perm

Integer

参数解释

Topic权限。

约束限制

不涉及。

取值范围

  • PUB:拥有发布权限。

  • SUB:拥有订阅权限。

  • PUB|SUB:拥有发布订阅权限。

  • DENY:无权限。

默认取值

6。

read_queue_nums

Integer

参数解释

读队列个数。

约束限制

不涉及。

取值范围

不涉及。

默认取值

16。

write_queue_nums

Integer

参数解释

写队列个数。

约束限制

不涉及。

取值范围

不涉及。

默认取值

16。

topic_filter_type

String

参数解释

Topic过滤类型。

约束限制

不涉及。

取值范围

  • SINGLE_TAG:单标签

    • MULTI_TAG:多标签

    默认取值

不涉及。

topic_sys_flag

Integer

参数解释

Topic系统标志位。

约束限制

不涉及。

取值范围

不涉及。

默认取值

0。

表5 MigrationRocketMqSubscriptionGroup

参数

是否必选

参数类型

描述

group_name

String

参数解释

消费组名。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

consume_broadcast_enable

Boolean

参数解释

是否允许以广播模式消费。

约束限制

不涉及。

取值范围

  • true:允许以广播模式消费。

  • false:不允许以广播模式消费。

默认取值

不涉及。

consume_enable

Boolean

参数解释

是否允许消费。

约束限制

不涉及。

取值范围

  • true:允许消费。

  • false:不允许消费。

默认取值

true。

consume_from_min_enable

Boolean

参数解释

是否从最小偏移量开始消费。

约束限制

不涉及。

取值范围

  • true:是。

  • false:不是。

默认取值

true。

notify_consumer_ids_changed_enable

Boolean

参数解释

消费者ID变化时是否通知。

约束限制

不涉及。

取值范围

  • true:是。

  • false:不是。

默认取值

true。

retry_max_times

Integer

参数解释

消费最大重试次数。

约束限制

不涉及。

取值范围

不涉及。

默认取值

16。

retry_queue_nums

Integer

参数解释

消费最大重试次数。

约束限制

不涉及。

取值范围

不涉及。

默认取值

1。

which_broker_when_consume_slow

Long

参数解释

慢消费时选择的broker节点ID

约束限制

不涉及。

取值范围

不涉及。

默认取值

1。

表6 MigrationRabbitVhostMetadata

参数

是否必选

参数类型

描述

name

String

参数解释

vhost名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

表7 MigrationRabbitQueueMetadata

参数

是否必选

参数类型

描述

vhost

String

参数解释

vhost名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

name

String

参数解释

队列名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

durable

Boolean

参数解释

是否持久化。

约束限制

不涉及。

取值范围

  • true:持久化。

  • false:不进行持久化。

默认取值

不涉及。

表8 MigrationRabbitExchangeMetadata

参数

是否必选

参数类型

描述

vhost

String

参数解释

vhost名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

name

String

参数解释

交换机名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

type

String

参数解释

交换机类型。

约束限制

不涉及。

取值范围

  • topic:支持routing key的模糊匹配。

  • direct:按routing key精确匹配进行消息路由。

  • fanout:广播模式,消息会发送到所有绑定的队列,忽略routing key。

  • headers:根据消息头(headers)中的键值对进行路由,而不是routing key。

默认取值

不涉及。

durable

Boolean

参数解释

是否持久化。

约束限制

不涉及。

取值范围

  • true:持久化。

  • false:不进行持久化。

默认取值

不涉及。

表9 MigrationRabbitBindingMetadata

参数

是否必选

参数类型

描述

vhost

String

参数解释

vhost名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

source

String

参数解释

消息的来源。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

destination

String

参数解释

消息的目标。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

destination_type

String

参数解释

目标的类型。

约束限制

不涉及。

取值范围

  • exchange:交换机。

  • queue:队列。RabbitMQ AMQP版本只支持绑定queue。

默认取值

不涉及。

routing_key

String

参数解释

路由键。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

响应参数

状态码:200

表10 响应Body参数

参数

参数类型

描述

task_id

String

参数解释

任务ID。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

请求示例

  • 创建元数据迁移任务,迁移其他厂商或自建RocketMQ实例的元数据到云上RocketMQ实例。

    POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/metadata?overwrite=true&name=task-123&type=rocketmq
    
    {
      "topic_config_table" : {
        "topic-test1" : {
          "order" : false,
          "perm" : 6,
          "read_queue_nums" : 3,
          "topic_filter_type" : "SINGLE_TAG",
          "topic_name" : "topic-test1",
          "topic_sys_flag" : 0,
          "write_queue_nums" : 3
        }
      },
      "subscription_group_table" : {
        "group-test1" : {
          "consume_broadcast_enable" : true,
          "consume_enable" : true,
          "consume_from_min_enable" : true,
          "group_name" : "group-test1",
          "notify_consumer_ids_changed_enable" : true,
          "retry_max_times" : 2,
          "retry_queue_nums" : 1,
          "which_broker_when_consume_slow" : 1
        }
      }
    }
  • 创建元数据迁移任务,迁移RabbitMQ的元数据到云上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"
      } ]
    }

响应示例

状态码:200

创建成功。

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

SDK代码示例

SDK代码示例如下。

  • 创建元数据迁移任务,迁移其他厂商或自建RocketMQ实例的元数据到云上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
    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.*;
    
    
    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}");
            body.withCreateRocketMqMigrationTaskReq("{\"subscription_group_table\":{\"group-test1\":{\"consume_enable\":true,\"consume_from_min_enable\":true,\"group_name\":\"group-test1\",\"which_broker_when_consume_slow\":1,\"consume_broadcast_enable\":true,\"notify_consumer_ids_changed_enable\":true,\"retry_queue_nums\":1,\"retry_max_times\":2}},\"topic_config_table\":{\"topic-test1\":{\"read_queue_nums\":3,\"write_queue_nums\":3,\"perm\":6,\"topic_name\":\"topic-test1\",\"topic_filter_type\":\"SINGLE_TAG\",\"order\":false,\"topic_sys_flag\":0}}}");
            request.withBody(listCreateRocketMqMigrationTaskReqCreateRocketMqMigrationTaskReq);
            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());
            }
        }
    }
    
  • 创建元数据迁移任务,迁移RabbitMQ的元数据到云上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());
            }
        }
    }
    
  • 创建元数据迁移任务,迁移其他厂商或自建RocketMQ实例的元数据到云上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
    # 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}"
            request.body = listCreateRocketMqMigrationTaskReqCreateRocketMqMigrationTaskReq
            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)
    
  • 创建元数据迁移任务,迁移RabbitMQ的元数据到云上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)
    
  • 创建元数据迁移任务,迁移其他厂商或自建RocketMQ实例的元数据到云上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
    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}"
    	var createRocketMqMigrationTaskReqCreateRocketMqMigrationTaskReq interface{} = "{\"subscription_group_table\":{\"group-test1\":{\"consume_enable\":true,\"consume_from_min_enable\":true,\"group_name\":\"group-test1\",\"which_broker_when_consume_slow\":1,\"consume_broadcast_enable\":true,\"notify_consumer_ids_changed_enable\":true,\"retry_queue_nums\":1,\"retry_max_times\":2}},\"topic_config_table\":{\"topic-test1\":{\"read_queue_nums\":3,\"write_queue_nums\":3,\"perm\":6,\"topic_name\":\"topic-test1\",\"topic_filter_type\":\"SINGLE_TAG\",\"order\":false,\"topic_sys_flag\":0}}}"
    	request.Body = listCreateRocketMqMigrationTaskReqCreateRocketMqMigrationTaskReq
    	response, err := client.CreateRocketMqMigrationTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建元数据迁移任务,迁移RabbitMQ的元数据到云上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)
        }
    }
    

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

状态码

状态码

描述

200

创建成功。

错误码

请参见错误码