>> Learn how to use
Azure Service Bus Topics in this episode of Azure tips and tricks.
You can use Azure Service Bus Topics to
create a solution that uses publish,
subscribe to decouple components.
Applications like mobile apps and APIs,
send messages to Azure Service Bus Topics with different subjects.
Back-end applications subscribe to
message topics and read and delete messages.
This mechanism decouples application components
to make them more available and scalable.
Let's see that in action.
Here in the Azure Portal,
I'll search for Service Bus.
There it is. This creates
a new namespace within Azure Service Bus.
Let's select a resource group.
Now I'll give it a name like this.
Finally, I'll select a pricing tier.
This is fine and create it.
I'll skip to when it is done.
Here is the Service Bus namespace.
This can have queues and topics in it.
Let's see. No topics yet,
so let's create one.
First, I'll give the topic a name like
this and I'll leave the rest as it is and create it.
Here it goes. Let's take a look.
A topic can have one or more subscriptions.
These receive messages that they filter out.
We have none yet so let's create some subscriptions.
First, give it a name.
That's it. I'll put five here.
This is the amount of times that messages in
the subscription can be read before they are deleted.
I'll leave this and create a subscription.
That's it. I'll create another one. Here we go.
This has a different name as it will receive different messages
and set this to five again and create it.
Now we have two subscriptions.
The subscriptions don't filter on messages yet. Let's take a look.
Subscriptions can have filters that
determine which messages they receive.
Let's create one. A filter also needs a name like this.
You can use a SQL-like language to filter or do this
where you filter on properties of
the message like the label property.
This will filter on the value post.
That's good. This one has a filter now.
Let's go back to the subscription.
Let's create a filter for the video subscription as well.
Here we go.. Create it and give it a name again.
I'll pick this filter type.
Again, we will filter on label but
now on the value video. That's it.
Let's save this and then we'll have
a topic with subscriptions and filters.
Let's go back to the topic and test
it with this Service Bus Explorer.
Here, we'll first send a message to the topic.
A plain text one with this message content in it.
Now for the label,
this one is post.
The subscription will filter on that and send.
Let's send another message.
Again, choose plain text and
with a different message content this time.
Again, I need to set the label.
This time it will have
the video value and that's it. Let's send it.
Messages on the topic stay there until they are deleted or expire.
I could also peek at them which leaves them on the topic.
Here, let's select the post subscription.
As you can see, this one has one message which is
correct because we sent one message with post in the label.
Peek it and it stays on the subscription queue.
This is the post message including the label. Let's receive.
Now I'll select the video subscription.
This also has one message on it which is correct.
When I receive it,
I execute a receive and delete operation
which gets the message and removes it from the subscription queue.
See, no messages on the queue.
Here is the message and it is the video message,
including the label value.
Cool. You can use Azure Service Bus Topics,
to create a scalable publish-subscribe architecture.
Go and check it out.