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
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.
Create a consumer and connect it to the target TDMQ for CMQ queue.
Consumer consumer = new Consumer();
// VPC address: http://{region}.mqadapter.cmq.tencentyun.com. CVM instances in a VPC can be accessed over the private network
// Public network address: https://cmq-{region}.public.tencenttdmq.com
consumer.setNameServerAddress("http://****.com");
// Set `SecretId`, which is required and can be obtained from the console
consumer.setSecretId("****");
// Set `SecretKey`, which is required and can be obtained from the console
consumer.setSecretKey("****");
// Set the signature algorithm, which is optional and is SHA1 by default
consumer.setSignMethod(ClientConfig.SIGN_METHOD_SHA256);
// Set the maximum number of messages that can be pulled in batches, which ranges from 1 to 16
consumer.setBatchPullNumber(16);
// Set the wait timeout period, which is 10s by default. You can pass in the specific wait time in methods such as `consumer.receiveMsg`
consumer.setPollingWaitSeconds(6);
// Set the request timeout period, which is 3,000 ms by default
// If you set the wait timeout period to 6s and request timeout period to 5,000 ms, the final timeout period will be (6 * 1000 + 5000) ms
consumer.setRequestTimeoutMS(5000);
// Name of the queue from which messages are pulled
final String queue = "****";
Run the code and check whether the consumer service can run normally with no errors reported.
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.
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.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?