Skip to content

Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications patterns & practices Developer Center

Notifications You must be signed in to change notification settings

huoxudong125/Cloud-Design-Patterns-Examples

Repository files navigation

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>Cloud Application Patterns on Windows Azure - Readme</title>
    <link rel="stylesheet" href="readme_files/styles/main.css" type="text/css" />
    <link rel="stylesheet" href="readme_files/styles/mnp.css" type="text/css" />
    <style type="text/css">

 p.MsoNormal
  {margin-bottom:.0001pt;
  font-size:11.0pt;
  font-family:"Calibri","sans-serif";
          margin-left: 0in;
            margin-right: 0in;
            margin-top: 0in;
        }
    </style>
</head>
<body>
    <a name="top"></a>
    <div id="commonWrapper">
        <div id="pageWrapper">
            <!--   START HEADER   -->
            <div class="page_header">
                <div class="page_header_logo">
                    <table>
                        <tr>
                            <td>
                                <a href="Readme.htm">
                                    <div class="page_header_title">
                                        Cloud Design Patterns</div>
                                </a>
                                <div class="page_header_subtitle">
                                    About the Examples</div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <!--   END HEADER   -->
            <div id="Main">
                <div id="MainMid">
                    <!-- START NAVIGATION BAR -->
                    <div id="TopNavigation">
                        <div class="topnav_item" id="topnav1">
                            <a tabindex="1" href="Readme.htm"><span class="topnav_item_left_selected"></span><span
                                class="topnav_item_middle_selected"><span class="topnav_item_text">Readme</span>
                            </span><span class="topnav_item_right_selected"></span></a>
                            <a tabindex="1" href="ReleaseNotes.htm"><span class="topnav_item_left"></span><span
                                class="topnav_item_middle"><span class="topnav_item_text">Release notes</span>
                            </span><span class="topnav_item_right"></span></a>
                        </div>
                        <div class="topnav_item_divider">
                        </div>
                    </div>
                    <!-- END NAVIGATION BAR -->
                    <div id="Content">
                        <div class="content_table_home">
                            <div class="homePgImgWide">
                                <div class="homearea">
                                    <div class="pageTitle">
                                        <div class="maintitle">About the Examples</div>
                                    </div>
                                    <div class="newpromo">
                                        <a href="http://msdn.microsoft.com/practices">
                                            <img src="readme_files/images/pnp_logo.gif" alt="Microsoft Patterns & Practices" />
                                        </a>
                                    </div>
                                    <div class="content_header_text">

<p>This document describes the examples that illustrate the scenarios described in the guide
<i>Cloud Design Patterns</i> (see <a href="http://aka.ms/Cloud-Design-Patterns" target="_blank">http://aka.ms/Cloud-Design-Patterns</a>).
Each example is a Microsoft Visual Studio 2012 project that you can compile and run.</p>

<p>&nbsp;</p><hr /><p>&nbsp;</p>

<p><b>Before you start</b></p>
<p>&nbsp;</p>
<p>Ensure that you have installed all of the software prerequisites. For details see the <a href="ReleaseNotes.htm"><b>Release Notes</b></a>.</p>
<p>&nbsp;</p>

<p>Each example is a separate project. The folders of the examples also contain code snippets
that demonstrate some of the patterns in the guide. These are not projects that can be run, but are included so
that you can easily view and reuse the code in your own solutions.</p>
<p>&nbsp;</p>

<p>The examples demonstrate operational aspects of applications running in Windows Azure. Therefore, you will need to
use the diagnostics tools in order to understand how each code sample works. You <b>must</b> ensure that
the web and worker roles in each solution are configured to use the diagnostics mechanism. If not, you will not
see the trace information generated by each example.</p>
<p>&nbsp;</p><hr /><p>&nbsp;</p>

<p><b>Running the Examples</b></p>
<p>&nbsp;</p>
<p>You can run all of the examples locally in the Visual Studio Windows Azure emulator. You can also run most of the examples by deploying them to a Windows Azure Cloud Service.</p>
<p>&nbsp;</p>
<ul>
	<li>Start Visual Studio using an account that has Administrator privileges ("Run as Administrator").</li>
	<li>Open the solution you want to explore from the subfolders where you downloaded the examples.</li>
	<li>Right-click on each role in Solution Explorer, select Properties, and ensure that the role is configured to generate diagnostic information.</li>
	<li>Follow any additional steps shown in the <a href="#examples">list of examples</a> to set up that example.</li><br />
	<li>If you want to run the example in the local Windows Azure emulator:</li>
	<ul>
	  <li>Press <i>F5</i> in Visual Studio to start the example running.</il>
	  <li>Open the Windows Azure Compute Emulator UI from the icon in the notification area.</li>
	  <li>Select each role in turn and view the diagnostic information generated by Trace statements in the code.</li>
	</ul>
	<li>If you want to run the example on Windows Azure:</li>
	<ul>
	  <li>Provision a Windows Azure Cloud Service and deploy the application to it from Visual Studio.</il>
	  <li>Open the Server Explorer Window in Visual Studio and expand the Windows Azure entry.</li>
	  <li>Expand Cloud Services and then expand the entry for the solution you deployed.</li>
	  <li>Right-click each role instance and select View Diagnostics Data to see the diagnostic information generated by Trace statements in the code.
	  This is written to the WADLogsTable in the Storage/Development/Tables section.</li>
	</ul>
</ul>
<p>&nbsp;</p><hr /><p>&nbsp;</p>

<a name="servicebus"></a>
<p><b>Configuring Service Bus for the Examples</b></p>
<p>&nbsp;</p>
<p>Some of the examples use a Windows Azure Service Bus to send and receive messages. Check the details of each example shown below to see if this is
	required. Where it is required. you must:</p>
<ul>
	<li>Provision a Windows Azure Service Bus Namespace</li>
	<li>Edit the ServiceBus.ConnectionString setting by changing "[SERVICE BUS CONNECTION STRING]" to your own Service Bus endpoint
	in the following files for every role in the solution:</li>
	<ul>
		<li>ServiceConfiguration.Cloud.csfg if you will run the example on Windows Azure.</li>
		<li>ServiceConfiguration.Local.csfg if you will run the example in the Windows Azure Emulator.<br />
		(you can update settings by right-clicking on each of the roles and selecting Properties, or by editing the files
		directly in the main Visual Studio window.)</li>
	</ul>
</ul>
<p>&nbsp;</p><hr /><p>&nbsp;</p>

<a name="examples"></a>
<p><b>About the Examples</b></p>
<p>&nbsp;</p>
<p>Each example is a separate project within the solution. The folders of the solution also contain code snippets
that demonstrate some of the patterns in the guide. These are not projects that can be run, but are included so
that you can easily view and reuse the code in your own solutions.</p>
<p>&nbsp;</p>
<p>The examples you can run are:</p>
<table width="100%">
<tr><td><a href="#cc">Competing Consumers</a></td><td><a href="#crc">Compute Resource Consolidation</a></td><td><a href="#ecs">External Configuration Store</a></td></tr>
<tr><td><a href="#hem">Health Endpoint Monitoring</a></td><td><a href="#le">Leader Election</a></td><td><a href="#paf">Pipes and Filters</a></td></tr>
<tr><td><a href="#pq">Priority Queue</a></td><td><a href="#rr">Runtime Reconfiguration</a></td><td><a href="#sch">Static Content Hosting</a></td></tr>
<tr><td><a href="#vk">Valet Key</a></td><td></td></tr>
</table>
<p>The code snippets for other patterns can be found in the root folder of the examples.</p>
<p>&nbsp;</p>

<a name="cc"></a>
<p><b>Competing Consumers</b>. This example contains two components: the Sender worker role is responsible for sending messages to a Service Bus queue,
and the Receiver worker role retrieves messages from the queue and processes them. The Receiver worker role is configured to run with two instances to simulate competition between consumers.</p>
<ul><li>Before running this example, configure a Windows Azure Service Bus Namespace as shown <a href="#servicebus">above</a>.</li></ul>
<p>&nbsp;</p>

<a name="crc"></a>
<p><b>Compute Resource Consolidation</b>. This example shows how you can consolidate several separate and distinct tasks into a single worker role.
There are no additional requirements for running this example.</p>
<p>&nbsp;</p>

<a name="ecs"></a>
<p><b>External Configuration Store</b>. This example shows a mechanism for storing configuration settings in an external store instead of using configuration files. In this example, settings are stored in Windows Azure Blob Storage. The blob containing the configuration information is monitored by an instance of the ExternalConfigurationManager class.
When the ExternalConfigurationManager object detects a change in the configuration store, it notifies the application of the change.</p>
<ul>
<li>This example can be run only in the local Windows Azure emulator.</li>
<li>To simulate an external update to the configuration blob:</li>
    <ul>
		<li>Open the NewConfiguration folder. This contains a version of the configuration blob with different values.</li>
		<li>Upload this blob to the local Windows Azure emulator storage to replace the original. You can do this in the Storage section
		of Visual Studio Server Explorer.</li>
        <li>View the Output Window to see the changes detected by the ExternalConfigurationManager.</li>
	</ul>
</ul>
<p>&nbsp;</p>

<a name="hem"></a>
<p><b>Health Endpoint Monitoring</b>. This example shows how you can set up a web endpoint that checks the health of dependent services
by returning appropriate status codes. The endpoints are designed to be consumed by a watchdog monitoring service such as Windows Azure Endpoint
Monitoring, but you can open and invoke the endpoint operations from a browser to see the results. You can also deploy and configure your
own endpoint monitoring tool of choice to send requests to the service operations and analyze the responses received.</p>
<ul>
	<li>Start the example running and navigate to one of the monitoring endpoints. Use the F12 Developer Tools in Internet Explorer or the
	equivalent in your browser to watch the network traffic response pattern.</li>
	<li>The response will be 200 (OK), or a 500 error code that indicates a problem with a service.</li>
	<li>The sample contains four endpoints that you can test:</li>
	<ul>
		<li><b>/HealthCheck/CoreServices</b> This is a simple check on dependent services to determine if they are responding.</li>
		<li><b>/HealthCheck/ObscurePath/{</b><i>path</i><b>}</b> This demonstrates a check operation that uses a configurable obscure path defined in the service configuration file.
		Replace <i>path</i> with the value of the setting named Test.ObscurePathfrom in the file ServiceConfiguration.*.csfg.
		Note that this technique is not to be used as an alternative to properly securing an application and implementing authentication.</b></li>
		<li><b>/HealthCheck/CheckUnstableServiceHealth</b> This will randomly return a 500 exception for approximately 20% of the requests.</li>
		<li><b>/HealthCheck/TestResponseFromConfig</b> This returns a response code set in configuration (.cscfg) for testing.
		Deploy the solution with endpoint monitoring configured to use this operation, and then explicitly set the "Test.ReturnStatusCode" setting
		to return the required status code to test and demonstrate the effects of these codes on the monitoring service.</li>
	</ul>
</ul>
<p>&nbsp;</p>

<a name="le"></a>
<p><b>Leader Election</b>. This example shows how a worker role instance can become a leader among a group of peer instances. The leader can then perform tasks that coordinate and control the other instances; these tasks should be performed by only one instance of the worker role. The leader is elected by acquiring a blob lease.
There are no additional requirements for running this example. </p>
<p>&nbsp;</p>

<a name="paf"></a>
<p><b>Pipes and Filters</b>. This example contains two filters that could perform some part of the overall processing for a task. The two filters are combined into a pipeline; the output of one filter is passed as the input to the next. The filters are implemented as separate worker roles and a Windows Azure Service Bus queue provides the infrastructure that acts as the pipe.</p>
<ul><li>Before running this example, configure a Windows Azure Service Bus Namespace as shown <a href="#servicebus">above</a>.</li></ul>
<p>&nbsp;</p>

<a name="pq"></a>
<p><b>Priority Queue</b>. This example shows how you can implement priority queues by using Service Bus Topics and Subscriptions.
A worker role is responsible for sending messages to a topic. It assigns a priority to each message. The receiving worker roles
read messages from subscriptions that have the corresponding priority. In the example, The PriorityQueue.High worker role runs
with two instances, whereas the PriorityQueue.Low worker runs only with one. This ensures that high priority messages are
read from the queue more quickly than low priority messages.</p>
<ul><li>Before running this example, configure a Windows Azure Service Bus Namespace as shown <a href="#servicebus">above</a>.</li></ul>
</ul>
<p>&nbsp;</p>

<a name="rr"></a>
<p><b>Runtime Reconfiguration</b>. This example shows how a change in the settings of a Cloud Service can be applied without restarting the web
or worker role. The relevant code is in the files Global.asax.cs and WebRole.cs.</p>
<ul>
	<li>If you intend to run the example in the local Windows Azure emulator:</li>
	<ul>
		<li>Start the application without debugging by selecting Start Without Debugging from the DEBUG menu.</li>
		<li>In the folder <i>samples-folder</i>\RuntimeReconfiguration\bin\Debug (where <i>samples-folder</i> is the folder where you installed the examples) open the file ServiceConfiguration.cscfg in Visual Studio or in a text editor.</li>
		<li>Change the value of the setting named CustomSetting to a different value.</li>
		<li>To indicate to the emulator that the configuration has changed, open a Windows Azure Command Prompt from the Windows Start screen or Apps page.</li>
		<li>In Command Prompt type the command <b>csrun /status</b> and make a note of the value of Deployment-Id.</li>
		<li>In Command Prompt type the following command on one line:<br />
		&nbsp; <b>csrun /update:</b><i>deployment-id</i><b>;</b><i>samples-folder</i><b>\RuntimeReconfiguration\bin\Debug\ServiceConfiguration.cscfg</b><br />
		replacing <i>deployment-id</i> and <i>samples-folder</i> with your own values.</li>
		<li>Wait for a few seconds to allow the reconfiguration to complete.</li>
		<li>In the browser, view the values that were updated without restarting the application. Note that, due to some issues with the compute emulator,
		the first time you run execute the csrun /update command it will restart the instance. After that it will re-configure the application without restarting it.</li>
	</ul>
	<li>If you intend to run the example on Windows Azure:</li>
	<ul>
		<li>Deploy the application to Windows Azure from Visual Studio and start it running.</li>
		<li>Open the Windows Azure portal, sign into your subscription, and select the Cloud Service where you deployed the application.</li>
		<li>Using the portal to change the value of the setting named CustomSetting in the service configuration to a different value.</li>
		<li>Wait for a few seconds to allow the reconfiguration to complete.</li>
		<li>In the browser, view the values that were updated without restarting the application.</li>
	</ul>
</ul>
<p>&nbsp;</p>

<a name="sch"></a>
<p><b>Static Content Hosting</b>. This example shows how to reference static content from a publicly accessible storage service. The example contains a
Windows Azure web role, which hosts a web application that references JavaScript files and images deployed to a Windows Azure storage account. This type of
content is typically deployed to the storage account as part of the application deployment process. However, to simplify the
example, these files are deployed to the storage account when the application starts up.</p>
<p>&nbsp; &nbsp; The JavaScript and stylesheet content is referenced in the file App_Start\BundleConfig.cs by using a CDN URL. The image content is referenced
in the file Views\Home\Index.cshtml. The URLs are generated by an HTML helper class implemented in the file StaticContentUrlHtmlHelper.cs.</p>
<p>&nbsp; &nbsp; When running the application in release mode, you should note that these static resources
are served out of the storage account, as opposed to being delivered by the application server.
</p>
<ul>
	<li>This example is designed to run by default in the local Windows Azure emulator. If you want to run it on Windows Azure you must:</li>
	<ul>
		<li>Provision a Windows Azure storage account.</li>
		<li>Update the file ServiceConfiguration.Cloud.cscfg by changing the value of the StaticContent.StorageConnectionString setting to the
		connection string for your storage account. You can do this in the Properties page for the role or by opening the file in the main Visual Studio window.</li>
	</ul>
</ul>
<p>&nbsp;</p>

<a name="vk"></a>
<p><b>Valet Key</b>. This example shows how a client application can obtain a shared access signature with the necessary permissions to write directly to blob storage. For simplicity, this sample focuses on the mechanism to obtain and consume a valet key and does not show how to implement authentication or secure communications.</p>
<ul>
	<li>Start the Web Service and note the URL of the web role shown in the browser address bar.</li>
	<li>Open the file app.config from the ValetKey.Client project and change the setting for serviceEndpointUrl to  &nbsp; [<i>your-URL</i>]<b>/api/values/</b></li>
	<ul><li>By default this is set to <b>http://127.0.0.1:81/api/values/</b></li></ul>
    <li>Start a new instance of the ValetKey.Client project to upload the blob.
    <ul><li>Right-click the project, select Debug, and click Start new instance.</li></ul>
    <li>View the Trace information to see what the code does.</li>
</ul>
<p>&nbsp;</p>

                  </div>
                                    <br />

                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="footerstrip">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="clear">
    </div>
</body>
</html>

About

Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications patterns & practices Developer Center

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published