Advanced message filtering
Advanced message filtering
In the previous section, you explored basic message filtering using string comparisons and demonstrated SNS routing behavior using different message property configurations to verify message delivery. Next, you’ll expand on basic message filtering using additional comparison techniques.
We will create an Amazon SQS queue as Orders-XL
-
Access the interface SQS

- For queue name enter
Orders-XL

- Select Create queue

- Create Orders-XL

- Click the SNS subscriptions tab.
- Click Subscribe to Amazon SNS topic.
- Click on Orders topic.
- Click Save

- Verify Orders-XL SQS queue successfully subscriber Orders SNS Topic and select OK.

-
We will create the Orders-XL subscription filter policy.
- Go to SNS
- Select Orders
- In the Orders interface
- Search Orders-XL to find Orders-XL SQS queue subscription

- Select Orders-XL subscription and select Edit

- Make edits Subscription filter policy
{
"quantity": [
{
"numeric": [ ">=", 100 ]
}
]
}

-
Finish editing Subscription filter policy

-
Make another Orders-X-EU.
- Go to SQS
- Select Create queue

- Enter
Orders-XL-EU
for the queue name.

- Select Create queue

- Select Subscribe Queue to SNS Topic.

-
From Choose a Topic,
- Select Orders topic
- Select Save

- Confirmation Orders-XL-EU SQS queue successfully registered Order SNS Topic

- Select Orders-XL-EU SQS queue subscription

- Edit Subscription filter policy
{
"location": [
{ "prefix": "eu" }
],
"quantity": [
{
"numeric": [ ">=", 100 ]
}
]
}

- Finish editing Subscription filter policy

Message 1: Non-matching numeric message attributes
-
Go to Event Generator
- Select Add attribute
- Type, select Number
- Name, enter
quantity
- Value, enter
50
- Select PUBLISH EVENT to push messages to Orders SNS topic.

Message 2: Matching numeric message attributes
- Change quantity attribute to 100. Then select PUBLISH EVENT to push the message to Orders SNS topic

Message 3: Matching AND comparison message attributes
-
We will add the attribute
- Select Add attribute
- For Type, choose String
- For Name, enter location
- For Value, enter eu-west
- Select PUBLISH EVENT to push messages to Orders SNS topic.

-
Verify sent messages
- Go to SQS
- Observe Messages Available:
- OrdersQueue, there will be 3 messages because Orders subscription does not filter messages by policy.
- Orders-EU queue will have 1 message because there is a push message with location = eu-west.
- Orders-XL queue has 2 messages because there are 2 push messages with quantity = 100
- Orders-XL-EU queue will have 1 message because there is 1 push message with quantity = 100 and location = eu-west.

Congratulations! You have successfully used the subscription filter to route published messages to the SNS topic subscription and verified that it was delivered to the correct SQS queue.