How to use Azure Service bus Queues

How to use Azure Service bus Queues

In this article, we will discuss What are Azure service bus queues and how to use Azure service bus queues in real-time. Along with that, we will discuss a few other topics as mentioned below.

What are Azure Service bus Queues?

Queues are the main concepts of Azure Service Bus.

Azure Service bus Queues are part of the Azure messaging service that supports queueing mechanisms. Messages will be in a queue and then will be processed with the First-in-first-out mechanism.

azure service bus queue architecture

Note that Azure Service bus Queues are different than Azure Storage Queues. You can check out Azure Storage Queue vs Service Bus to know the key differences between both of them.

How to use Azure Service bus Queues

To use the Azure Service bus Queues we need to perform the below steps.

  1. Create Azure Service bus namespace
  2. Creating a Queue in the Service bus namespace
  3. Sending a message to the Queue
  4. Peeking a message from the Queue
  5. Receiving a message from the Queue

Now, to use the Azure Service bus Queues, the first thing we need to create the Azure Service bus namespace.

Related: Azure service bus pricing

How to create Azure Service bus namespace

Well, it is so simple to create an Azure Service bus namespace in Azure Portal using the below steps.

  1. Log in to the Azure Portal.
  2. Search for Service bus and click on the search result Service Bus under Services.
How to create Azure Service bus

3. Click on the + Create button on the Service Bus page or you can click on the Create service bus namespace button to create a service bus namespace.

how to use azure service bus
how to use service bus in Azure

4. On the Create namespace page, select the Basics tab and then provide the below details

  • Subscription: Select a valid Azure Subscription.
  • Resource Group: Click on the Create new link to create a new Resource Group or you can select an existing Resource Group.
  • Namespace name: Provide a unique name for your Service bus namespace.
  • Location: Choose the location or Region,
  • Pricing tier: Choose the Pricing tier based on your requirement, You can click on the “Browse the available plans and their features” link to check out all the pricing tiers and then choose the one that best suits your requirement.

Leave all the values in the other tabs as it is and then click on the Review + Create button.

How to create Azure Service bus namespace

5. Now, the system will validate all the details entered by you, and then once all the details are valid, it will show you Validation Succeeded and the Create button will get enabled. Click on the Create button to create the Azure Service bus namespace.

create Azure Service bus namespace

6. Click on the Go to Resource button to navigate to the Azure Service bus namespace.

what is service bus in azure

A namespace contains the Queues, So let’s create a Queue in the namespace.

Creating a Queue in the Service bus namespace

To create the queue in the Service bus namespace follow the below steps

7. On the Service Bus Namespace page, click on the + Queue button.

Creating a Queue in the Service bus namespace

8. On the Create queue window, provide the below details.

  • Name: Provide a unique name for the Queue.
  • Max queue Size: Specify a max queue size.
  • Max delivery count: Specify the maximum delivery count.
  • Enable the other features like “Enable duplicate detection”, “Enable auto-delete on idle queue”, etc based on your requirement.

Finally, click on the Create button to create the queue inside the Service bus namespace.

How to Create a Queue in the Service bus namespace

9. To find the Queue you have created at the last step, Click on the Queues link from the left navigation on the Service Bus Namespace page.

How to Create a Queue in Service bus namespace

Sending a message to the Queue

Now that our Queue is ready so as a next step, I will send a message to the Queue I have created.

10. Click on the Queue that we have created above.

11. On the Queue page, click on the Service Bus Explorer (Preview) from the left navigation –> Then click on the Send messages button as highlighted below.

How to send a message to the Service Bus Queue

12. On the Send messages window, Type a message in the Message Body, Choose a content type (For example text/plain) –> then click on the Send button.

How to send a message to the Azure Service Bus Queue

Expand the Broker Properties, Specify a label or subject. You can also Specify the values for all other properties based on your need.

Finally, click on the Send button to send a message to the Service bus Queue.

How to send a message to Service Bus Queue

Peeking a message from the Queue

13. On the Service Bus Queue page, select the Peek mode, Click peek from start or click on the Peek next messages to peek the next messages or even you can click on the Peek with options button.

How to Peek messages in Azure Service Bus Queue

Once, you will click on the Peek with options, on the Settings window, specify the number of messages to peek and the sequence number to peek from, and then click on the Peek button.

How to Peek messages in Service Bus Queue in Azure

Receiving a message from the Queue

14. Now, the next job is to receive the message, So for that Select, the Receive mode, and click on the Receive messages button.

How to receive messages in Azure Service Bus Queue

On the Settings window, Select Receive mode, Specify the number of messages to receive and specify the Max time to wait for a message in ms and then click on the Receive button, and you are done.

How to receive a message in Azure Service Bus Queue

You may also like following the below articles

Conclusion

We have discussed What is Azure service bus queues, How to create Azure Service bus namespace, and how to use Azure service bus queues in real-time. Thanks for reading this article !!!