tencent cloud

TDMQ for RocketMQ

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Introduction and Selection of the TDMQ Product Series
What Is TDMQ for RocketMQ
Strengths
Scenarios
Product Series
Comparison with Open-Source RocketMQ
High Availability
Quotas and Limits
Supported Regions
Basic Concepts
Billing
Billing Overview
Pricing
Billing Examples
Pay-as-you-go Switch to Monthly Subscription (5.x)
Renewal
Viewing Consumption Details
Refund
Overdue Payments
Getting Started
Getting Started Guide
Preparations
Step 1: Creating TDMQ for RocketMQ Resources
Step 2: Using the SDK to Send and Receive Messages (Recommended)
Step 2: Running the TDMQ for RocketMQ Client (Optional)
Step 3: Querying Messages
Step 4: Deleting Resources
User Guide
Usage Process Guide
Configuring Account Permissions
Creating the Cluster
Configuring the Namespace
Configuring the Topic
Configuring the Group
Connecting to the Cluster
Managing Messages
Managing the Cluster
Viewing Monitoring Data and Configuring Alarms
Cross-Cluster Message Replication
Use Cases
Naming Conventions for Common Concepts of TDMQ for RocketMQ
RocketMQ Client Use Cases
RocketMQ Performance Load Testing and Capacity Assessment
Access over HTTP
Client Risk Descriptions and Update Guide
Migration Guide for TencentCloud API Operations Related to RocketMQ 4.x Cluster Roles
Migration Guide
Disruptive Migration
Seamless Migration
Developer Guide
Message Types
Message Filtering
Message Retries
POP Consumption Mode (5.x)
Clustering Consumption and Broadcasting Consumption
Subscription Relationship Consistency
Traffic Throttling
​​API Reference(5.x)
History
API Category
Making API Requests
Topic APIs
Consumer Group APIs
Message APIs
Role Authentication APIs
Hitless Migration APIs
Cloud Migration APIs
Cluster APIs
Data Types
Error Codes
​​API Reference(4.x)
SDK Reference
SDK Overview
5.x SDK
4.x SDK
Security and Compliance
Permission Management
CloudAudit
Deletion Protection
FAQs
4.x Instance FAQs
Agreements
TDMQ for RocketMQ Service Level Agreement
Contact Us

Sending and Receiving Filtered Messages

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-01-23 17:52:24

Scenarios

This document uses the Spring Boot Starter SDK as an example to describe how to send and receive messages through an open-source software development kit (SDK), helping you better understand the whole process of sending and receiving filtered messages.

Prerequisites

You have obtained the client connection parameters as instructed in SDK Overview.

Operation Steps

Sending Messages

Similar to sending normal messages, you only need to concatenate the tag to the sending topic in the rocketMQTemplate method.

// Spring Boot does not support passing tags using headers. As required, tags must be concatenated after the topic in the format of topicName:tags. No concatenation identifier indicates no tags. String destination = StringUtils.isBlank(tags) ? topic : topic + ":" + tags; // Object message type. SendResult sendResult = rocketMQTemplate.syncSend(destination, MessageBuilder.withPayload(message) .setHeader(MessageConst.PROPERTY_KEYS, "yourKey") // Specify the business key. .build()); System.out.printf("syncSend1 to topic %s sendResult=%s %n", topic, sendResult);
For example, if the topic name is TopicTest and the tag is TAG1, the first parameter for calling the rocketMQTemplate method is TopicTest:TAG1.

Consuming Messages

Set the selectorExpression field to the filter tag. For example, in the following code, set rocketmq.consumer1.subExpression to TAG1 to consume messages of TAG1.
@Service
@RocketMQMessageListener(
consumerGroup = "${rocketmq.namespace}%${rocketmq.consumer1.group}", // Specify the consumer group in the format of full namespace name%group name.
// The full topic name is required. Therefore, concatenate the topic name. You can also set the format yourself: full namespace name%topic name.
topic = "${rocketmq.namespace}%${rocketmq.consumer1.topic}",
selectorExpression = "${rocketmq.consumer1.subExpression}" // Subscription expression. If it is not configured, all messages are subscribed to.
)
public class Tag1Consumer implements RocketMQListener<String> {

@Override
public void onMessage(String message) {
System.out.println("Tag1Consumer receive message:" + message);
}
}


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan