Overview
This document takes the Java client as an example to describe how to migrate a CMQ queue to TDMQ for CMQ.
Migration principle
Scheme overview
Overall process
Migrate the CMQ queue and topic metadata to TDMQ for CMQ in the CMQ console.
Keep the old consumer unchanged, create a new consumer, and connect it to the TDMQ for CMQ queue.
The producer stops producing messages for the original CMQ queue and switches the production stream to the TDMQ for CMQ queue.
The old CMQ consumer continues consuming existing messages in the original CMQ queue. After the consumption is completed, deactivate it.
Prerequisites
You have deployed CMQ queue producer and consumer services as instructed in SDK for TCP, and they are running normally. The following migration process takes the SDK for TCP as an example. Directions
2. Select Queue on the left sidebar, select a Region, and click Sync to TDMQ at the top of the page.
3. In the pop-up window, click Start to migrate all queue and topic metadata in the region to TDMQ for CMQ.
4. After the migration is completed, log in to the TDMQ console. 5. Select Queue Service on the left sidebar, select the same Region, and you can see the queues migrated to TDMQ for CMQ.
Step 2. Create a consumer
1. Create a consumer and connect it to the target TDMQ for CMQ queue.
Consumer consumer = new Consumer();
consumer.setNameServerAddress("http://****.com");
consumer.setSecretId("****");
consumer.setSecretKey("****");
consumer.setSignMethod(ClientConfig.SIGN_METHOD_SHA256);
consumer.setBatchPullNumber(16);
consumer.setPollingWaitSeconds(6);
consumer.setRequestTimeoutMS(5000);
final String queue = "****";
NameServerAddress: API call address, which can be copied in Queue Service > API Request Address in the TDMQ for CMQ console. SecretId and SecretKey: TencentCloud API key, which can be copied in Access Key > API Key Management in the CAM console. queue: Queue name.
2. Run the code and check whether the consumer service can run normally with no errors reported.
3. In Queue Service > Send Message in the TDMQ for CMQ console, send a test message to the message recipient to check whether the consumer service can consume normally. Step 3. Switch the production stream
1. Change the NameServer
value of the original producer to the access address of the TDMQ for CMQ queue, which can be copied in Queue Service > API Request Address in the TDMQ for CMQ console. 2. Run the message production program to check whether the producer service can send messages normally.
Step 4. Deactivate the old consumer
After the old CMQ consumer has consumed all existing messages in the original CMQ queue, deactivate it.
On the Monitoring page in Queue Service > Queue in the CMQ console, you can view the number of heaped messages in the CMQ queue. If it is 0, existing messages in the original CMQ queue have all been consumed.
Was this page helpful?