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

  1. Access the interface SQS

    • Select Create New Queue

SQS

  1. For queue name enter Orders-XL

SQS

  1. Select Create queue

SQS

  1. Create Orders-XL

SQS

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

SQS

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

SQS

  1. 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

SQS

  1. Select Orders-XL subscription and select Edit

SQS

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

SQS

  1. Finish editing Subscription filter policy

    • Select Save changes

SQS

  1. Make another Orders-X-EU.

    • Go to SQS
    • Select Create queue

SQS

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

SQS

  1. Select Create queue

SQS

  1. Select Subscribe Queue to SNS Topic.

SQS

  1. From Choose a Topic,

    • Select Orders topic
    • Select Save

SQS

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

SQS

  1. Select Orders-XL-EU SQS queue subscription

SQS

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

SQS

  1. Finish editing Subscription filter policy

SQS

Message 1: Non-matching numeric message attributes

  1. 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.

SQS

Message 2: Matching numeric message attributes

  1. Change quantity attribute to 100. Then select PUBLISH EVENT to push the message to Orders SNS topic

SQS

Message 3: Matching AND comparison message attributes

  1. 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.

SQS

  1. 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.

SQS

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.