Microsoft Azure Service Bus – C#

Currently fiddling with the Service Bus and Queues. In the process of seeing if this would be a better way to send data to Azure. So how does one programmatically communicate with a Service Bus Queue?

There are a few things that one would need.

  1. A Microsoft Azure subscription. For this, go to www.windowsazure.com and subscribe.
  2. A Service Bus and Queue (although I will need to create the queue programmatically)
  3. Visual Studio and some C# skills.

So, what will be done is to create a Service Bus on your azure subscription.

And that bus will have its properties, take note of the connection string.

Then fire up Visual Studio and create a new project. A console project will do. Nothing fancy here, just need to establish communication to the Queue by sending some stuff and then retrieving them right after.

You will need to add some references to access the ServiceBus namespace J

 

And once you have those in place, you can proceed to coding this out. Now would be a good time to fix up the references

So, what object would you need to “talk” to the Queue? Well, common sense would dictate that you would need a “message” to send before attempting to talk to the queue right? It appears to be a bit of too many pieces, but these could all be “managed” right? So.. Microsoft.ServiceBus.NamespaceManager would do us well..

How to programmatically create a Queue on Microsoft Azure using C#.

I’ll go ahead and create a separate method to programmatically create a Queue on my Azure Subscription using C#.

private
void CreateMyQueue()

{


NamespaceManager MyManager = NamespaceManager.Create();

MyManager.CreateQueue(“TestQueue”);

}

This is simple.. too simple. (always wanted to say that).

And some searching will reveal that there are some other things that one would need to make this work, but sometimes I just like to play around and hit F5 to get to see what I need to do.

Running the app and calling the method should give you this: (not exactly.. there is a surprise here that I am sure you can fix on your own)

“Configuration is missing required information. Make sure the property ‘Endpoint’ is defined as part of ‘Microsoft.ServiceBus.ConnectionString’ key within ‘appSettings’ section, or Windows Azure configuration settings.”

This is as straightforward as it can be. You need to add the servicebus connection string in you appSettings J So..

Retrieving the settings:

Adding it to app.config:

Should allow us to run it without doing anything else :D

So basically, we have created a way to create a Queue, where will this queue be created? In the Azure Subscription identified by the connection string. So running this would result in..

A newly created queue, programmatically, with nothing in it. LOL. Anyways, it worked.

Do take some time to investigate. Did you notice that the casing of the queue’s name was converted to lower case?

Looking at the documentation, upper case characters should be allowed. Let us dig into that some other time.

Send Message to Azure ServiceBus Queue using C#

So now we have a queue; how do we send message objects?

The QueueClient object should do well here. So I make a separate method to send a simple message object of type BrokeredMessage.

private
static
void SendSampleMessage()

{


QueueClient MyQueueClient = QueueClient.Create(“testqueue”);


BrokeredMessage MyMessage = new
BrokeredMessage(“this is a test message”);

MyMessage.MessageId = “1″;

MyQueueClient.Send(MyMessage);

}

 

Very very straightforward and devoid of any validation J

Create a message, send the message. That’s it.

 

It says the length now is 1, because the app has sent one message J

How to retrieve an azure servicebus queue message using C#

So now let us retrieve the message and its contents.

I had to step into the code to show the retrieved message.. too lazy to go Console.Writeline. LOL!

So there you have it.. your basic of sending and retrieving messages to the Microsoft Azure ServiceBus Queue. The items you see here is by all means the simplest and most happy programming available. If one follows this step by step, one will encounter an error that should easily be resolved J

Also, I will leave it up to the reader to:

  1. Add validation to the methods. Best practice would dictate to see first if the Queue exists before creating it.
  2. Refactor the code for better performance.

Thank you!

 

 

 

 

Posted in Computers and Internet | Leave a comment

Asynchronous Grill

So the question remains.. “how many MVPs does it take to start a barbeque?” :D

For those not in the know, Microsoft MVPs are select people who are nominated by peers and have shown strong community influence and are recognized as Industry Experts. These people; as some may claim, are the cream of the crop, in their respective fields.

BUT, in the case of the Philippines, we MVPs also have connections outside of the world of technology. And as it goes, we all sometimes like to go “unplugged” once every so often. To detach ourselves from technology J. A few years back, we went birding; then some went to the beach.. this year, a lot of us decided to spend some time on the beach again, which is good.

April 26th came and several of the Philippine MVPs went to a beach…

Allan, Jojo, Jon, Glen, Eufer, Erwin, Mike, John, Jay R and I went to Paniman Resort in Cavite with a few items to do:

  • Cook
  • Eat
  • Talk
  • Eat
  • Talk some more
  • Eat some more

If you took the time to view our profiles, you would see that among us, there is enough skills to author and deploy an enterprise IT solution. But that was not the topic that day, what we wanted was to go offline for a bit and enjoy mother nature.

So, upon arrival we quickly set up to grill the food..

Pork chops and chicken on one grill..

And oysters on another.

Man, you can take the geek out of tech but you can’t take the tech out of the geek..

There were really no big problems this time; (except for the poor internet signal). The challenge of starting a fire was not that big. Although we did contemplate at one point which would make the best grilling material between an iPhone and and Android device. LOL

Here’s Jon taking care of lunch..

Eufer set up his own grill and cooked some oysters.

So basically, the grill was on dual processors with async properties.. and while they were grilling, the hungry mouths laid in wait.

Waiting for this to get cooked..

Glenn brought a huge slab of beef!!! Yummy!

Of course we would take turns fanning the grill while others cheated by “stealing” some of the beef..

One of the personal highlights for me was doing some fishing..

It was quite productive.. caught some little buggers J

Some walking along the beach..

But the most fun was, talking about the other MVPs who were not there LOL!

All in all.. it was a great way to spend a Saturday J

Posted in Computers and Internet | 2 Comments

Staged Publishing of Monaco maintained app!

Really nice surprise today.

Was fiddling around with Monaco and found this..

 

This is really nice. Now we have a way to see the edits I did on the website, on a staging level.

Awesome….

Posted in Computers and Internet | Leave a comment

Blog from OneNote

When we were talking about blogging from MSWord, an officemate asked me if I could do the same with OneNote. I guess he uses OneNote more than MSWord.

So… I kinda fiddled with OneNote and found this!


 
 

There is a Send to Blog button.. And to test how this works.. I am now blogging this using OneNote. :)

You know what happened? When I clicked “Send to Blog”.. it sent me to MSWord! LOL!

Posted in Computers and Internet | Leave a comment

Define and give Credentials to off-site Developer for Visual Studio Online

I think I got it..

I was asking around how to enable my off-site developers to use Monaco to edit and develop an AzureWebsite in my Azure Subscription without me needing to give them my Azure credentials.

Here is the process:

If you have not done so, open your Azure Management Portal and go to Websites and highlight the website you wish your devs to develop.

Then on the dashboard, you will see

On first access it will be “Set your deployment credentials”… I think.. :D

This is my second attempt so it now appears as Reset. Clicking that URL will:

And there you go! You have set the credentials to share!

So again, from the dashboard you click the Edit in VS link

Take that URL.. (nevermind my bookmarks)

Give that to your dev and the credentials. And they should be able to connect J

Here is my friend accessing a different azure website. Take note she is being challenged for credentials

And….

 

Posted in Computers and Internet | Leave a comment

Setting up Source Control between AzureWebsite and Team Foundation Service

 


With “Monaco” in preview.. it enables devs to code on the cloud. It only makes sense for the code to also be in the cloud.

Good thing MS has this Team Foundation Service; which is, to oversimplify, Microsoft’s cloud version of Team Foundation Server.

With both technologies in your hands, again, it only makes sense to be able to edit code that is in the cloud, on the cloud.

So, on your Windows Azure Management Portal, you highlight your selected AzureWebsite that you wish to edit and store on the cloud and view a special entry in the dashboard.

Clicking on that link will open a modal dialog where you can choose what cloud based source control you wish to connect to:

I choose Visual Studio Online as it is the one I have..

Here you enter your TFS(Team Foundation Service) url and hit Authorize Now to enable the connection. There is also an available link to Create a new TFS Account.

And after a successful authorization, you get to choose which TFS account to use.

It just so happens that I have more than one. J

And..

You are now officially linked!

 

To complete the scenario you will need to have a Team Foundation Server account and a Windows Azure Subscription. J

Posted in Computers and Internet | Leave a comment

Creating and Editing a simple website using Visual Studio Online

Ok. So here we are to try and:

  1. Create a simple website
  2. Add a folder for an image
  3. Add an image to the folder
  4. Display that image on the page

Pretty simple…

I start off with a blank azure website that I just created. Then opened it up with VSOnline.

To “run” this site..

click the Run button.

And VSOnline will give you the result in the Output window

 

So I click that url and see that the site is up and running.

 

Now I add a new folder to the site

So I now have…

I’ll try to add an image…

Oh wow! Right clicking gives me..

So I try to upload a screenshot from a recent speedtest :p

And.. try to add that to the site.

And test…

 

And while I was editing, I was pleased to see some form of intellisense J

 

Posted in Computers and Internet | Leave a comment