Share via


How to configure Microsoft Azure Service Bus

You can read about What is Microsoft Azure Service, In this article you will come to know how to configure Microsoft Azure Service Bus.

  1. Create a Service Namespace
  2. Configure with Visual Studio 2013.
  3. Setup Service Bus Connection string.
    1. Configure connection string using, console application.
    2. Configure connection string using, Cloud Service.
    3. Configure connection string using, Website.

Create a Service Namespace

We need to create a service namespace for using Queues. A service namespace provides the addressing layer with in your application. We need to perform following steps in order to create a new Namespace.

  1. First we need to log on into Azure Management Portal.
  2. On left side in Management Portal there is a menu with name Service Bus, you need to click it.
  3. You need to click on New Button, as show in Figure. http://kamranshahidbutt.com/wp-content/uploads/2015/01/New-Button-Service-Bus-Selection.png
  4. Then you need to select APP SERVICES, SERVICE BUS AND THEN QUEUES as show in Figure. http://kamranshahidbutt.com/wp-content/uploads/2015/01/Service-Bus-Selection.png
  5. When you select Queues, you have two options either you can create QUICK CREATE or CUSTOM CREATE as show in Figure. http://kamranshahidbutt.com/wp-content/uploads/2015/01/Create-a-new-Queue.png
  6. It will take few minutes to activate the Namesapce, after it is activating then you can use it as show in Figure. http://kamranshahidbutt.com/wp-content/uploads/2015/01/Active-status.png
  7. Now we need to get credentials of the Namespace so that we can use it, by clicking the option Connection Information.http://kamranshahidbutt.com/wp-content/uploads/2015/01/Connection-Information.png
  8. You can find SAS key and key name, which you will be use in your application. You need to copy it.http://kamranshahidbutt.com/wp-content/uploads/2015/01/Access-connection-Information1.png

Configure with Visual Studio 2013

  1. You need to create a solution of Visual Studio 2013, console application.
  2. Now we will add a reference of Microsoft Azure Service Bus, for this we will use NuGet Package Manager, because it is an easiest way to add a reference.
  3. You need to click on TOOLS -> NuGet Package Manager -> Manage NuGet Package Manager for solution.http://kamranshahidbutt.com/wp-content/uploads/2015/02/Open-NuGet-Package-Manager.png
  4. Now you need to enter service bus, from the list you need to select Microsoft Azure Service Bus and then click on install button it will automatically download and add all the required references. After installing it close the dialog.http://kamranshahidbutt.com/wp-content/uploads/2015/02/Micrsoft-Azure-Service-Bus-Install.png

Setup Service Bus Connection string

  1. In console application you can put the configuration string into App.config file.
  2. In Microsoft Azure Cloud Service, we can store configuration string into *.csdef and *.cscfg files
  3. In website you will place the configuration string into web.config file.

Configure connection string using, console application

You can configure configuration string by updating App.config file.

<appSettings>
<add key="Microsoft.ServiceBus.ConnectionString" 
value="Endpoint=sb://YourServiceNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YourKey" />
</appSettings>

You need to replace YourServiceNamespace and YourKey.

Configure connection string using, Cloud Service

You can configure configuration string by updating Service Defination (*.csdef) and Service Configuration (*.cscfg) file, as show below.

<ServiceDefinition name="WindowsAzure1">
    <WebRole name="MyRole" vmsize="Small">
        <ConfigurationSettings>
            <Setting name="Microsoft.ServiceBus.ConnectionString" />
        </ConfigurationSettings>
    </WebRole>
</ServiceDefinition>
<ServiceConfiguration serviceName="WindowsAzure1">
    <Role name="MyRole">
        <ConfigurationSettings>
            <Setting name="Microsoft.ServiceBus.ConnectionString" 
                     value="Endpoint=sb://YourServiceNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedSecretValue=YourKey" />
        </ConfigurationSettings>
    </Role>
</ServiceConfiguration>

You need to replace YourServiceNamespace and YourKey.

Configure connection string using, Website

You can configure configuration string by updating web.config file.

<appSettings>
<add key="Microsoft.ServiceBus.ConnectionString" 
value="Endpoint=sb://YourServiceNamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YourKey" />
</appSettings>

You need to replace YourServiceNamespace and YourKey.