In this how-to i will explain with a sample application how we can do some messaging with Azure Queues.
First we need to create a Service Bus Namespace on the Azure Portal. For the moment we need to use the old portal.
We can’t do it on the new portal….
Click in the dashboard in the menu on the left on the “Service Bus” item, click then on the “Create a new namespace” link.
Then you should see the following screen.
Fill in an unique namespace name, the Region for deployment, the type ( we need the messaging for our queue ) also select the messaging Tier ( see the following link for the pricing ).
After some time your service bus namespace is available
You can click on the namespace, this will open the main dashboard.
Now we can start building the solution in Visual Studio (2013).
First we need to add the “ServiceBus” reference to our project. You can do this with the Nuget Package Manager.
He creates also an “App.config” file. You need to change the connectionstring with the one from the dashboard.
You can get it when you click on the following icon in the Azure dashboard
You can also install it with the Nuget Package Manager Console. Just use the following command
Just copy the full connection string under the SAS heading to your “App.config”.
It should be something like this…
We use a couple methods, below i will describe them all..
The following method will create our queue. Also we delete the queue when it exists….In the following method we will send the message. First we create a new message with “BrokeredMessage” after that we try to send it to our queue… In the following method we will receive the message. He tries to receive a message within 5 second. When i don’t find any message anymore means the queue is emtpy. When he finds a message we will mark is as complete. Then it will be deleted from our queue… Then we also have our main method. This will call the other methods…. You can also find the source code on my [Github](https://github.com/SvenVandenbrande/CodeExamples.git) –> QueueExample
Have fun with it… If you have a problem. Ping me on twitter or send a comment on this post.