Programming Azure Blobs with Java


I'm producing a series of blog post that highlights the work I've done with an O'Reilly media video course. I will produce several posts a week to support this course, as seen below.

http://bit.ly/bruno-does-linux-data-java

smallslide0

The course is targeted towards developers who want to write Java applications on Linux and host those application in Azure.

These applications talk to today's top data stores, including:

  • Azure Tables
  • Azure Blobs
  • Azure Queues
  • SQL Server
  • SQL Database
  • MySQL
  • PostGres
  • DocumentDB
  • MongoDB
  • Cassandra
  • Redis

Using Java to connect to Azure Blobs

  • Reading and writing blobs is easy with the Azure SDK
  • You will need to:
    • Provision a storage account
    • Reference a container
    • Write code for the blob operations (upload, delete, download, etc)

smallslide001

Slide 1 - Overview


You can find the Java Storage SDK

  • You can compile your own jar from the latest sources

smallslide002

Slide 2 - Finding the SDK


The Github Repo with the Java SDK

  • Source code is available
  • We will compile our own Jar file

smallslide003

Slide 3 - Github


Git Clone

  • Downloading the Azure Java Storage SDK

smallslide004

Slide 4 - Downloading the SDK to local dev computer


Maven Compile

  • You will need to install and run Maven
  • Explained in course at top of this post

smallslide014

Slide 5 - Compiling the .java to .class


Using the jar utility to create a JAR file

  • Creating a jar file from all the class files
  • Review
    • Download sources
    • Compile sources
    • Create jar file
    • Add jar file to Eclipse project (future module)

smallslide005

Slide 6 - Creating jar file


Viewing Jar file

  • You can now see the jar file created
  • You may want to copy it to an easier location
    • Like c:\azure-storage-java

smallslide007

Slide 7 - Viewing the jar file


Moved jar file to new location

  • Don't want it too deeply buried

smallslide008

Slide 8 - New jar file location


Creating a new Java project in Eclipse

  • Obviously, I assume you've installed Eclipse
  • Issue a File/New/Java Project

smallslide009

Slide 9 - Installing Eclipse


Filling out the connection string

  • We have added BlobManager.java
  • You need to go to the portal to fill out the rest
  • Notice the import statements for the Azure Java Storage SDK

smallslide010

Slide 10 - Adding BlobManager.java


The Azure Portal

  • Notice we have:
    • Storage Account Name
    • Primary Key
  • We will need to paste this into our code

smallslide011

Slide 11 - Azure Portal


Storage Connection String

  • Notice on line 11 and 12 we have storage account name and primary account key pasted
  • Next we will go to try {} block on line 16

smallslide012

Slide 12 - Finished connection string


Connecting to storage account

  • Using CloudStorageAccount and CloudBlobClient objects
  • Lines 16 and 17

smallslide013

Slide 13 - Code to connect

Make sure you have the azurestorage.jar properly referenced

  • It is part of project properties
  • After adding the azurestorage.jar file to project you need to make sure it is part of the Java Build Path.

smallslide015

Slide 14 - Java build Path


Comments (4)
  1. Marc says:

    Bruno,

    Great job!!

    I have viewed "Microsoft Azure Data Storage for Developers" and find it a great wealth of information. A good combination of architecture + coding.

    Thanks,

    Marc

  2. khorshed alom says:

    I have microsoft azure data storage for developers.

  3. khorshed alom says:

    wel this msdn.

  4. khorshed alom says:

    good

Comments are closed.

Skip to main content