Brokered Messaging in Service Bus with the new Visual Studio Tools

Brokered Messaging in Service Bus with the new Visual Studio Tools

This post is a learning/ inspiration from the presentation by Clemens Vasters and Abhishek Lal at TechEd NA 2012, to view that complete session click here.

On June the 7th 2012 Microsoft announced plethora of new features for their Windows Azure platform- the all new portal, the IaaS feature, the web sites feature to name few. Of course to achieve those features developers need the SDK, so on the same day, SDK version 1.7 was also released. First things first this SDK version 1.7 runs side-by-side with earlier SDK (which is 1.6) and this SDK is released for VS 2010 as well as VS 2012 RC.

For starters, from VS tooling point of view there are two new *roles* added to the *Cloud* project template- “Cache Worker Role” and “Worker Role with Service Bus Queue”.

In this blog post I will be walking through a demo of “Worker Role with Service Bus Queue”. We will cover “Cache Worker Role” in the next blog post.

1.  Let’s go ahead and create a File à New à Project. Select *Windows Azure Cloud Service* project template.

2.  Select “Worker Role with Service Bus Queue” for the role.

3.   Once in Visual Studio open up the “Server Explorer” (short cut- Ctrl+W,L). Here you will observer two new items- Windows Azure Service Bus and Windows Azure Virtual Machines. The names are pretty much intuitive.

4.   At this point let’s jump to our portal and create a service bus namespace. Please note that Service Bus portal is still chosen from the older portal.

5.   In Visual Studio right click the “Windows Azure Service Bus” node in “Server Explorer” and select “Add New Connection…”

6.   Copy the respective details from portal into the fields in “Add New Connection” window.

7.   You are now done with the initial settings.  In Visual Studio you can now expand the “namespace” node. Once you do that you can see Queues and Topics in the same way as you would in the portal. The portal becomes redundant beyond this point.

8.   We can do few cools things from here. You can go ahead and create a new ‘queue’ by right-clicking on the queues node. You can set all the options the way you do it on the portal. I created a new queue called “processingqueue”.

9.   Select the queue-name and click F4. The properties windows will open up. In this window notice the value of the ‘message count’ property. It will be zero.

10.   Right-click on the queue-name and select “Send a test message”. This will send a test message to the queue. Likewise you can receive message as well. This cool feature of send and receive allows for quick testing while developing applications. The properties window will now show the messages as one if you did only send.

11.   Let’s send a message to the queue and read it using the APIs and the code generated by the default template.

A.   Right-click on the queue-name and select “Send a test message”.

B.   (Open the solution explorer) In the Solution you will have two projects, one is the cloud project and the second one is the worker role project. The cloud project (titled as WindowsAzure4) would contain roles settings. In this case the worker-role project’s settings.









C.   Select the namespace from the “Server Explorer” and do F4. From the properties window copy the issuer key and the namespace to the connection string.









D.   With this much you are done with reading the messages from the queue. Once you do F5 now, the message(s) will be read from the queue. You can cross check this by selecting the queue from the Server Explorer and checking its “Message Count” property.

Conclusion: Architecting your application using Service Bus Queue is certainly not a new feature it was there since last two years, what’s new is the tooling support for Visual Studio added in this SDK version 1.7. It makes the life of a developer much easier.

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.