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.
https://bit.ly/bruno-does-linux-data-java
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)
Slide 1 - Overview
You can find the Java Storage SDK
- You can compile your own jar from the latest sources
Slide 2 - Finding the SDK
The Github Repo with the Java SDK
- Source code is available
- We will compile our own Jar file
Slide 3 - Github
Git Clone
- Downloading the Azure Java Storage SDK
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
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)
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
Slide 7 - Viewing the jar file
Moved jar file to new location
- Don't want it too deeply buried
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
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
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
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
Slide 12 - Finished connection string
Connecting to storage account
- Using CloudStorageAccount and CloudBlobClient objects
- Lines 16 and 17
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.
Slide 14 - Java build Path
Comments
Anonymous
February 10, 2016
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, MarcAnonymous
February 21, 2016
I have microsoft azure data storage for developers.Anonymous
February 21, 2016
wel this msdn.Anonymous
February 21, 2016
good