eclipse-image

Tonight I visited the San Diego Java User Group and took part in a coding dojo (more about that later).  While there, I mentioned to the attendees that we do have some resources for Java developers to use if they want to try out using Windows Azure or SQL Azure in their applications.

To that end, I’ll list what I know here and ask that any Java developers who do try out these tools or samples to let me know how this stuff works (or doesn’t work) for your applications.

Of course Windows Azure consists really of three big buckets: compute, storage and more services (such as Service Bus and Access Control). On the compute services side, developers pick from web or worker roles.  Oversimplified a web role is similar to a web site and worker role is similar to an OS service (i.e. no UI).  This blog post has more detail.

Azure Product Group lead Steve Marx writes in his blog about which compute roles are available for Java developers and basically explains why you’d generally only use a WORKER role below:

“You could invoke java.exe (via copy-deployment of the JRE) from a web role, but I would caution against using it as a way of responding to web requests, because starting a process on each web request is pretty inefficient.  However, in the worker role, invoking an executable is perfectly reasonable.

The worker role in Windows Azure is a very simple pattern.  You write a .NET assembly with a Start method, which never returns.  To run Java code instead, you just need to write a .NET assembly which invokes java.exe from that Start method.

From that Java code, you can do whatever you want, but typically you’ll want to poll a Windows Azure queue and maybe write results back to storage.  Because Windows Azure storage is based on HTTP and XML, it’s not too hard to write Java code to interact with storage.”

Below is a picture of the architecture as well.

Java interop with Windows Azure

Assuming you’d want to try this out, your first step is to grab the Windows Azure SDK for Eclipse / Java.    This SDK includes the following:

  • Java classes for Windows Azure Blobs, Tables & Queues (for CRUD operations)
  • Helper Classes for HTTP transport, AuthN/AuthZ, REST & Error Management
  • Manageability, Instrumentation & Logging support
  • Support for storing Java sessions in Azure Table Storage
  • After you download and install these tools, then you’ll also see some additions to Eclipse.

    The samples are written with a PHP web role and Java worker role.  The web role really can be written in any language, we just wrote them with PHP to show interoperability in two non-Microsoft languages in our samples.

    What you’ll see in Eclipse after you install the tools is a new View, called the “Windows Azure Storage Explorer” (shown below).  Using this View, you can see your application’s contents of the three Windows Azure storage types, blobs, queues or tables.

    Windows Azure Storage Explorer

    For even more information, check out a session from PDC09 (called ‘Building Java Apps on Azure’ ), which is based on coding up a sample application.  In this session, Steve Marx reviews an application that follows the pattern described above, i.e. uses Java for a Windows Azure worker role with Windows Azure queued storage.

    SQL Azure

    If, rather than Windows Azure storage, you’d prefer to use SQL Azure (more RDMS-like storage than Windows Azure storage [tables, blob or queues]) as storage for a Java application, there is NOTHING that you need to install in Eclipse.  You may wish to download the CTP of SQL Server 2008 R2, so that you can use SQL Server Management Studio to connect to your SQL Azure instance for convenience.  This is not required however.

    Happy Programming!