<!-- cmq sdk --><dependency> <groupId>com.qcloud</groupId> <artifactId>cmq-http-client</artifactId> <version>1.0.7</version></dependency><!-- 云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);
参数 | 说明 |
SERVER_ENDPOINT | API 调用地址,在 TDMQ CMQ 版控制台的主题订阅 > API 请求地址处复制。![](https://qcloudimg.tencent-cloud.cn/raw/910150612a00a6461ff923cd53a1ec97.png) |
SECRET_ID、SECRET_KEY | 云 API 密钥,登录 访问管理控制台,在访问密钥 > API 密钥管理页面复制。![](https://qcloudimg.tencent-cloud.cn/raw/82946cd1e7b1d46a9ccb06ef171137da.png) |
topicName |
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();// 消费成功,删除消息。未删除的消息,将在一定时间后可重新投递queue.deleteMessage(message.receiptHandle);
本页内容是否解决了您的问题?