AWS SNS message filtering to receive a subset of topic messages.
Tutorial Objectives:
1. Learn to use SNS message filtering
2. Learn to implement fanout messaging pattern using SNS & SQS
Step 1: Open AWS Management Console and open Amazon SNS service console.
Give topic name as Insurance-Quote-Requests and click Next step.
Choose Type: Standard and Create topic.
The new topic appears on Topic details page.
Step 2: Open Amazon SQS service console in new window and click Create queue.
Leave Standard queue selected and name the queue as Vehicle-Insurance-Quotes.
Scroll down and click Create queue.
Similarly create two additional queues named as Life-Insurance-Quotes and All-Quotes.
All three queues are now listed in the SQS console.
Step 3: Select the All-Quotes queue, click Actions and select Subscribe to Amazon SNS topic.
From the dropdown, select Insurance-Quote-Requests topic and click Save.
Follow same step for Life-Insurance-Quotes and Vehicle-Insurance-Quotes to subscribe to topic.
Step 4: Return to the Amazon SNS console tab and click on Topics.
Click on the topic name Insurance-Quote-Requests.
Scroll down you will be able to see all SQS queues subscribed to this SNS topic. Select Vehicle-Insurance-Quotes queue then click Edit.
This will take you to the Edit subscription page. Click on the arrow to edit subscription filter policy.
On the dialog box displayed, enter the following JSON object:
{"insurance_type": ["car", "boat"]}
Click Save changes.
Now, repeat the process add filter policy to the second queue. Select the Life-Insurance-Quotes queue, click Edit.
On the dialog box displayed, enter the following JSON object:
{"insurance_type": ["life"]}
Click Save changes.
All-Quotes queue will catch all events published to the topic. So, there is no need to set filter policy for the subscription related to the All-Quotes queue.
Step 5: On the Insurance-Quotes-Requests Topic page, click on Publish message.
Create the first message by entering the following values in the form:
· In Subject, enter: Insurance Quote Request #1
· In Message structure, leave Identical payload for all delivery protocols selected
· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: 2017 Volvo S60, Montreal
· In Message attributes:
· Select String in the Type field
· Enter insurance_type in the Name field
· Enter car in the Value field
· Click Publish message.
You are returned to the Insurance-Quote-Requests Topic page. Click on Publish message again, and create a second message using the following values:
· In Subject, enter: Insurance Quote Request #2
· In Message structure, leave Identical payload for all delivery protocols selected
· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: Male, 33 years old, Vancouver
· In Message attributes:
· Select String in the Type field
· Enter insurance_type in the Name field
· Enter life in the Value field
· Click Publish message.
You are returned to the Insurance-Quote-Requests Topic page. Click on Publish message again, and create a third message using the following values:
· In Subject, enter: Insurance Quote Request #3
· In Message structure, leave Identical payload for all delivery protocols selected
· In Message body to send to the endpoint, enter the following text to represent a car insurance quote request: Townhouse, 1500 sq ft, Toronto
· In Message attributes:
· Select String in the Type field
· Enter insurance_type in the Name field
· Enter home in the Value field
· Click Publish message.
Step 6: Return to Amazon SQS console. Select the Vehicle-Insurance-Quotes queue, and click on Send and receive messages.
Scroll down and click Poll for messages.
Click to the Message ID
Note that only one message was pushed into this queue, related to that car insurance quote (Insurance Quote Request #1). Close the dialog box.
Repeat the process for the second queue. Select the Life-Insurance-Quotes queue, and click on Send and receive messages.
Scroll down and click Poll for messages.
Click to the Message ID.
Note that another message was pushed into this queue, related to that life insurance quote (Insurance Quote Request #2).
Finally, Select the All-Quotes queue, Click Start Polling for Messages.
Step 7: Delete all the resources.
· Delete the subscription and then delete all the queues.
· Delete the topic.
Was this document helpful? How can we make this document better? Please provide your insights. You can download PDF version for reference.
We provide the best AWS training from Pune, India.
For aws certification contact us now.
Easy to understand..very well explained!
Easy to understand
Easy to understand
Well explained
Very useful sir