Here you will see how to send a Brokered Message to the Azure Service Bus.
Introduction
In this tutorial, we will write a simple C# program to send a brokered message to the Azure Service Bus. The tools that we'll leverage are Visual Studio 2013, .NET Framework 4.5.2, Microsoft Azure Service Bus client library from NuGet, along with Azure Service Bus namespace, topic and subscription on the Azure Portal.
Step 1: Create a Console Application
Create a Console Application using .NET Framework 4.5.2 and name the solution AzureServiceBus.
Step 2: Setup Namespace, Topic and Subscription on Azure Service Bus
Log into the Azure portal and navigate to the Service Bus as outlined below.
Now create a namespace (for example testnamespace), a topic (for example testtopic) and a subscription (for example testsubscription1) and verify the configuration elements as in the following:
Step 3: Create Sender
The code excerpt to create a sender is outlined below. A token provider is created using key name and access key values. A Messaging Factory object is created by providing a token provider and baseaddress. The sender is created using a messaging factory object.
Also, please note that the token can be created with expiry duration passing TimeSpan input. Feel free to explore the TokenProviderClass in additional detail in MSDN.
Step 4: Build an Object to Send
For this step, let's consider a simple employeeobject with three fields (EmpId, EmpName and Date Of Hire) to show the process and populate the object with sample values as in the following.
Send a brokered message using the sender object, in which the brokered message body is filled with a custom object. Calling the send()method will drop your message on the Azure Service Bus and can be verified on a subscription.
Azure Web Apps for Developers