2015.04.23 Azure Mobile Services

Preview:

Citation preview

Azure Mobile ServicesMarco ParenzanMicrosoft MVP 2014 for Azure

1nn0va / marco.parenzan@1nn0va.it

#CDays15 – Milano 24, 25 e 26 Marzo 2015

Speaker info/Marco Parenzan

Formazione & Divulgazione con 1nn0va

Microsoft MVP 2014 for Microsoft Azure

www.slideshare.net/marco.parenzan

www.github.com/marcoparenzan

marco [dot] parenzan [at] 1nn0va [dot] it

www.1nnova.it

@marco_parenzan

Cloud Architect.NET developerLoves Functional Programming, Html5 Game Programming and Internet of Things

Microservices

Saturday 2015:

un viaggio con

NServiceBus LI

VE

IoT Day - 08/05/2015

Introduction

Why Employee Mobile Apps?

•Deliver apps never possible before

•Employees demand mobile experiences

• Increasingly businesses are mobile-first

Mobile Services: A Turnkey Backend for Employee Mobile Apps

• Deliver Native & Cross Platform Apps

• Enable Corporate Single Sign-On

• Integrate w/ O365 and On-Premise Enterprise Systems

• Connect To Any Data Source

• Enable Offline and Real-Time Sync

• Leverage Your Existing Skills with .NET Web API

Internet of Things

Con Microsoft Azure IoT services, si possonomonitorare assets, incrementare l’efficienza, spingere le performance operative per abilitare le innovazioni, ed utilizzandomeccanismi di data analytics avanzati si puòtrasformare la propria azienda con nuovibusiness models e revenue streams.

Event Hubs

Notification Hubs

Stream Analytics

Machine Learning

HDInsight

Power BI for Office 365

Azure Steaming Analytics

Mobile Services

Storage

Authentication

Logic

Push

Scheduler

• Fornisce servizi essenzialiper lo sviluppo di Client

• Client Supportati• iOS

• Android

• HTML5/Web

• Xamarin

• Windows

• Windows Phone

• PhoneGap

• Sencha

API APPS

Easily build and consume APIs in the cloud

WEB APPSWeb apps that scale with your

business

LOGIC APPS

Automate business process across SaaS and on-premises

MOBILE APPS

Build Mobile apps for any device

Azure App Service

Node.js

11

request push.*

console mssql

tables azure

sendgrid

pusher

twilio

Node.js scripts

Demo: Getting Started with Mobile Services

Backend Logic:.NET

.NET Backend

• Web API based w/ additional functionality, developed in and deployed from Visual Studio

• TableController data context can map to SQL, Table Storage, Mongo, etc

• Pull in NuGet modules and other .NET libraries

• Set permissions with attributes on classes

• Local Debug

14Microsoft Azure

The REST API

15

Action HTTP Method URL Suffix

Create POST /TodoItem

Read GET /TodoItem?filter=id%3D42

Update PATCH /TodoItem/id

Delete DELETE /TodoItem/id

Microsoft Azure

Base Endpoint: https://MobileService.azure-

mobile.net/tables/*

Structured Storage

• Powered by SQL Database

• Supports rich querying capabilities

• Dynamic Schematization

• Data management in:• Azure Portal

• SQL Portal (Silverlight)

• SQL Management Studio

• REST API

• Azure CLI Tools

• SQL CLI

16Microsoft Azure

Auto-generated Columns

• id – unique guid

• __createdAt – date

• __updatedAt – date

• __version – timestamp• Helps with concurrency and offline

17Microsoft Azure

JSON to SQL Type Mappings

18

JSON Type T-SQL Type

Numeric values (integer, decimal,

floating point)

Float(53)

Boolean bit

DateTime DateTimeOffset(3)

String Nvarchar(max)

Microsoft Azure

Custom API

• Non-table based endpoints

• Accessible from• GET

• POST

• PUT

• PATCH

• DELETE

• For node.js logic in scripts like table endpoints

• For .NET delivered through a WebAPI

• Expose any functionality you want

19Microsoft Azure

File Storage

• Don’t store files in Mobile Services DB

• Use Mobile Service to provide a Valet Key Pattern to Blob Storage, aka BLOB SAS• Create table / custom API script to talk to Blob Storage

• Script generates Shared Access Signature (SAS) URL

• Script returns SAS URL to client app

• Client app uploads data to blob storage directly

• Store file URL in Mobile Service DB as needed

• Blob storage costs less and is built for redundant file storage

• Resource Broker extension for .NET and Node backends

20Microsoft Azure

Demo: .NET Table API

Offline Sync

Mobile Services Offline Support

•Easily enable “occasionally-connected” scenarios

•Simple lightweight client APIs

•Support multiple backend data stores

•Works with both .NET and NodeJS backend

Offline support

TableController

(with optimistic

concurrency)

Mobile ServiceDevice

SQL Database

BYOD

MongoDB

Table Storage

SQLite

Explicit Push/Pull

Conflict resolution

Offline Sync: Potential Uses

• Improve app responsiveness by caching server data locally on the device

•Make apps resilient against intermittent network connectivity

• Allow end-users to create and modify data even when there is no network access, supporting scenarios with little or no connectivity

• Sync data across multiple devices and detect conflicts when the same record is modified by two devices

25

Demo: being offline

Authorization&Authentication

Data Authorization

Per HTTP method auth options:• App Key Required

• Not ideal for production use

• Everyone

• Authenticated Users

• Admins and other scripts• Requires Master Key as header

401 Unauthorized response if security check fails

28Microsoft Azure

User Auth Flow (server)

29Microsoft Azure

GOOGLE

FACEBOOK

TWITTER

MOBILE SERVICE

DEVICE

MICROSOFT

ACCOUNT

AAD

User Auth Flow (client)

30Microsoft Azure

GOOGLE

FACEBOOK

TWITTER

MOBILE SERVICE

DEVICE

MICROSOFT

ACCOUNT

AAD

The User object

User.level• Admin

• Authenticated

• Anonymous

User.userId• Provider:id or undefined

User.getIdentities() • UserId

• Provider Access Token / Secret

• Basic user information (i.e. name, username, locale, picture, link)

31Microsoft Azure

Azure Active Directory and Mobile Services• Extend line-of-business to mobile

• Bring turn-key login experience with corporate credentials to mobile developers

• Enable applications built around organizational structures

• Make AAD users a first-class concept in Mobile Services, with push-to-user and per-user data

Demo: Adding Auth

Push Notifications

Notification Hubs

• Separate from Mobile Services• Can be used regardless of whether you’re storing data in Azure

• Extremely scalable push notifications

• Cross platform support• Push to iOS, Android, Kindle, Windows Phone, Windows Store

• Tags (i.e. tie my registration to this topic or user ID)

• Templates (i.e. when I get a push, send it in this format)

• Server SDKs for .NET, Java, and Node (also open as REST API)

35Microsoft Azure

Push Notification Flow

36Microsoft Azure

Demo: Adding Push Notifications

Advantages of using Notification Hubs

X-plat: from any back-end to any mobile platform• Backend can be on-prem or in the cloud, .NET, Java, PHP, Node, you name it

• Support IOS, Android, Windows Phone, Windows, Kindle

Avoid storing device information in the app back-end• Notification Hub maintains the registry of devices and the associations to users/interest groups

Work with logical users and segments• Target individual users and large interest groups using tags

Personalization and localization• Keep your back-end free of presentation concerns like localization and user preferences using templates

Broadcast at scale, multicast, unicast• Push notifications to millions of devices (across platforms) with a single call

Telemetry• Rich telemetry available through portal or APIs

Notify all users

•Broadcast a notification to all users by making a single API from your app backend w/o specifying any tags

App back-end

App back-endNotification Hub

Notify a single logical user

•Tags can be used to represent individual logical users • Client app authenticates with the

app backend• Client app passes device handle to

the app backend• App backend registers the devices

for the tag “userId”• Target individual users by

specifying particular “userId” tag App back-end

Client app

2

3

Notification

Hub

4

1 4

Demo: “Toasting” users

DiagnosticsLoggingScale

Diagnostics, Logging, Scale

43

API Calls, # of Devices,

Data Out

Console Logging (auto

error logging)

Scale Service Based off API

CallsAuto-scale to Save Money

Free Tier for Mobile Free Tier for SQL

Mobile Service Scaling

Free: 500k calls / month / subscription

Basic: 1.5M calls / unit (6) / month

Standard: 15M calls / unit (10) / month

Microsoft Azure

Demo: tracing info

Conclusions

Mobile Service Tiers

47

FREE 1 BASIC STANDARD

Price2

Free

(up to 10 services / month)

€11.17 / month

per unit

€104.26 / month

per unit

API Calls2

500 K 1.5 M / unit 15 M / unit

Active Devices3

500 Unlimited Unlimited

Scale N/A Up to 6 units Unlimited units

Push Notifications Notification Hubs Free Tier included,

up to 1 M pushes

Notification Hubs Basic Tier included,

up to 10 M pushes

Notification Hubs Standard Tier included,

up to 10 M pushes

Real time messaging & Web Sockets Limited 350 / mobile service Unlimited

Offline synchronizations Limited Included Included

Scheduled jobs4

Limited Included Included

SQL Database5

(required)

20 MB included,

Standard rates apply for additional

capacity

20 MB included,

Standard rates apply for additional

capacity

20 MB included,

Standard rates apply for additional capacity

CPU capacity 60 minutes / day Unlimited Unlimited

Outbound data transfer 165 MB per day (daily Rollover)* Included Included

Recommended