Microsoft Lab Of Things - Week6 Tuesday - Kookmin University 1
Objectives and what to study Azure Storage concepts Azure Storage development Blob Table Queue 2
Objectives Understand Azure Storage Services Advantage of Azure Storage What to study How to use Azure Storage services: Blob, Table, Queue, and File storage How access to your data in Azure Storage 3
Azure Storage services: Blob storage stores file data. A blob can be any type of text or binary data, suc h as a document, media file, or application installer. Table storage stores structured datasets. Table storage is a NoSQL key-attribut e data store, which allows for rapid development and fast access to large quant ities of data. Queue storage provides reliable messaging for workflow processing and for co mmunication between components of cloud services. File storage offers shared storage for legacy applications using the standard S MB 2.1 protocol. Azure virtual machines and cloud services can share file data a cross application components via mounted shares, and on-premise applications can access file data in a share via the File service REST API. 4
Relationships between the Azure storage resources in a standard storage account: 5
A standard storage account allows accession to Blob storage, Table storage, Queue storage, and File storage. File storage is available by request via the Azure Preview page. Each standard storage account can contain up to 500 TB storage 500TB: aggregated storage of all blob, queue, table, and file data The storage capacity can be scaled 6
Blob storage What is Blob Storage Blob storage offers a cost-effective and scalable solution to store in the cloud, for large amounts of unstructured data. Blob storage can be used to store: Documents Social data: photos, videos, music, and blogs Images and text for web applications Configuration data for cloud applications Big data: logs and other large datasets Backups of files, computers, databases, and devices 7
Blob storage Concepts Storage Account: All access to Azure Storage is done through a storage account Container: A container provides a grouping of a set of blobs All blobs must be in a container An account can contain an unlimited number of containers Blob: A file of any type and size. There are two types of blobs that can be stored in Azure Storage: block and page blobs. URL format: Blobs are addressable using the following URL format: http://<storage account>.blob.core.windows.net/<container>/<blobs> Ex: http://sally.blob.core.windows.net/movies.mov1.avi 8
Blob storage Concepts Create an Azure Storage account Setup a storage connection string Programmatically access Blob storage 9
Blob storage Create an Azure Storage account Log in to Azure Management Portal 10
Blob storage Create an Azure Storage account New storage account is created 11
Blob storage Setup a storage connection string A connection string used to configure endpoints and credentials for accessing storage service. Should be mantained in a confgure file rather than hard-cording Step 1: Copy storage name and key on azure management portal Save these information 12
Blob storage Setup a storage connection string Step 2: Configure your connection string using.net configuration Open web.config or app.config Replace account-name with the name of your storage account and accountkey with your account access key For example, with previous saving information, we can set our connection stri ng like this: 13
Blob storage Programmatically access Blob storage Obtaining the assembly Use NuGet to obtain the Microsoft.WindowAzure.Storage.dll assembly In Manage NuGet Packages, install Azure Storage package by searching WindowsAzure.Storage 14
Blob storage Programmatically access Blob storage Namespace declarations Add the following code namespace declarations to the top of any C# file in which you want to programmatically access Azure Storage. using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Auth; using Microsoft.WindowsAzure.Storage.Table; Reference the Microsoft.WindowAzure.Storage.dll assembly 15
Blob storage Programmatically access Blob storage Retrieving your connection string and CloudStorageAccount object Using C# code to retrieving connection string in app.config file Add a reference to System.Configuration.dll to project, and then add another namespace for it: using System.Configuration; 16
Blob storage Programmatically access Blob storage Create a container Every blob in Azure storage must reside in a container. This code shows how to create a container if it does not already exist. Set the container to be public using the following code 17
Blob storage Programmatically access Blob storage Upload a Blob into a container Get a container reference and use it to get a block blob reference. Upload stream of data to blob reference by calling the UploadFromStream method 18
Blob storage Programmatically access Blob storage List the Blobs in a container Get a container reference Use ListBlobs method to retrieve the blobs and directory within it. Call CloudBlockBlob, CloudPageBloc, or CloudBlobDirectory, to access the returned Blobs 19
Blob storage Programmatically access Blob storage List the Blobs in a container Example: The following code demonstrates how to retrieve and output the URI of each item in the photo container 20
Blob storage Programmatically access Blob storage Download blobs Retrieve blob reference Call DownloadToStream method 21
Blob storage Programmatically access Blob storage Delete blobs Get a blob reference Call the Delete method on it 22
Table storage What is the Table Service The Azure Table service stores large amounts of structutred data. The service is a NoSQL data store which accepts authenticated calls from inside and outside the Azure cloud. Azure tables are ideal for storing structured, non-relational data. Common uses of the Table service include: Storing TBs of structured data capable of serving web scale applications Storing datasets that don't require complex joins, foreign keys, or stored pr ocedures and can be denormalized for fast access Quickly querying data using a clustered index You can use the Table service to store and query huge sets of structured, non-relational data, and your tables will scale as demand increases. 23
Table storage Table Service Concepts Table service contains the following components: URL format: Code address tables in an account using this address format: Storage account: All access to Azure Storage is done through a storage account Table: A table is a collection of entities Entity: An entity is a set of properties, similar to a database row Properties: A property is a name-value pair Each entity can include up to 252 properties to store data. 24
Table storage Programmatically access Table storage These steps are the same in Blob storage lecture. Creating storage account on Azure Management Portal Set connection string in app.config file Retrieving connection string Create a table First, create a CloudTableClient object. Then, use tableclient object to create a new table 25
Table storage Programmatically access Table storage Create a table First, create a CloudTableClient object. Then, use tableclient object to create a new table 26
Table storage Programmatically access Table storage Add an entity to a table Create a class that defines the properties of your entity. Create a CloudTableClient object Use the table client to create a Cloudtable object referring to destined table Create a TableOperation object that inserts the custome entity The insert operation is executed by calling Execute method 27
Table storage Programmatically access Table storage Retrieve a single entity The following code uses a TableOperation to specify the customer 'Ben Smith'. Specifying both partition and row keys in a query is the fastest way to retrieve a single entity from the Table service. 28
Table storage Programmatically access Table storage Replace an entity Use Replace method to update an entity Replace operations will fail if the entity has been changed since it was retrieved from the server. 29
Table storage Programmatically access Table storage Insert-or-update an entity Use InsertOrReplace method to insert the entity if it doesn't exist, or replaces it if it does, regardless of when the last update was made. 30
Table storage Programmatically access Table storage Delete an entity You can easily delete an entity after you have retrieved it, using the same pattern shown for updating an entity. 31
Table storage Programmatically access Table storage Delete a table A table which has been deleted will be unavailable to be recreated for a period of time following the deletion. 32
Queue storage What is the Queue Service Azure Queue storage is a service for storing large numbers of messages that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. Common uses of Queue storage include: Creating a backlog of work to process asynchronously Passing messages from an Azure Web role to an Azure Worker role 33
http://<storage account>.queue.core.windows.net/<queue> Queue storage Queue Service Concepts The Queue service contains the following components: URL format: Queues are addressable using the following URL format: http://<storage account>.queue.core.windows.net/<queue> Ex: http://myaccount.queue.core.windows.net/imagestodownload Storage account: All access to Azure is done through a storage account Queue: A queue contains a set of message. All messages must be in queue Message: A message, in any format, of up to 64KB 34
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage These steps are the same in Blob storage lecture. Creating storage account on Azure Management Portal Set connection string in app.config file Retrieving connection string Create a queue Create a CloudQueueClient object Use the queueclient object to get a reference to the queue you want to use 35
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage Insert a message into a queue Create a new CloudQueueMessage Call the AddMessage method 36
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage Peek at the next message You can peek at the message in the front of a queue without removing it from the queue by calling the PeekMessage method. 37
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage Change the contents of a queued message You can change the contents of a message in-place in the queue If the message represents a work task, you could use this feature to update the status of the work task Example: updates the queue message with new contents, and sets the visibility timeout to extend another 60 seconds. 38
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage Get the queue length Use FetchAttributes to retrieves the message count attribute of a queue. The ApproximateMethodCount property returns the last value retrieved by the FetchAttributes method 39
http://<storage account>.queue.core.windows.net/<queue> Queue storage Programmatically access Queue storage Delete a queue Call Delete method to delete a queue and all messages contained in it. 40