You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/service-bus-dotnet-multi-tier-app-using-service-bus-queues.md
+28-35Lines changed: 28 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ ms.custom: devx-track-csharp
11
11
12
12
Developing for Microsoft Azure is easy using Visual Studio and the free Azure SDK for .NET. This tutorial walks you through the steps to create an application that uses multiple Azure resources running in your local environment.
13
13
14
-
You will learn the following:
14
+
You'll learn the following:
15
15
16
16
* How to enable your computer for Azure development with a
In this tutorial, you'll build and run the multi-tier application in an Azure cloud service. The front end is an ASP.NET MVC web role and the back end is a worker-role that uses a Service Bus queue. You can create the same multi-tier application with the front end as a web project, that is deployed to an Azure website instead of a cloud service. You can also try out the [.NET on-premises/cloud hybrid application](../azure-relay/service-bus-dotnet-hybrid-app-using-service-bus-relay.md) tutorial.
25
+
In this tutorial, you'll build and run the multi-tier application in an Azure cloud service. The front end is an ASP.NET MVC web role and the back end is a worker-role that uses a Service Bus queue. You can create the same multi-tier application with the front end as a web project that is deployed to an Azure website instead of a cloud service. You can also try out the [.NET on-premises/cloud hybrid application](../azure-relay/service-bus-dotnet-hybrid-app-using-service-bus-relay.md) tutorial.
26
26
27
27
The following screenshot shows the completed application.
28
28
@@ -36,7 +36,7 @@ the communication between the tiers.
36
36
37
37
Using Service Bus messaging between the web and middle tiers decouples the
38
38
two components. In contrast to direct messaging (that is, TCP or HTTP),
39
-
the web tier does not connect to the middle tier directly; instead it
39
+
the web tier doesn't connect to the middle tier directly; instead it
40
40
pushes units of work, as messages, into Service Bus, which reliably
41
41
retains them until the middle tier is ready to consume and process them.
42
42
@@ -49,19 +49,12 @@ configured with filter rules that restrict the set of messages passed to
49
49
the subscription queue to those that match the filter. The following example uses
50
50
Service Bus queues.
51
51
52
-
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-100.png" alt-text="Diagram showing the communication between the Web Role, the Service Bus, and the Worker Role.":::
52
+
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-100.png" alt-text="Diagram showing the communication between the Web Role, Service Bus, and the Worker Role.":::
53
53
54
54
This communication mechanism has several advantages over direct
55
55
messaging:
56
56
57
-
***Temporal decoupling.** With the asynchronous messaging pattern,
58
-
producers and consumers need not be online at the same time. Service
59
-
Bus reliably stores messages until the consuming party is ready to
60
-
receive them. This enables the components of the distributed
61
-
application to be disconnected, either voluntarily, for example, for
62
-
maintenance, or due to a component crash, without impacting the
63
-
system as a whole. Furthermore, the consuming application might only
64
-
need to come online during certain times of the day.
57
+
***Temporal decoupling.** When you use the asynchronous messaging pattern, producers and consumers don't need to be online at the same time. Service Bus reliably stores messages until the consuming party is ready to receive them. This enables the components of the distributed application to be disconnected, either voluntarily, for example, for maintenance, or due to a component crash, without impacting the system as a whole. Furthermore, the consuming application might only need to come online during certain times of the day.
65
58
***Load leveling.** In many applications, system load varies over
66
59
time, while the processing time required for each unit of work is
67
60
typically constant. Intermediating message producers and consumers
@@ -73,7 +66,7 @@ messaging:
73
66
added to read from the queue. Each message is processed by only one
74
67
of the worker processes. Furthermore, this pull-based load balancing
75
68
enables optimal use of the worker machines even if the
76
-
worker machines differ in terms of processing power, as they will
69
+
worker machines differ in terms of processing power, as they'll
77
70
pull messages at their own maximum rate. This pattern is often
78
71
termed the *competing consumer* pattern.
79
72
@@ -107,12 +100,12 @@ queue and displays status information about the queue.
107
100
### Create the project
108
101
109
102
1. Using administrator privileges, start Visual
110
-
Studio: right-click the **Visual Studio** program icon, and then click**Run as administrator**. The Azure Compute Emulator,
103
+
Studio: right-click the **Visual Studio** program icon, and then select**Run as administrator**. The Azure Compute Emulator,
111
104
discussed later in this article, requires that Visual Studio be
112
105
started with administrator privileges.
113
106
114
-
In Visual Studio, on the **File** menu, click**New**, and then
115
-
click**Project**.
107
+
In Visual Studio, on the **File** menu, select**New**, and then
108
+
select**Project**.
116
109
2. On the **Templates** page, follow these steps:
117
110
1. Select **C#** for programming language.
118
111
1. Select **Cloud** for the project type.
@@ -126,24 +119,24 @@ queue and displays status information about the queue.
126
119
1. On the **Roles** page, double-click **ASP.NET Web Role**, and select **OK**.
127
120
128
121
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-11.png" alt-text="Select Web Role":::
129
-
4. Hover over **WebRole1** under **Azure Cloud Service solution**, click
130
-
the pencil icon, and rename the web role to **FrontendWebRole**. Then click**OK**. (Make sure you enter "Frontend" with a lower-case 'e,' not "FrontEnd".)
122
+
4. Hover over **WebRole1** under **Azure Cloud Service solution**, select
123
+
the pencil icon, and rename the web role to **FrontendWebRole**. Then select**OK**. (Make sure you enter "Frontend" with a lower-case 'e,' not "FrontEnd".)
131
124
132
125
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-02.png" alt-text="Screenshot of the New Microsoft Azure Cloud Service dialog box with the solution renamed to FrontendWebRole.":::
133
126
5. In the **Create a new ASP.NET Web Application** dialog box, select **MVC**, and then select **Create**.
134
127
135
128
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-12.png" alt-text="Screenshot of the New ASP.NET Project dialog box with MVC highlighted and outlined in red and the Change Authentication option outlined in red.":::
136
-
8. In **Solution Explorer**, in the **FrontendWebRole** project, right-click **References**, then click
129
+
8. In **Solution Explorer**, in the **FrontendWebRole** project, right-click **References**, then select
137
130
**Manage NuGet Packages**.
138
-
9.Click the **Browse** tab, then search for **Azure.Messaging.ServiceBus**. Select the **Azure.Messaging.ServiceBus** package, select **Install**, and accept the terms of use.
131
+
9.Select the **Browse** tab, then search for **Azure.Messaging.ServiceBus**. Select the **Azure.Messaging.ServiceBus** package, select **Install**, and accept the terms of use.
139
132
140
133
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-13.png" alt-text="Screenshot of the Manage NuGet Packages dialog box with the Azure.Messaging.ServiceBus highlighted and the Install option outlined in red.":::
141
134
142
135
Note that the required client assemblies are now referenced and some new code files have been added.
143
136
10. Follow the same steps to add the `Azure.Identity` NuGet package to the project.
144
-
10. In **Solution Explorer**, expand **FronendWebRole**, right-click **Models** and click**Add**,
145
-
then click**Class**. In the **Name** box, type the name
146
-
**OnlineOrder.cs**. Then click**Add**.
137
+
10. In **Solution Explorer**, expand **FronendWebRole**, right-click **Models** and select**Add**,
138
+
then select**Class**. In the **Name** box, type the name
139
+
**OnlineOrder.cs**. Then select**Add**.
147
140
148
141
### Write the code for your web role
149
142
In this section, you create the various pages that your application displays.
@@ -224,7 +217,7 @@ In this section, you create the various pages that your application displays.
224
217
}
225
218
}
226
219
```
227
-
4. From the **Build** menu, click**Build Solution** to test the accuracy of your work so far.
220
+
4. From the **Build** menu, select**Build Solution** to test the accuracy of your work so far.
228
221
5. Now, create the view for the `Submit()` method you
229
222
created earlier. Right-click within the `Submit()` method (the overload of `Submit()` that takes no parameters) in the **HomeController.cs** file, and then choose **Add View**.
230
223
6. In the **Add New Scaffolded Item** dialog box, select **Add**.
@@ -246,7 +239,7 @@ In this section, you create the various pages that your application displays.
246
239
the queue. In **Solution Explorer**, double-click the
247
240
**Views\Home\Submit.cshtml** file to open it in the Visual Studio
248
241
editor. Add the following line after `<h2>Submit</h2>`. For now,
249
-
the `ViewBag.MessageCount` is empty. You will populate it later.
242
+
the `ViewBag.MessageCount` is empty. You'll populate it later.
250
243
251
244
```html
252
245
<p>Current number of orders in queue waiting to be processed: @ViewBag.MessageCount</p>
@@ -264,8 +257,8 @@ Global.aspx.cs. Finally, update the submission code you
264
257
created earlier in HomeController.cs to actually submit items to a
265
258
Service Bus queue.
266
259
267
-
1. In **Solution Explorer**, right-click **FrontendWebRole** (right-click the project, not the role). Click **Add**, and then click **Class**.
268
-
2. Name the class **QueueConnector.cs**. Click **Add** to create the class.
260
+
1. In **Solution Explorer**, right-click **FrontendWebRole** (right-click the project, not the role). Select **Add**, and then select **Class**.
261
+
2. Name the class **QueueConnector.cs**. Select **Add** to create the class.
269
262
3. Now, add code that encapsulates the connection information and initializes the connection to a Service Bus queue. Replace the entire contents of QueueConnector.cs with the following code, and enter values for `your Service Bus namespace` (your namespace name) and `yourKey`, which is the **primary key** you previously obtained from the Azure portal.
270
263
271
264
```csharp
@@ -362,25 +355,25 @@ Service Bus queue.
362
355
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-app2.png" alt-text="Screenshot of the application's Submit page with the message count incremented to 1.":::
363
356
364
357
## Create the worker role
365
-
You will now create the worker role that processes the order
358
+
You'll now create the worker role that processes the order
366
359
submissions. This example uses the **Worker Role with Service Bus Queue** Visual Studio project template. You already obtained the required credentials from the portal.
367
360
368
361
1. Make sure you have connected Visual Studio to your Azure account.
369
362
2. In Visual Studio, in **Solution Explorer** right-click the
370
363
**Roles** folder under the **MultiTierApp** project.
371
-
3.Click**Add**, and then click**New Worker Role Project**. The **Add New Role Project** dialog box appears.
364
+
3.Select**Add**, and then select**New Worker Role Project**. The **Add New Role Project** dialog box appears.
372
365
373
366
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/SBNewWorkerRole.png" alt-text="Screenshot of the Solution Explorer pane with the New Worker Role Project option and Add option highlighted.":::
374
367
1. In the **Add New Role Project** dialog box, select **Worker Role**. Don't select **Worker Role with Service Bus Queue** as it generates code that uses the legacy Service Bus SDK.
375
368
376
369
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/SBWorkerRole1.png" alt-text="Screenshot of the Ad New Role Project dialog box with the Worker Role with Service Bus Queue option highlighted and outlined in red.":::
377
-
5. In the **Name** box, name the project **OrderProcessingRole**. Then click**Add**.
370
+
5. In the **Name** box, name the project **OrderProcessingRole**. Then select**Add**.
378
371
1. In **Solution Explorer**, right-click **OrderProcessingRole** project, and select **Manage NuGet Packages**.
379
372
9. Select the **Browse** tab, then search for **Azure.Messaging.ServiceBus**. Select the **Azure.Messaging.ServiceBus** package, select **Install**, and accept the terms of use.
380
373
381
374
:::image type="content" source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-13.png" alt-text="Screenshot of the Manage NuGet Packages dialog box with the Azure.Messaging.ServiceBus highlighted and the Install option outlined in red.":::
382
375
1. Follow the same steps to add the `Azure.Identity` NuGet package to the project.
383
-
1. Create an **OnlineOrder** class to represent the orders as you process them from the queue. You can reuse a class you have already created. In **Solution Explorer**, right-click the **OrderProcessingRole** class (right-click the class icon, not the role). Click**Add**, then click**Existing Item**.
376
+
1. Create an **OnlineOrder** class to represent the orders as you process them from the queue. You can reuse a class you have already created. In **Solution Explorer**, right-click the **OrderProcessingRole** class (right-click the class icon, not the role). Select**Add**, then select**Existing Item**.
384
377
1. Browse to the subfolder for **FrontendWebRole\Models**, and then double-click **OnlineOrder.cs** to add it to this project.
385
378
1. Add the following `using` statement to the **WorkerRole.cs** file in the **OrderProcessingRole** project.
386
379
@@ -457,16 +450,16 @@ submissions. This example uses the **Worker Role with Service Bus Queue** Visual
:::imagetype="content"source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-38.png"alt-text="Screenshot of what appears when you click the emulator icon. Show Compute Emulator UI is in the list of options.":::
462
+
:::imagetype="content"source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-38.png"alt-text="Screenshot of what appears when you select the emulator icon. Show Compute Emulator UI is in the list of options.":::
470
463
471
464
:::imagetype="content"source="./media/service-bus-dotnet-multi-tier-app-using-service-bus-queues/getting-started-multi-tier-39.png"alt-text="Screenshot of the Microsoft Azure Compute Emulator (Express) dialog box.":::
0 commit comments