1. Trang chủ
  2. » Công Nghệ Thông Tin

Introducing Windows Azure- P15 pps

5 287 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 267,85 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The package used to deploy an Azure application to fabric The command-line utility provided by the Azure SDK, CSRun.exe, is the tool used to deploy the package to the local fabric, whic

Trang 1

43

approach for handling Azure message login His article can be found at http://

blogs.msdn.com/brunoterkaly/archive/2009/01/18/windows-azure-services-exercise-2-configuration-logging-and-debugging.aspx

Leverage the Power of Development Fabric Services

We briefly described the development fabric in the Introduction The development fabric is a powerful feature of the Azure Framework The development fabric simulates the Azure fabric service on a local

computer environment You can run, test, debug, and do any necessary tuning on performance or local configuration before deploying applications to production

An Azure application can be deployed to the local fabric and run stand-alone from the local fabric

as well as launching from Visual Studio if step-by-step debugging is needed Azure applications need

to be packed before being deployed to either the local fabric or the Azure fabric The package can be

generated using a command-line utility from the SDK, CSPack, with the /copyonly option CSPack will

generate a structured package, including the configuration file The package will be automatically

generated if you select Publish by right-clicking on the solution node of an application from Visual

Studio The generated configuration package and application package can be found from the project

folder as shown in Figure 2-10

Figure 2-10 The package used to deploy an Azure application to fabric

The command-line utility provided by the Azure SDK, CSRun.exe, is the tool used to deploy

the package to the local fabric, which can be found from the installed SDK bin directory Detailed

information to use this tool can be found from MSDN http://msdn.microsoft.com/en-us/library/

dd179412.aspx Based on my experience, in most cases Visual Studio in conjunction with the Azure

Portal should handle all deployment tasks very well

Using Fiddler 2 to Debug Cloud Storage Applications

Fiddler 2 is a very powerful web debugging tool from Microsoft and can be downloaded from

http://www.fiddler2.com/fiddler2/ This tool can be used to compose, listen to, and send HTTP

messages This tool can also be used to debug and test Azure applications including cloud storage

applications Below is an example of how to use this tool to help debug a cloud storage application In

order to do the demo we need to deploy the cloud storage application we created previously to run from the remote Azure fabric

Deploying an application to the remote Azure cloud environment is a topic covered in

Chapter 9 When the application is successfully hosted in the cloud, there is an URL assigned as

shown in Figure 2-11

Trang 2

44

Figure 2-11 The URL is assigned after the storage web role has been deployed to Microsoft and is running from the remote cloud environment

Copy that URL in your browser and Default.aspx will launch the application and access the remote storage as Figure 2-12 shows Figure 2-13 shows the debugging information captured when we click on the Add button using Microsoft Fiddler 2

Figure 2-12 As the web role been hosted from Microsoft, using the URL as shown from Figure 2-11 to launch the default.aspx page and access the storage running in the cloud

Trang 3

45

Figure 2-13 The HTTP debugging information captured when adding data to a cloud storage table using Microsoft Fiddler2

Leverage LINQ to Query Entities in Cloud Storage

LINQ is a feature introduced with Microsoft NET 3.0 that provides an agile way to query cloud table

entities Listing 2-13 is an example of using LINQ to print out all RowKey values of all rows from the table Address for tracing purposes

Listing 2-13 Using LINQ to Query RowKey Values of All Rows from Address Table

addressTableService.TableContext().CreateQuery<Address>

( addressTableService.TableContext().TableName).ToList<Address>().ForEach(

x => System.Diagnostics.Trace.WriteLine(string.Format(" - Row Key = <{0}>",

x.RowKey)));

An example using LINQ to return the top two entities from the Address table is shown in Listing 2-14

Listing 2-14 Using LINQ to Query RowKey Top N Rows from the Address Table

int i = 0;

foreach( Address a in addressTableService.TableContext()

.CreateQuery<Address>( addressTableService.TableContext().TableNam)

.ToList<Address>().Take<Address>(2) )

{

System.Diagnostics.Trace.WriteLine(

Trang 4

46

string.Format(" - Row Key[{0}] = <{1}>", i, a.RowKey)

);

++i;

}

Using HTTP REST to Query the Top N Entities

REST (Representational State Transfer) provides a powerful way to access Internet resources using HTTP and is widely used for web-related applications It can also be used to access Azure table storage The syntax to retrieve the top N entities from a cloud table is the following, using HTTP GET:

http://<TableStorageSolution>.table.core.windows.net/<TableName>()?$top=N

To query our Address table for the top 10 records the syntax is:

http://softnetsolutionstorage.table.core.windows.net/AddressTable()?$top=10

Using Continuation Tokens to Retrieve Paginated Data

When querying a large set of data from cloud tables, the number of entities returned in the query may be limited due to one of the following reasons:

• The number of total entities to return is greater than the maximum number of

entities allowed in the response by the server (currently 1,000)

• The total size of the entities in the response is greater than the maximum size of a

response, currently 4 MB including the property names but excluding the XML tags used for REST

• The time for completing the query is more than the timeout (currently 60

seconds)

If your queries fall foul of these restrictions, you can use continuation tokens to page the data You can consider continuation tokens to be keys used to query data sequentially, where one chunk of data follows another one The continuation tokens can be obtained from the return header from the current query results Listing 2-15 is sample code to peek at continuation tokens This piece of code is

a stand-alone piece and not part of the project of this exercise We leave it to you as homework (The class DataServiceQuery used in this piece of code is a class from the StorageClient assembly of the Azure SDK.) The highlighted code in the next listing shows how to get the continuation token

programmatically from the response header There is no continuation token returned if the query does not meet the limit conditions listed above This function is extracted from the project in the next exercise and can be found from the code in Default.aspx.cs We are going to talk more about the continuation tokens used in the code in the next section

Listing 2-15 Sample Code for Peeking at the Continuation Tokens

private void ContinuationKeyPeek()

{

AddressTableContext tableContext =

Trang 5

47

addressTableService.TableContext() as AddressTableContext;

ContinuationToken continuationToken = null;

do

{

var topTenAddress =

tableContext.CreateQuery<Address>(tableContext.TableName).Take(10);

var query = topTenAddress as DataServiceQuery<Address>;

if (continuationToken != null)

{

query = query.AddQueryOption("NextPartitionKey",

continuationToken.PartitionKey);

if (continuationToken.RowKey != null)

{

query = query.AddQueryOption("NextRowKey", continuationToken.RowKey);

}

}

var response = query.Execute() as QueryOperationResponse;

if (response.Headers.ContainsKey("x-ms-continuation-NextPartitionKey"))

{

continuationToken.PartitionKey =

response.Headers["x-ms-continuation-NextPartitionKey"];

if (response.Headers.ContainsKey("x-ms-continuation-NextRowKey"))

{

continuationToken.RowKey =

response.Headers["x-ms-continuation-NextRowKey"];

}

}

else

{

continuationToken = null;

}

} while (continuationToken != null);

}

public class ContinuationToken

{

public string PartitionKey { get; set; }

public string RowKey { get; set; }

}

There are rich technologies available to retrieve the data from cloud table storage, including the web role service offered by the Azure Framework, LINQ or REST, or tools such as Fiddler using the HTTP

protocol Next we are going to learn other basic cloud table storage data I/O actions—deleting and

updating data from cloud table storage

Ngày đăng: 05/07/2014, 01:20

TỪ KHÓA LIÊN QUAN