Building Scalable Cloud Connected
Mobile Apps using Windows Azure
Jahufar Sadique (99X)
What is Windows Azure Mobile
Services?
• A set of services build on Azure that provides backend ‘plumbing’ to
your mobile apps.
• Focus on building apps and not backend logic
– Data (dynamic schema)
– Authentication (Federated identities such as Facebook, Google,
Twitter, Windows Live)
– Server Logic (via Mobile Services Server Scripts)
– Push Notifications (GCM, APNS, WNS)
• Monitoring/Analytics/Logging infrastructure
• Client SDKs supported for Android, iOS, Windows Phone and
HTML/Javascript
Getting Started
• The service is not free
• ..but comes with a 3 month free trial (subject
to credit card verification)
• What you get:
http://www.windowsazure.com/en-
us/pricing/free-trial/
• DEMO: Azure Dashboard
• DEMO: Creating a new mobile service
• DEMO: Download the SDK and setup project
Mobile Service: Data
• Backend is Windows Azure SQL Database
• Dynamic schema – create your model in code,
and the fields are mapped by magic
• Throttling and failures are automatically
handled.
• NO RELATIONS (i.e. no foreign keys, cascade
logic etc)
DEMO
Creating a simple list of users
Authentication
• Authenticate against: Facebook, Google,
Twitter, Windows Live
• Table level permissions for CRUD operations:
– Everyone (default)
– Only authenticated users
– Only scripts and admins
DEMO
Securing the list of users
Server Scripts
• Similar to a trigger
• Allows you to build custom business logic when
something happens to your data
• Available operations: insert, update, read, delete (del)
e.g.:
function insert (id, user, request) {
request.execute();
}
Server Scripts: Continued
Insert: function insert(item, user, request) { }
Update: function update(item, user, request) { }
Delete: function del(id, user, request) { }
Read: function read(query, user, request) { }
•Script functions always take 3 arguments:
– 2nd
arg is always “user” (represents a user)
– 3rd
arg is always “request” (used to send responses).
– 1st
arg changes according to operation
Scripts: Continued
• Example:
function insert(item, user, request) {
if (item.userId !== user.userId) {
request.respond(statusCodes.FORBIDDEN, ‘Access Denied.');
} else {
request.execute();
}
}
* Complete script reference can be found at:
http://msdn.microsoft.com/en-us/library/windowsazure/jj554226.aspx
Push Notifications
• Allows direct push to devices
• Supported push services:
– GCM (API key required)
– APNS (Certificate required)
– WNS (Client secret & Package SID required)
N.B: For Windows Phone/WNS: 500 notifications/per user/per day.
Implementing Push Notifications
(in 5 easy steps)
Code walkthrough
Push Notifications: Step 1
Register App for Notifications
• GCM is the native push system for Android
• Register your app and enable GCM using
Google API console
(https://code.google.com/apis/console/)
Push Notifications: Step 2
Configure Mobile Services
• Copy generated API key from Google API
Services
• Select ‘Push’ from Azure Console and paste
key
Push Notifications: Step 3
Integrate push library to your app
• Copy gcm.jar to libs
• Add permissions
<permission android:name=“com.test.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name=“com.test.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
• Add reciever/services
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name=“com.test" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
Push Notifications: Step 4
Register your device & handle pushes
• Assuming you have ‘deviceId’ field on your data model:
String deviceId = GCMRegistrar.getRegistrationId(this);
Users.deviceId = deviceId;
//save here
• When a push arrives, onMessage fires:
protected void onMessage(Context context, Intent intent) {
//notify user etc.
}
http://developer.android.com/google/gcm/gs.html
Push Notifications: Step 5
Getting the server to notify
function insert(item, user, request) {
request.execute({ success: function() {
request.respond();
push.gcm.send(Users.deviceId, item.text);
}
}
Diagnostics, Logging and Scale
• Diagnostics:
– CPU Time
– Memory consumptions
– API calls/time taken per request
• Logging
– With server scripts via console.x (console.info,
console.error etc)
• Scale
– Scale up or down by spinning up new VMs or by
scaling up VM size
More Services
• Scheduler
– Schedule server scripts on demand or on interval
– Examples:
• Purge old data,
• Poll/aggregate data from other sources
• Schedule pushes to be sent at a certain time
• SendGrid (3rd
party service)
– Email-As-A-Service
• Pusher (3rd
party service)
– Enhanced push services (among other things)
Thank you

Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Apps using Windows Azure

  • 1.
    Building Scalable CloudConnected Mobile Apps using Windows Azure Jahufar Sadique (99X)
  • 2.
    What is WindowsAzure Mobile Services? • A set of services build on Azure that provides backend ‘plumbing’ to your mobile apps. • Focus on building apps and not backend logic – Data (dynamic schema) – Authentication (Federated identities such as Facebook, Google, Twitter, Windows Live) – Server Logic (via Mobile Services Server Scripts) – Push Notifications (GCM, APNS, WNS) • Monitoring/Analytics/Logging infrastructure • Client SDKs supported for Android, iOS, Windows Phone and HTML/Javascript
  • 3.
    Getting Started • Theservice is not free • ..but comes with a 3 month free trial (subject to credit card verification) • What you get: http://www.windowsazure.com/en- us/pricing/free-trial/
  • 4.
    • DEMO: AzureDashboard • DEMO: Creating a new mobile service • DEMO: Download the SDK and setup project
  • 5.
    Mobile Service: Data •Backend is Windows Azure SQL Database • Dynamic schema – create your model in code, and the fields are mapped by magic • Throttling and failures are automatically handled. • NO RELATIONS (i.e. no foreign keys, cascade logic etc)
  • 6.
  • 7.
    Authentication • Authenticate against:Facebook, Google, Twitter, Windows Live • Table level permissions for CRUD operations: – Everyone (default) – Only authenticated users – Only scripts and admins
  • 8.
  • 9.
    Server Scripts • Similarto a trigger • Allows you to build custom business logic when something happens to your data • Available operations: insert, update, read, delete (del) e.g.: function insert (id, user, request) { request.execute(); }
  • 10.
    Server Scripts: Continued Insert:function insert(item, user, request) { } Update: function update(item, user, request) { } Delete: function del(id, user, request) { } Read: function read(query, user, request) { } •Script functions always take 3 arguments: – 2nd arg is always “user” (represents a user) – 3rd arg is always “request” (used to send responses). – 1st arg changes according to operation
  • 11.
    Scripts: Continued • Example: functioninsert(item, user, request) { if (item.userId !== user.userId) { request.respond(statusCodes.FORBIDDEN, ‘Access Denied.'); } else { request.execute(); } } * Complete script reference can be found at: http://msdn.microsoft.com/en-us/library/windowsazure/jj554226.aspx
  • 12.
    Push Notifications • Allowsdirect push to devices • Supported push services: – GCM (API key required) – APNS (Certificate required) – WNS (Client secret & Package SID required) N.B: For Windows Phone/WNS: 500 notifications/per user/per day.
  • 13.
    Implementing Push Notifications (in5 easy steps) Code walkthrough
  • 14.
    Push Notifications: Step1 Register App for Notifications • GCM is the native push system for Android • Register your app and enable GCM using Google API console (https://code.google.com/apis/console/)
  • 15.
    Push Notifications: Step2 Configure Mobile Services • Copy generated API key from Google API Services • Select ‘Push’ from Azure Console and paste key
  • 16.
    Push Notifications: Step3 Integrate push library to your app • Copy gcm.jar to libs • Add permissions <permission android:name=“com.test.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name=“com.test.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> • Add reciever/services <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name=“com.test" /> </intent-filter> </receiver> <service android:name=".GCMIntentService" />
  • 17.
    Push Notifications: Step4 Register your device & handle pushes • Assuming you have ‘deviceId’ field on your data model: String deviceId = GCMRegistrar.getRegistrationId(this); Users.deviceId = deviceId; //save here • When a push arrives, onMessage fires: protected void onMessage(Context context, Intent intent) { //notify user etc. } http://developer.android.com/google/gcm/gs.html
  • 18.
    Push Notifications: Step5 Getting the server to notify function insert(item, user, request) { request.execute({ success: function() { request.respond(); push.gcm.send(Users.deviceId, item.text); } }
  • 19.
    Diagnostics, Logging andScale • Diagnostics: – CPU Time – Memory consumptions – API calls/time taken per request • Logging – With server scripts via console.x (console.info, console.error etc) • Scale – Scale up or down by spinning up new VMs or by scaling up VM size
  • 20.
    More Services • Scheduler –Schedule server scripts on demand or on interval – Examples: • Purge old data, • Poll/aggregate data from other sources • Schedule pushes to be sent at a certain time • SendGrid (3rd party service) – Email-As-A-Service • Pusher (3rd party service) – Enhanced push services (among other things)
  • 21.