Compared with open source Apache RocketMQ, Alibaba Cloud ApsaraMQ for RocketMQ is more stable and secure and provides a more comprehensive O&M system. You can migrate Apache RocketMQ clusters to ApsaraMQ for RocketMQ instances for a better experience. This topic describes how to use the migration tool provided by ApsaraMQ for RocketMQ to migrate a self-managed Apache RocketMQ cluster to an ApsaraMQ for RocketMQ instance.
Prerequisites
An ApsaraMQ for RocketMQ 5.0 instance is created. For more information, see Create an instance.
A service-linked role is created. For more information, see Service-linked roles.
Role name: AliyunServiceRoleForRMQMigration
Policy: AliyunServiceRolePolicyForRMQMigration
Description: Allow ApsaraMQ for RocketMQ to assume this role to access virtual private clouds (VPCs).
Migration process
The following figure describes the process to migrate an Apache RocketMQ cluster to an ApsaraMQ for RocketMQ instance.
Step 1: Evaluate the migration task
Evaluate the risks of migration and the version and feature compatibility between the Apache RocketMQ cluster and the ApsaraMQ for RocketMQ instance to determine the scope of data that you want to migrate.
Specify the information about the network and nodes of the Apache RocketMQ cluster. ApsaraMQ for RocketMQ connects to the network based on a minimum scope policy to grant permissions on traffic switching and traffic switch checking.
ApsaraMQ for RocketMQ reads the metadata of topics and groups in the Apache RocketMQ cluster and copies the metadata to the destination ApsaraMQ for RocketMQ instance.
Confirm all producers and consumers that are involved in the migration and change the endpoint in the messaging code of the source Apache RocketMQ cluster to the endpoint of the destination ApsaraMQ for RocketMQ instance.
Perform phased traffic switching by topic.
Step 1: Evaluate the migration task
Before you migrate an Apache RocketMQ cluster to an ApsaraMQ for RocketMQ instance in batches, you must perform a technical evaluation on the migration task and confirm the migration scope.
Technical evaluation: This helps you determine whether the environment of the Apache RocketMQ cluster meets the requirements for migration. This also helps you obtain information about features that are supported before and after the migration.
Migration scope confirmation: We recommend that you perform phased migration in batches based on the importance of your business and the coupling between business applications. You can migrate part of your business and then migrate the remaining business after the migrated business stabilizes.
Technical evaluation
Limits on Apache RocketMQ clusters: Before you migrate an Apache RocketMQ cluster to an ApsaraMQ for RocketMQ instance, evaluate whether the cluster meets the requirements. If the cluster does not meet the requirements, submit a ticket. The following table describes the limits on Apache RocketMQ clusters.
Limit
Description
Deployed version
Apache RocketMQ 4.x and 5.x brokers are supported.
Network
The source Apache RocketMQ cluster must be deployed in a VPC. If the source Apache RocketMQ cluster is deployed in an on-premises data center, make sure that the cluster can be accessed from a VPC.
Region
You can migrate self-managed Apache RocketMQ clusters to ApsaraMQ for RocketMQ instances in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Shenzhen), and China (Zhangjiakou).
Feature
ApsaraMQ for RocketMQ does not support access control list (ACL) verification. If you enable the ACL feature for the Apache RocketMQ cluster, you must disable the feature before migration. If you do not disable the ACL feature, the feature does not take effect after migration.
Parameter
Message size
A message cannot exceed 4 MB in size.
Message retention period
Minimum value: 24. Unit: hours.
Maximum value: 720. Unit: hours.
Maximum delay time of scheduled messages
Subscription and pay-as-you-go Standard Edition instances and serverless Standard Edition and Professional Edition instances: 7 days.
Subscription and pay-as-you-go Professional Edition and Enterprise Platinum Edition instances: 40 days.
For more information, see Quotas and limits.
Limits on SDK versions: The migration solution follows the principle of minimal changes. In most cases, the versions of client SDKs are automatically upgraded. If the migration involves the upgrade of major versions, new features are added and stability optimizations are provided. In this case, we recommend that you upgrade the SDK version during migration.
SDK
Programming language
SDK version
Upgrade required or not
Apache RocketMQ Remoting SDK
The following code shows the endpoint format of SDKs of this type:
producer.setNamesrvAddr("xxx:9876"); consumer.setNamesrvAddr("xxx:9876");
Java
5.x SDK
This type of SDK is compatible with ApsaraMQ for RocketMQ instances. No upgrade is required.
Java and C++
4.x SDK
If the PullConsumer, DefaultLitePullConsumer, and DefaultPullConsumer operations are called by the source Apache RocketMQ cluster, you must upgrade the SDK to 5.x. For more information, see Overview.
Apache RocketMQ gRPC SDK
The following code shows the endpoint format of SDKs of this type:
ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder() .setEndpoints(192.168.XX.XX:9876) .setCredentialProvider(sessionCredentialsProvider) .build();
Java, C++, Go, and C#
5.x SDK
This type of SDK is compatible with ApsaraMQ for RocketMQ instances. No upgrade is required.
Migration scope confirmation
The migration solution provided by ApsaraMQ for RocketMQ allows you to migrate Apache RocketMQ clusters to ApsaraMQ for RocketMQ instances by topic. Batch migration, canary release, and rollback are also supported. This effectively reduces risks caused by large-scale changes.
Before migration, you must confirm the business scope of each topic and determine the topics that you want to migrate in each batch.
Topic selection: Select the topics that you want to migrate in the cluster and determine the topics to be migrated in each batch. We recommend that you first migrate topics of non-core business.
Cooperation from upstream and downstream applications: After you select the topics that you want to migrate, you must notify all producer and consumer applications that use these topics to change the endpoint.
ImportantMake sure that you notify all upstream and downstream applications that use the topics. If specific applications do not change the endpoint, risks such as message consumption delay may occur.
Step 2: Configure the network
In this step, you need to create a migration task and configure the network for the source Apache RocketMQ cluster. The migration tool provided by ApsaraMQ for RocketMQ can use the configured network to read metadata in the source Apache RocketMQ cluster and manage the migration task.
Usage notes
The migration tool provided by ApsaraMQ for RocketMQ can access only the following information about the source Apache RocketMQ cluster based on the minimum scope policy:
The metadata of topics
The metadata of groups
Information about dynamic routing registration in topics
Information about consumer connections and message accumulation
The migration tool does not access other information about the source Apache RocketMQ cluster or write configuration information to the cluster. Therefore, the access of the migration tool to an Apache RocketMQ cluster does not have impacts on the running of the cluster.
Make sure that network configurations are valid before you go to the next step. Once you enter the next step, you cannot roll back to the network configuration step. To modify the network configurations, you must create a new migration task.
Procedure
Log on to the ApsaraMQ for RocketMQ console.
In the top navigation bar, select the region where the source Apache RocketMQ cluster and destination ApsaraMQ for RocketMQ instance reside. In the left-side navigation pane, choose .
On the Migration to Cloud page, click Create Task.
In the Create Migration Task panel, configure the parameters and click OK.
For information about the parameters, see Parameters configured for the network of the source Apache RocketMQ cluster.
In the Network Settings step of the Migration to Cloud wizard, enter the network information about the source Apache RocketMQ cluster and click Configure Network.
For information about the parameters, see Parameters configured for the network of the source Apache RocketMQ cluster.
Wait until the background configuration is complete. Then, click Next.
Parameter settings
Table 1. Parameters configured for the network of the source Apache RocketMQ cluster
Parameter | Description | Example |
Cluster Type | The network environment in which the Apache RocketMQ cluster is deployed. Valid values:
| VPC-connected Cluster |
Cluster Name | The custom identifier of the Apache RocketMQ cluster. The cluster name is used only to identify the cluster and view the migration task. The name does not affect the business system. | first |
VPC | The ID of the VPC in which the Apache RocketMQ cluster is deployed. This parameter is required only if you set the Cluster Type parameter to VPC-connected Cluster. | vpc-bp1mhd******24chrxn |
vSwitch | The vSwitch. The vSwitch is used only to enable the ApsaraMQ for RocketMQ migration tool to access the network of the Apache RocketMQ cluster. You must follow the following rules when you select a vSwitch:
This parameter is required only if you set the Cluster Type parameter to VPC-connected Cluster. | vsw-bp1hejs******0los38rn |
Security Group | The security group. We recommend that you select the security group to which the Elastic Compute Service (ECS) instance on which the Apache RocketMQ cluster is deployed belongs. If you select a different security group, make sure that the security rule of the security group allows access to the destination ApsaraMQ for RocketMQ instance. This parameter is required only if you set the Cluster Type parameter to VPC-connected Cluster. | sg-bp160q******vtcxvwl |
Name Server Address | The IP addresses of the name servers of the Apache RocketMQ cluster. Separate multiple IP addresses with commas (,) or semicolons (;). Important You must specify all IP addresses of the name servers of the Apache RocketMQ cluster that you want to migrate. Otherwise, you may fail to select the topics that you want to migrate during migration. | 192.168.XX.XX:9876 |
Access Credential |
| ACL |
Username | The name of the admin account of the Apache RocketMQ cluster. This parameter is required only if the ACL feature is enabled for the Apache RocketMQ cluster. | admin |
Password | The password of the admin account of the Apache RocketMQ cluster. This parameter is required only if the ACL feature is enabled for the Apache RocketMQ cluster. | ****** |
Step 3: Migrate metadata
After you configure the network, you must select the topics and groups that you want to migrate based on your migration plan to complete the metadata migration.
Usage notes
During metadata migration, the ApsaraMQ for RocketMQ migration tool dynamically reads the information about all topics and groups that are created in the Apache RocketMQ cluster and displays the information in lists. You need to migrate only the metadata of the topics and groups that you want to migrate.
You cannot roll back to this step. Make sure that the topics and groups that you want to migrate are all migrated before you go to the next step. Otherwise, you must manually add topics in subsequent operations.
Procedure
In the Metadata Migration step, click the Topic Metadata tab.
Select the topic that you want to migrate from the topic list and the corresponding message type from the Message Type drop-down list. Then, click Confirm and Import in the Actions column to import the topic.
You can also select multiple topics and click Batch Import to import the topics at a time.
ImportantMessage types are not defined in Apache RocketMQ 4.x. ApsaraMQ for RocketMQ verifies whether the message type that you specified for the topic to be migrated is consistent with the type of message that the topic handles. When you migrate metadata, you must select the message type based on your actual business.
If you select a wrong message type, messages fail to be sent or received after migration. If you are not sure about the message type of the topic or whether different types of messages exist in the topic, submit a ticket.
Click the Group Metadata tab, select the group that you want to migrate from the group list, select the order in which messages are consumed from the Consumption Order drop-down list, and then click Confirm and Import in the Actions column to import the group.
You can also select multiple groups and click Batch Import to import the groups at a time.
ImportantThe consumption order of messages in an Apache RocketMQ 4.x SDK is specified on the client. The consumption order of messages in a group on an ApsaraMQ for RocketMQ 5.x instance is controlled by the broker. When you migrate metadata, you must specify the consumption order of messages in the group based on your business scenario.
If you select a wrong message consumption order, consumption exceptions occur after migration. If you are not sure about the consumption order of messages in a group, submit a ticket.
Click Next after you confirm that all topics and groups that you want to migrate are imported.
Step 4: Change the endpoint
After you migrate the metadata of the specified topics and groups, you start to migrate the online business. At this stage, you must change the endpoint that the producer and consumer applications use to access the source cluster to the endpoint that they use to access the destination ApsaraMQ for RocketMQ 5.x instance. This way, the producer and consumer applications that are involved in the migration task can be connected to the destination ApsaraMQ for RocketMQ instance.
Usage notes
After you change the endpoint, you must restart the producer and consumer applications to connect the applications to the destination ApsaraMQ for RocketMQ instance. During this process, the migration tool routes topics that are used for messaging to the Apache RocketMQ cluster at the backend. The messaging system remains unchanged in this step. No limit is imposed on the order in which the messaging applications change the endpoint.
Make sure that the endpoint is changed in all producer and consumer applications that are involved in the migration.
If the endpoint is not changed in specific producer applications, specific messages fail to be sent.
If the endpoint is not changed in specific consumer applications, message accumulation occurs and specific messages cannot be consumed.
Examples of endpoint change
Apache RocketMQ Remoting SDKs
Before change:
producer.setNamesrvAddr("192.168.XX.XX:9876"); consumer.setNamesrvAddr("192.168.XX.XX:9876");
After change:
producer.setNamesrvAddr("rmq-cn-pe334******-vpc.cn-hangzhou.rmq.aliyuncs.com:8080"); consumer.setNamesrvAddr("rmq-cn-pe334******-vpc.cn-hangzhou.rmq.aliyuncs.com:8080");
Apache RocketMQ gRPC SDKs
Before change:
ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder() .setEndpoints(192.168.XX.XX:9876) .setCredentialProvider(sessionCredentialsProvider) .build();
After change:
ClientConfiguration clientConfiguration = ClientConfiguration.newBuilder() .setEndpoints(rmq-cn-pe334******-vpc.cn-hangzhou.rmq.aliyuncs.com:8080) .setCredentialProvider(sessionCredentialsProvider) .build();
Procedure
After you change the endpoint and restart the messaging applications, click Next in the Change Endpoint step.
Step 5: Migrate messages
To migrate messages, you must switch read and write traffic in each topic of the Apache RocketMQ cluster to the ApsaraMQ for RocketMQ instance.
Usage notes
During traffic switching, you must check whether messages are sent and received as expected each time the topic status changes. If no exceptions occur, go to the next step. If exceptions occur, roll back to the previous step and troubleshoot the issue.
Make sure that the traffic in all topics that you want to migrate are switched and messages can be sent and received as expected before you complete the migration task. You cannot modify the information about traffic switching after you complete the migration task.
Traffic switching details
Table 2. Traffic switching status
Status | Description | Traffic topology |
Read and Write in Source Cluster | The initial status of message migration.
| |
Write in Source Cluster and Read in Source and Destination Clusters |
| |
Write in Destination Cluster and Read and Write in Source and Destination Clusters |
At this stage, traffic for message production and traffic for message consumption exist at the same time in the destination cluster. Check whether messages can be sent and received as expected and wait until messages in the source cluster are consumed. | |
Read and Write in Destination Cluster | After you confirm that messages can be sent and received as expected in the destination cluster and that accumulated messages are consumed in the source cluster, you can switch the topic to this state. In this case, read traffic and write traffic are directed to the destination cluster, and the migration is complete.
|
Switch traffic
In the Message Migration step, select the topic for which you want to migrate messages and confirm the check status of the topic.
If the status is Check Passed, go to the next step.
If the status is not Check Passed, troubleshoot the exception based on the check result. Then, click Re-verify in the Actions column until the check is passed. After the check is passed, go to the next step.
For information about items that are checked during each stage of traffic switching, see Check items.
If the status is not Check Passed and you confirm that the check result does not affect the migration, click Ignore Check in the Actions column of the topic and go to the next step.
In the Actions column of the topic whose traffic you want to switch, click Switch Traffic.
In the message that appears, click OK.
Traffic switching consists of four stages. You must perform the traffic switching operation four times. Traffic switching is complete until Traffic Switching Stage changes to Read and Write in Destination Cluster.
For information about the change of read and write traffic in topics during each stage of traffic switching, see Traffic switching status.
Confirm that the traffic of all topics that you want to migrate in the migration task is switched and click Migrated in the lower part of the page.
Other operations
The following items describe other operations that you can perform on the Message Migration page when you switch traffic:
Roll Back
Roll back to the previous state: If the migration does not work as expected, you can roll back the status of the specified topic to a previous state in which the migration works as expected and perform subsequent operations after you troubleshoot the issue.
Roll back to the initial status: You can roll back to the initial status of traffic switching by using this method. The initial status of traffic switching refers to the routing state and is used for emergency troubleshooting.
NoteIf you perform this operation, huge changes are caused to the status of traffic switching. Unconsumed messages that are produced during previous migration process may be delayed or cannot be processed.
Create Topic
If a topic that you want to migrate is not selected during metadata migration, you can create a topic that has the same name as the topic that you want to migrate on the ApsaraMQ for RocketMQ 5.x instance during traffic switching.
Batch Traffic Switching/Batch Rollback
You can perform batch traffic switching and batch rollback.
NoteYou can perform batch traffic switching and batch rollback only for topics that are at the same traffic switching stage.Traffic Switching Stage
Check items during traffic switching
Table 3. Check items
Stage | Check item |
Switch to the Write in Source Cluster and Read in Source and Destination Clusters state |
|
Switch to the Write in Destination Cluster and Read and Write in Source and Destination Clusters state |
|
Switch to the Read and Write in Destination Cluster state |
|
References
For information about the differences between open source Apache RocketMQ and ApsaraMQ for RocketMQ and the migration mechanism and benefits of cloud migration, see Overview.
After the migration task is complete, you can use metrics on the ApsaraMQ for RocketMQ dashboard to check whether the instance is running as expected and whether the business data of the instance is normal. If exceptions occur, you can roll back the task. For more information, see Dashboard and Roll Back.