In this article, you will learn configuring service bus queue in azure portal and sending, receiving and peeking messages.
In this article, you will learn configuring service bus queue in azure portal and sending, receiving and peeking messages. To start with, you just need an Azure portal subscription – Trial or Paid. We will go step-by-step.
In service bus queue, message stored in queue and both sender and receiver work separately with their own processing rate.
Go to Azure portal and click on new resource.
Search for “Service Bus” and select service bus template.
Template to create Service bus opens up. Click on Create.
Now create namespace for service bus.
Your input will be go through validation process and input is validated.
Click “Create” to create this resource. Once deployment is completed, you will see this below dashboard.
Now click on “Queue” to create a service bus queue.
You can find this queue on dashboard as below.
Or you can click on “Queue” or “Topic from side navigation.
You will find overview of Queue with many other options. Now click on “Shared access policies” tab, you will find a predefined key “RootManageSharedAccessKey” with all policy selected i.e. managed, send and listen. Primary connection string can be used to connect service bus using Visual Studio.
Now click on this queue. Here you will find options to create shared access policies for send, listen and manage. Click on “Shared access policies” and click “Add”.
A screen will open having options to create SAS polies.
Here we created two policies i.e. for send and listen.
Now click on “Service Bus Explorer” option.
Here you will see message summary – active, dead-lettered and scheduled each having message count. You will also see tabs like “Send”, “Receive” and “Peek” with “Send” as default selected.
To send message select content type (Text/Plain, Application/XML or Application/JSON) and type message. You can also add custom attribute to send in message. Click on “Send” button to send message.
Once you press send, you will notice that count of active message increase to 1. Now click on “Receive” tab to receive message. Receive message button will receive one message at a time and will delete message from queue after you receive it. Click on “Receive” to receive message.
“Receive performs a destructive read (ReceiveAndDelete) from Queue and the message received will be deleted from the Queue. Messages shown here are no longer stored.”
You will get a message that message will be deleted once you confirm, press “Yes” and continue.
You will get this screen. Here you can notice that active message count is 0 now. Below you can see message. Click on it to view the message.
I sent one more message of application/json format. Let see how it react.
Click on “Receive” to receive message.
You can also peek messages (upto 32 messages at a time) to see preview of messages. Here I sent 2 messages of different type and clicked on “Peek” to peek these message. Now I can view them one by one. I can also receive it when required.
Now let’s receive it. Please note that receive works on FIFO (First in First Out). I created a plain test message first and then json message, so message of sequence number 4 should be received first that is plain text message. Here notice that active message count decrease to 1 from 2 and you can see test message in right side pane.
Hope this is clear now. In the next article, we will try to implement this in C# code.