Download - Building Cross Platform Mobile Apps Powered by Azure Chris J.T. Auld Director - Intergen AZR225
Building Cross Platform Mobile Apps Powered by AzureChris J.T. AuldDirector - Intergen
AZR225
Session Objectives and Takeaways
Session Objective(s): Understand common patterns for migrating on-prem to AzureSee an approach to using SQL Azure FederationsSee various approaches for using the Azure Service BusUnderstand options and approaches for mobile front-ends
Moving to Azure needs more than mere compatibilityFederations allow almost unlimited scale outMono is a reasonable approach for x-platform mobility‘Super-Simple’ to consume Service bus from mobile
Web Application Layer (UI)
What is StockTrader?
N-tier application Web tier: ASP.NETMiddle tier(s): .NET WCF ServicesData tier: SQL Server/SQL Azure
Many modes of operationsSingle boxScale-out across clusterOn-premise or Windows AzureAcross hybrid clouds
High PerformanceBenchmarks Benchmark/capacity planner tool included
SecureData tier securityCommunication and message security
Use
r Inte
rface
Mid
dle
Tie
r B
usin
ess S
erv
ices
Data
Acce
ss
SQL Server/SQL Azure
Account Table
Account Profile Table
Orders Table
Holdings Table
Quote Table
Data Access Layer (DAL)
Market Summary Class
Customer Class Orders Class
Middle-Tier Business Services Layer (BSL)Business Service Layer
Core StockTraderServices Classes
Business Transactions
ServiceClient Class
Order Processor Service (OPS)
ServiceClient Class
Order Processing Service Class
Ord
ers
Tie
r
https://azurestocktrader.cloudapp.net
ASP.NET Web Forms
Business Transactions
StockTrader DB
SQL Server
Internet
DMZ
Firewall
ForeFront TMG
StockTrader Order
Processor Service
StockTrader Business Services
StockTrader Web
Application
System Center/VMM Managed Private Cloud
VMVM
VMVM
VMVM
VMVM
VMVM
VMVM
StockTrader On Premise Architecture
Windows Azure Platform
DMZ
StockTrader DB
SQL Server
StockTrader Azure Migration: Azure Lift and Shift
Windows AzureWeb Role
Azure StockTrader
Web Application
Windows Azure Worker Role
Azure StockTrader
Order ProcessorService
Windows Azure Web Role
Azure StockTrader Business Services
StockTrader DB
SQL Azure
Https andClient
Certificate
Net.tcp encrypted andClient Certificate
SQL Encrypted
SQL Encrypted
Firewall
ForeFront TMG
System Center/VMM Managed Private Cloud
Internet
StockTrader DB
Scale-outInstances
Scale-outInstances
Scale-outInstances
StockTrader Business Services
StockTrader Order
Processor Service
StockTrader Web
Application
VMVM
VMVM
VMVM
VMVM
VMVM
VMVM
StockTrader Business Service
StockTrader Order
Processor Service
StockTrader Web
Application
VMVM
VMVM
VMVM
VMVM
VMVM
VMVM
Firewall
ForeFront TMG
Existing On Premise Application
3 Objectives for StockTrader v6
1. Separate Exchange and Brokerage Aspects1. Split database2. Show Cloud B2B Scenario
2. Scale at the data tier1. Scale out using federations
3. Deliver rich experiences expected of apps today1. Mobile; All common platforms2. HTML5+JS3. Windows 8
StockTrader Azure Migration: Azure Optimized
Windows AzureWeb Role
Azure StockTrader
Web Application
Windows Azure Worker Role
Azure StockTrader
Order ProcessorService
Windows Azure Web Role
Azure StockTrader Business Services
AccountDB
SQL Azure
Scale-outInstancesScale-out
Instances
Scale-outInstances
QuoteDB
SQL Azure
queue topicsubs
RESTful Endpoint+ Token Service
Topic(s)subs
subs
subs…
Polling
Publishing
demo
StockTrader v6All-Up Demo
Azure Optimized vs Compatible
Critical changes for cloud scale applicationsStateless Application/Web TierScale out database tier of RDBMS is used Some services not supported e.g. distributed txn hard
Opportunities for optimizationService bus for messagingService bus for offload of polling
Optimizing
Scale Out Data TierUsing SQL AzureFederations
Using SQL Azure
Key Benefits
High availability without any additional effortFull TDS + T-SQL CompatabilityCode just works
Key Challenges
Limited Scale-UpQuery throttle means performance is non-deterministicNo point-in-time backup
If you are using SQL Azure for a large scale application you must consider implementing data
tier scale out
StockTrader versions up to v5
Account
AccountProfile
Holding
Orders
Quote
QuoteFederationKey=QuoteSymbol
AccountFederationKey = UserID
StockTrader v6AccountDB
QuoteDB
NewsTopics
AccountAccountProfile
HoldingOrders
AccountDevice
Quote
QuoteSymbol
demo
Federations Configuration
Moving to Federations
Federation KeyInt/UniqueIdentifier/VarbinaryWe had varchar so convert to varbinary in app layer
Primary KeysIdentity columns not supportedMoved to Uniqueidentifier Flowed through to service layerUse string in service layer; cast to Int/Guid for OnPrem/Cloud
Moving to Federations
Application ConnectivityNeed to USE FEDERATION when connectingMust use robust retry logic to support SQL AzureShow Federation.cs
Fan-Out QueriesRequired to retrieve lists of quotesSet filtering off and query each member sequentiallyRoom for optimization here come to AZR432 on Friday
Multiple DatabasesMove to multiple databases was not necessarily requiredCould have defined two Federations in a single DB
Transaction Scopes and Federations
Can’t connect to federation member while enlisted in transactionConnection pooling has issues as USE FEDERATION changes connection contextusing (var scope = new TransactionScope())
{ using (var connection = new SqlConnection(…)) { // enlists in current transaction connection.Open(); // Run SQL statements // doesn’t actually commit txn scope.Complete(); }}
using (var connection = new SqlConnection(…)){ connection.Open(); using (var scope = new TransactionScope()) { // Run statement to connect to right // federation (txn scope is ignored as // connection not enlisted)
connection.EnlistTransaction(scope); // Run SQL statements scope.Complete(); }}
A Quick note on Transactions
StockTrader OnPremise uses MSMQ + SQL Server incl MSDTCBoth Service Bus and SQL Azure support transactions including use of TransactionScopeNeither supports enlisting in transaction managed by MSDTC
i.e. No support for distributed transactions
No transaction support across federation membersNeed to suppress the transaction scope when working with the service bususing (new
TransactionScope(TransactionScopeOption.Suppress)) {}
For much more on Federations
AZR432: SQL Azure Federations Deep DiveChris AuldCentral C2/1/2012 0945hr -1100hr
Optimizing
De-coupling BSL from Ordering using Azure Service Bus
Messaging - Before
MSMQ (on-prem)
[Brokerage] Business Services
[Exchange]Order Processing
Service
Async Request
Quotes /Accounts
Messaging – Via Service Bus
ServiceBus
[Brokerage] Business Services
[Exchange]Order Processing
Service
Quotes /Accounts
Async Request Queue
Async Response Topic
Quotes /AccountsAccounts
Quotes /Accounts
Quotes /AccountsQuotes
Messaging – More Brokerages
ServiceBus
[Brokerage] Business Services [Exchange]
Order Processing Service
Async Request Queue
Async Response Topic
Quotes /Accounts
Quotes /AccountsQuotes
[Brokerage] Business Services
[Brokerage] Business Services
SEND permission
LISTEN permission+ rules
LISTEN permission + rules
LISTEN permission + rulessu
bsu
bsu
b
Service Bus: Notes on Implementation
Two separate contractsIOrderProcessorIOrderProcessorResponse
Just ‘plain–old ‘ WCFHosting
OPS explicitly hosted as a Worker RoleBSL hosted within IIS; use auto-start to ensure it is running
Brokered Messaging
Brokered MessagingQueued via Queues and TopicsRule based routing
Need to add metadata to messageShow ServiceBusMessageInspectorInject SB username into message on clientEcho sent SB username into message on server
Apply filters against the ‘sender’Show rules in SBExplorer
Optimizing
Service Bus for High Volume Messaging
High Volume Messaging
Our ScenarioReal time newsThousands of mobile clients‘Currently’ Polling our web roles at high frequency
End Goal1. Offload polling from Web Roles to SB
Other options also available. E.g. Windows Azure Mobile Services
Azure ServiceBus On-demand Topic Scale-out
StockTrader
System
Service Bus
News
News_1
Subscription
Subscription
Subscription
RegistrationService
2 .. 1999
New UX
Delivering cross platform clients toAndroid, iOS, Windows 8 and Windows Phone
Cross Platform Mobile App DevHTML5 (+ PhoneGap)
Doesn’t look nativeEverything like iOS?
No AppStore discoveryX-Browser issuesNo offline on WP7Animations are poorNot all APIs availableeven with PGIt’s Javascript
Mono
C# + .NET in VS.NETLambdas, LINQDelegates, Events
Access to almost all platform APIs via Mono WrappersGo native if neededUI still written ‘by-hand’
Native
Platform specific UXWrite the app 3 times
3 different languages3 x code to maintainObjective C is awful
100% Shared Code 0% Shared Code
Shared CodeShared files co-located; *.csproj for each platformEach solution has
Platform specific projectShared project
Similar MVVM pattern for all platformsShared ModelsShared RepositoryProbably could have shared ViewModels too…
Can use shared Interface + Platform Specific Implementation
WindowsPhonePreferencesProvider: IDevicePreferencesProvider
Show Android and Windows 8 Solutions
Consuming the Azure Service BusAll done from Shared codePolling on a timer‘Register’ device – on first login
Service creates subscriptions (and additional topic if needed)Returns subscription details to client
Auth using service busGet an ACS (WRAP) token for the service busStore token + timeoutPass token with request to SB for messagesDelete messages from subscription once done
Show StockTraderPollingNewsRepository.cs
In Review: Session Objectives and Takeaways
Session Objective(s): Understand common patterns for migrating on-prem to AzureSee an approach to using SQL Azure FederationsSee various approaches for using the Azure Service BusUnderstand options and approaches for mobile front-ends
Moving to Azure needs more than mere compatibilityFederations allow almost unlimited scale outMono is a reasonable approach for x-platform mobility‘Super-Simple’ to consume Service bus from mobile
Related Content
AZR432 – SQL Azure Federations Deep Dive
Find Me Later At Microsoft Pods in Exhibition Area
Code will be released in next few weeks. Keep an eye on www.syringe.net.nz
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the
part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.