My first Windows Azure app is (at the time of writing) up and running at http://tweetpoll.cloudapp.net/. I’ve not built it to provide anything particularly useful but what it does do is demonstrate the capabilities of Windows Azure storage, web roles and worker roles and has afforded me the opportunity to get my hands dirty with Windows Azure, something I’ve been meaning to do for quite a while. The source code is available at http://tweetpoll.codeplex.com.
What does it do?
Very simply, the application displays the distribution of the lengths of Twitter statuses (“tweets”) from Twitter’s public timeline. Here’s a screenshot of that display:
Unsurprisingly 140 is the most common length for a Tweet however it seems that there are a great number in the 40-80 character range as well. It’ll be interesting to see if the graph smoothes out over time.
The web page front-ending the application also does a few ancillary things:
- Displays the total number of tweets that the application has fetched
- Displays a sample of messages currently residing on the application’s queue (more on the queue later)
- Displays the number of times that the web page has been accessed
TweetPoll won’t be available forever, I suspect that the moment Microsoft start charging for hosting on Azure that I’ll take it down but in the meantime feel free to stare transfixed as the numbers twitch before your very eyes!!!! Great fun I’m sure you’ll agree!!!
How does it do it?
My application consists of a worker role and a web role. The worker role has responsibility for:
- Polling Twitter’s public timeline for the 20 most recent tweets
- Pushing a message onto an Azure queue for each tweet
- Popping a message from the head the Azure queue
- Calculating the length of the tweet in the popped message
- Incrementing the counter for that particular Tweet length which is persisted in an Azure table
The web role has responsibility for:
Here is an architecture diagram that depicts the whole system:
It is of course totally unnecessary for one thread to push a message onto a queue just for another to pop it off again but this isn’t meant to be a real-world scenario; I just wanted to use as many pieces of Azure as possible.
Under the covers I used the Storage Client sample code from the Azure SDK which made interacting with Azure storage rather simple.
Thanks go to…
John O’Brien for his rather spiffing Azure Queue watcher gadget for Windows Sidebar which polls an Azure queue to detect the number of messages and which helped me immensely during development.
Its also quite gratifying to deploy your app to the cloud, set it running, and watch as the gadget starts ticking over as messages are pushed on and popped off.
That’s it. I hope the source code up on Codeplex helps anyone else that may be venturing into the world of Azure development. Any questions, just ask!