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
## Get connection string to the namespace (Azure portal)
14
+
Creating a new namespace automatically generates an initial Shared Access Signature (SAS) policy with primary and secondary keys, and primary and secondary connection strings that each grant full control over all aspects of the namespace. See [Service Bus authentication and authorization](../service-bus-authentication-and-authorization.md) for information about how to create rules with more constrained rights for regular senders and receivers.
15
+
16
+
A client can use the connection string to connect to the Service Bus namespace. To copy the primary connection string for your namespace, follow these steps:
17
+
18
+
1. On the **Service Bus Namespace** page, select **Shared access policies** on the left menu.
19
+
3. On the **Shared access policies** page, select **RootManageSharedAccessKey**.
20
+
4. In the **Policy: RootManageSharedAccessKey** window, select the copy button next to **Primary Connection String**, to copy the connection string to your clipboard for later use. Paste this value into Notepad or some other temporary location.
21
+
22
+
:::image type="content" source="./media/service-bus-create-namespace-portal/connection-string.png" lightbox="./media/service-bus-create-namespace-portal/connection-string.png" alt-text="Screenshot shows an S A S policy called RootManageSharedAccessKey, which includes keys and connection strings.":::
23
+
24
+
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/service-bus-dotnet-multi-tier-app-using-service-bus-queues.md
+30-35Lines changed: 30 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
@@ -95,6 +88,8 @@ The first step is to create a *namespace*, and obtain a [Shared Access Signature
In this section, you build the front end of your application. First, you
@@ -105,12 +100,12 @@ queue and displays status information about the queue.
105
100
### Create the project
106
101
107
102
1. Using administrator privileges, start Visual
108
-
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,
109
104
discussed later in this article, requires that Visual Studio be
110
105
started with administrator privileges.
111
106
112
-
In Visual Studio, on the **File** menu, click**New**, and then
113
-
click**Project**.
107
+
In Visual Studio, on the **File** menu, select**New**, and then
108
+
select**Project**.
114
109
2. On the **Templates** page, follow these steps:
115
110
1. Select **C#** for programming language.
116
111
1. Select **Cloud** for the project type.
@@ -124,24 +119,24 @@ queue and displays status information about the queue.
124
119
1. On the **Roles** page, double-click **ASP.NET Web Role**, and select **OK**.
125
120
126
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":::
127
-
4. Hover over **WebRole1** under **Azure Cloud Service solution**, click
128
-
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".)
129
124
130
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.":::
131
126
5. In the **Create a new ASP.NET Web Application** dialog box, select **MVC**, and then select **Create**.
132
127
133
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.":::
134
-
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
135
130
**Manage NuGet Packages**.
136
-
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.
137
132
138
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.":::
139
134
140
135
Note that the required client assemblies are now referenced and some new code files have been added.
141
136
10. Follow the same steps to add the `Azure.Identity` NuGet package to the project.
142
-
10. In **Solution Explorer**, expand **FronendWebRole**, right-click **Models** and click**Add**,
143
-
then click**Class**. In the **Name** box, type the name
144
-
**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**.
145
140
146
141
### Write the code for your web role
147
142
In this section, you create the various pages that your application displays.
@@ -222,7 +217,7 @@ In this section, you create the various pages that your application displays.
222
217
}
223
218
}
224
219
```
225
-
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.
226
221
5. Now, create the view for the `Submit()` method you
227
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**.
228
223
6. In the **Add New Scaffolded Item** dialog box, select **Add**.
@@ -244,7 +239,7 @@ In this section, you create the various pages that your application displays.
244
239
the queue. In **Solution Explorer**, double-click the
245
240
**Views\Home\Submit.cshtml** file to open it in the Visual Studio
246
241
editor. Add the following line after `<h2>Submit</h2>`. For now,
247
-
the `ViewBag.MessageCount` is empty. You will populate it later.
242
+
the `ViewBag.MessageCount` is empty. You'll populate it later.
248
243
249
244
```html
250
245
<p>Current number of orders in queue waiting to be processed: @ViewBag.MessageCount</p>
@@ -262,8 +257,8 @@ Global.aspx.cs. Finally, update the submission code you
262
257
created earlier in HomeController.cs to actually submit items to a
263
258
Service Bus queue.
264
259
265
-
1. In **Solution Explorer**, right-click **FrontendWebRole** (right-click the project, not the role). Click **Add**, and then click **Class**.
266
-
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.
267
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.
268
263
269
264
```csharp
@@ -360,25 +355,25 @@ Service Bus queue.
360
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.":::
361
356
362
357
## Create the worker role
363
-
You will now create the worker role that processes the order
358
+
You'll now create the worker role that processes the order
364
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.
365
360
366
361
1. Make sure you have connected Visual Studio to your Azure account.
367
362
2. In Visual Studio, in **Solution Explorer** right-click the
368
363
**Roles** folder under the **MultiTierApp** project.
369
-
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.
370
365
371
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.":::
372
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.
373
368
374
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.":::
375
-
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**.
376
371
1. In **Solution Explorer**, right-click **OrderProcessingRole** project, and select **Manage NuGet Packages**.
377
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.
378
373
379
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.":::
380
375
1. Follow the same steps to add the `Azure.Identity` NuGet package to the project.
381
-
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**.
382
377
1. Browse to the subfolder for **FrontendWebRole\Models**, and then double-click **OnlineOrder.cs** to add it to this project.
383
378
1. Add the following `using` statement to the **WorkerRole.cs** file in the **OrderProcessingRole** project.
384
379
@@ -455,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.":::
468
463
469
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.":::
After the namespace and topic/subscriptions are provisioned, and you have the necessary credentials, you're ready to create filter rules on the subscriptions, then send and receive messages. You can examine the code in [this GitHub sample folder](https://github.com/Azure/azure-service-bus/tree/master/samples/Java/azure-servicebus/TopicFilters).
50
+
After the namespace and topic/subscriptions are provisioned, and you have the connection string to the namespace, you're ready to create filter rules on the subscriptions, then send and receive messages. You can examine the code in [this GitHub sample folder](https://github.com/Azure/azure-service-bus/tree/master/samples/Java/azure-servicebus/TopicFilters).
48
51
49
52
## Send and receive messages
50
53
@@ -58,7 +61,7 @@ To run the code, follow these steps:
58
61
59
62
2. Navigate to the sample folder `azure-service-bus\samples\DotNet\Azure.Messaging.ServiceBus\BasicSendReceiveTutorialWithFilters`.
60
63
61
-
3. Obtain the connection string you copied to Notepad in the Obtain the management credentials section of this tutorial. You also need the name of the topic you created in the previous section.
64
+
3. Obtain the connection string you copied to Notepad earlier in this tutorial. You also need the name of the topic you created in the previous section.
62
65
63
66
4. At the command prompt, type the following command:
0 commit comments