Exercise - Create a Service Bus queue and topic
You have an application for the sales team in your global company. Each team member has your app installed on a mobile device to use for sales. An Azure web service hosts the business logic implemented for your application and stores information in Azure SQL Database. Each geographical region has its own instance of the web service.
You've identified the following scenarios for message exchange between the mobile app and the web service:
- Messages that relate to individual sales must be sent to the web service instance in the user's region.
- Messages that relate to sales performance must be sent to all instances of the web service.
You've decided to implement a Service Bus queue for the first use case and a Service Bus topic for the second use case.
In this exercise, in the Azure portal, you'll create a Service Bus namespace that contains a queue, a topic, and subscriptions.
Create a Service Bus namespace
Start by creating the namespace. In Azure Service Bus, a namespace is a container for queues and topics. Each namespace has a unique, fully qualified domain name, with primary and secondary shared access signature (SAS) encryption keys. A sending or receiving component must provide an SAS key to gain access to objects in a namespace.
Sign in to the Azure portal with the same credentials that you used to activate the sandbox.
Under Azure services, select Create a resource.
In the Create a resource pane, enter Service Bus in global search. In the search results, in Service Bus published by Microsoft for Azure, select Create.
In the Create namespace pane, on the Basics tab, enter or select the following values for each setting:
Setting Value Description Project Details Subscription Concierge subscription The subscription in which this new app is created. Resource group [Sandbox resource group name] The name of the resource group in which to create your Service Bus namespace. In this exercise, you'll create the namespace in the resource group that was assigned when you activated the sandbox. Instance Details Namespace name [Globally unique name] Enter a name that is unique in Azure.
If you want to use the format salesteamapp<Company><year>, your namespace name would look like the example salesteamappContoso2022.
Location Select from the dropdown Choose from the free sandbox regions listed after this table. Pricing tier Standard The recommended pricing tier for this exercise.
The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from the following list when you create resources:
- West US 2
- South Central US
- Central US
- East US
- West Europe
- Southeast Asia
- Japan East
- Brazil South
- Australia Southeast
- Central India
Select Review + create.
When validation succeeds, select Create to create your Service Bus namespace.
Create a Service Bus queue
Next, add a queue for messages about individual sales to your namespace:
When deployment is finished, select Go to resource.
On the Service Bus Namespace page, select Queues under Entities on the left menu.
Select + Queue on the command bar.
In the Create queue pane, for Name, enter salesmessages, and then select Create.
When the message queue has been created, salesmessages is listed under Queues at the bottom of the Service Bus namespace pane.
Create a Service Bus topic and subscriptions
You also want to create a topic that will be used for messages that relate to sales performance. Each instance of the business logic web service subscribes to this topic, and each sales performance message will be delivered to all web service subscriptions.
Add a Service Bus topic and subscriptions:
On the left menu, select Topics under Entities in the left menu, and then select + Topic on the command bar.
In the Create topic pane, for Name, enter salesperformancemessages, and then select Create.
When the topic has been created, salesperformancemessages is listed under Topics at the bottom of the Service Bus namespace pane.
You can add or remove subscriptions in queues and topics by using the tabs in the Service Bus namespace, or you can use the Azure portal resource menu. To use the menu option, in the left menu, under Entities, select Topics, and then select salesperformancemessages in the list of topics.
In the salesperformancemessages Service Bus topic pane, in the command bar, select + Subscription.
In the Create subscription pane, for Name, enter Americas. For Max delivery count, enter 100. Select Create.
The salesperformancemessages Service Bus topic appears with the Americas subscription listed in the Subscriptions section at the bottom of the pane.
Next, add a second subscription. In the command bar, select Subscription.
In the Create subscription pane, for Name, enter EuropeAndAsia. For Max delivery count, enter 100. Select Create.
The Subscriptions section of the salesperformancemessages Service Bus topic for your sales team app now lists two subscriptions.
You have built the infrastructure to use Service Bus to increase the resilience of your distributed application. You've created a queue for messages about individual sales, and a topic for messages about sales performance. You've added multiple subscriptions to the topic, so topic messages can be delivered to multiple web services around the world.