Hey, everyone.
And welcome back.
Now, in today's video, we are going to discuss about the SNS topic filtering.
Now, in the default settings, whenever you send a message to the next topic, the message is forwarded
to all of the subscriber endpoints.
For example, let's say that you have sent a hello world message to the topic, and at this stage there
are two subscribers.
You have a broad rescue and the device rescue.
So this Helloworld message will go to both the prod as well as the dev.
Q So this is the default way in which the sense works.
However, sometimes in real world scenarios there are many use cases in which, depending upon the type
of message that is received at the SNS level, you might want to send it to a selective queue.
For example, let's say some production related message has received to the SMS topic.
You want that message to go to the production queue.
Similarly, some development related message has come to the sense you want it to go to the development
queue.
So this is what is referred to as the sense message filtering.
Now, in order to achieve the sense filtering, you need to create a filter policy.
Filter policy is a basic JSON object which contains the properties that define the message that each
subscriber receives.
For example, in this sense you see there are certain filter policy.
First one is Alice, second one is Bob.
So, Alice, whenever a message of Alice is received, this message goes to the priority queue.
Similarly, whenever a message of Bob is received, it goes to the normal queue.
For example, this time a message of Alice is received at an SAS level.
SNS will go ahead and check its filter policy.
In the filter policy, it has determined that Alice message should go to the priority queue and hence
it will go to the priority queue.
This message will not be forwarded to the normal queue, so this is one of the use cases that can be
achieved using the SAS filtering.
So let's go ahead and look into this practically.
Now for today's demo I have a SAS topic called S first SAS topic and I have two set of queues.
One is the priority queue and second one is the normal queue.
Now if I look into the SAS topic over here, there are two subscriptions associated with to queue.
You have a priority queue subscription, you have the normal queue subscription.
Now in the priority queue subscription, there is a subscription filter policy where it states that
in a message, if it sees an attribute of customer type as either priority gold or platinum, then that
message will go to the priority queue.
Similarly, if we open up the second subscription here, the customer type is normal.
So whenever a message attribute of customer type of normal is received, then SNS will send it to the
normal queue.
All right, so this is the basics.
Let's go ahead and look into how this would look like practically.
So let's go to the topic.
Let's quickly publish a message.
I'll just say test message.
Let's go a bit down in the message attribute, you can go ahead and specify the customer type.
I'll say gold and I'll publish the message.
All right.
Now, if we refresh the skills queue this time you see the message has received at priority queue level.
No message is available at normal queue.
In fact, let me refresh to verify and yes, no message has been received at normal queue.
Similarly, let's go ahead and publish one more test message.
This time we'll say customer type as normal.
Let's publish a message.
Now, this message should go to the normal queue.
Now, if I refresh, you see, one message has been received here.
Great.
So I hope for this at a high level overview.
You understood the basics of sense filtering.
Again, we have taken a very simple use case.
Depending upon the use case, it can be much more complex and based on that, the filter policy can
also be much more complex.
However, this is the basics and with this will conclude today's video.