<!-- cmq sdk --><dependency><groupId>com.qcloud</groupId><artifactId>cmq-http-client</artifactId><version>1.0.7</version></dependency><!-- TencentCloud API sdk --><dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>3.1.423</version></dependency>
Account account = new Account(SERVER_ENDPOINT, SECRET_ID, SECRET_KEY);Queue queue = account.getQueue(queueName);String msg = "hello client, this is a message. Time:" + new Date();CmqResponse response = queue.send(msg);
Parameter | Description |
SERVER_ENDPOINT | API call address, which can be copied from Queue Service > API Request Address in the TDMQ for CMQ console. |
SECRET_ID, SECRET_KEY | TencentCloud API key, which can be copied on the Access Key > API Key Management page in the CAM console. |
queueName |
Account account = new Account(SERVER_ENDPOINT, SECRET_ID, SECRET_KEY);Queue queue = account.getQueue(queueName);Message message = queue.receiveMessage();// Successfully consumed messages are deleted. Retained messages can be delivered again after a certain period of timequeue.deleteMessage(message.receiptHandle);
Parameter | Description |
SERVER_ENDPOINT | API call address, which can be copied from Queue Service > API Request Address in the TDMQ for CMQ console. |
SECRET_ID, SECRET_KEY | TencentCloud API key, which can be copied on the Access Key > API Key Management page in the CAM console. |
queueName |
<!-- cmq sdk --><dependency><groupId>com.qcloud</groupId><artifactId>cmq-http-client</artifactId><version>1.0.7</version></dependency><!-- TencentCloud API sdk --><dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>3.1.423</version></dependency>
Account account = new Account(SERVER_ENDPOINT, SECRET_ID, SECRET_KEY);Topic topic = account.getTopic(topicName);
Parameter | Description |
SERVER_ENDPOINT | API call address, which can be copied from Queue Service > API Request Address in the TDMQ for CMQ console. |
SECRET_ID, SECRET_KEY | TencentCloud API key, which can be copied on the Access Key > API Key Management page in the CAM console. |
topicName | Topic subscription name, which can be obtained on the Topic Subscription page in the TDMQ for CMQ console. |
String msg = "hello client, this is a message. tag=TAG1. Time:" + new Date();List<String> tags = Collections.singletonList("TAG1");String messageId = topic.publishMessage(msg, tags, null);
String msg = "hello client, this is a message. route(abc) Time:" + new Date();String messageId = topic.publishMessage(msg, "abc");
Account account = new Account(SERVER_ENDPOINT, SECRET_ID, SECRET_KEY);Queue queue = account.getQueue(queueName);Message message = queue.receiveMessage();// Successfully consumed messages are deleted. Retained messages can be delivered again after a certain period of timequeue.deleteMessage(message.receiptHandle);
Was this page helpful?