Click here to Skip to main content
15,895,142 members
Articles / Database Development / SQL Server / SQL Server 2008

Event-Driven Architecture in the Clouds with Windows Azure

,
Rate me:
Please Sign up or sign in to vote.
4.95/5 (23 votes)
5 Feb 2010CPOL14 min read 71.1K   577   58  
To demonstrate Azure and EDA, this article will show you how to build a flight delay management system for all US airports in clouds with Windows Azure.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using FlightUpdates.Utility.Constants;
using FlightUpdates.MessageProcessorService.Resource_Files;

namespace FlightUpdates.MessageProcessorService
{
    public class WorkerRole : RoleEntryPoint
    {
        public override void Run()
        {
            try
            {
                Trace.Listeners.Add(new TraceWriterUtil());
                Trace.WriteLine(Messages.ServiceStart);
                FlightDelayQueueProcessor flightDelayQueueProcessor = new FlightDelayQueueProcessor();

                while (true)
                {
                    //Process messages
                    Trace.WriteLine(Messages.ProcessingMessageFromQueue);
                    flightDelayQueueProcessor.ProcessFlightDelayMessagesFromQueue();

                    //Nap time
                    Trace.WriteLine(Messages.NapTime + TwitterSettings.runProccessingInterMin);
                    Thread.Sleep(TimeSpan.FromMinutes(TwitterSettings.runProccessingInterMin));

                }
            }           
            catch (Exception err)
            {
                Trace.WriteLine(err.ToString(), LogMessageTypes.Error);
                throw (err);
            }
        }

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 1;

            //DiagnosticMonitor.Start("DiagnosticsConnectionString");

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            return base.OnStart();
        }

        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Other
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions