By default, a subscription to a Simple Message Queue (formerly MNS) topic receives every message published to that topic. To route messages to different queues based on message tags, assign a message filtering tag to the subscription. Only messages whose tag matches the subscription's filtering tag are pushed to the destination queue.
How it works
Message filtering uses string-based tags to control which messages reach each subscription's destination queue. The routing logic follows two rules:
Tag match: If a subscription has a message filtering tag, only messages with the same tag are pushed to its destination queue.
No tag on subscription: If a subscription has no message filtering tag, all messages are pushed to its destination queue regardless of whether the messages carry tags.
The following diagram shows how Topic 1 routes messages across three subscriptions, each pointing to a different destination queue:

| Subscription | Message filtering tag | Messages pushed to destination queue |
|---|---|---|
| Subscription 1 (Queue 1) | tag-a | Message 1 only (tagged tag-a) |
| Subscription 2 (Queue 2) | tag-b | Message 2 only (tagged tag-b) |
| Subscription 3 (Queue 3) | (none) | All messages (Message 1, Message 2, and Message 3) |
Subscription 3 has no message filtering tag, so it receives every message published to the topic, including messages with tags and messages without tags.
Set up tag-based filtering
This example configures a subscription on Topic A so that only messages tagged tag-a are pushed to Queue B.
Prerequisites
Before you begin, make sure that you have:
A topic (Topic A) and a queue (Queue B) in your MNS instance. See Create a subscription
Step 1: Create a subscription with a message filtering tag
In the Create Subscription panel for Topic A, configure the following fields:
| Field | Value |
|---|---|
| Push Type | Queue |
| Receiver Endpoint | Queue B |
| Message Filtering Tag | tag-a |

Step 2: Publish messages with a matching tag
When you publish messages with an SDK, set the message tag to tag-a so that the message matches the subscription's filter. For complete sample code, see Step 5: Publish a message.
TopicMessage message = new Base64TopicMessage();
// Set the tag to match the subscription's message filtering tag
message.setMessageTag("tag-a");Only messages with the tag-a tag are pushed to Queue B. Messages with a different tag or no tag are not pushed to this subscription's destination queue.
Related topics
Manage topics in the console -- Create and manage subscriptions for your topics.
Publish a message -- Complete Java SDK example for publishing tagged messages to a topic.