47
Azure Mobile Services Marco Parenzan Microsoft MVP 2014 for Azure 1nn0va / [email protected]

2015.04.23 Azure Mobile Services

Embed Size (px)

Citation preview

Page 1: 2015.04.23 Azure Mobile Services

Azure Mobile ServicesMarco ParenzanMicrosoft MVP 2014 for Azure

1nn0va / [email protected]

Page 2: 2015.04.23 Azure Mobile Services

#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

Page 4: 2015.04.23 Azure Mobile Services

Introduction

Page 5: 2015.04.23 Azure Mobile Services

Why Employee Mobile Apps?

•Deliver apps never possible before

•Employees demand mobile experiences

• Increasingly businesses are mobile-first

Page 6: 2015.04.23 Azure Mobile Services

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

Page 7: 2015.04.23 Azure Mobile Services

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

Page 8: 2015.04.23 Azure Mobile Services

Azure Steaming Analytics

Page 9: 2015.04.23 Azure Mobile Services

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

Page 10: 2015.04.23 Azure Mobile Services

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

Page 11: 2015.04.23 Azure Mobile Services

Node.js

11

request push.*

console mssql

tables azure

sendgrid

pusher

twilio

Node.js scripts

Page 12: 2015.04.23 Azure Mobile Services

Demo: Getting Started with Mobile Services

Page 13: 2015.04.23 Azure Mobile Services

Backend Logic:.NET

Page 14: 2015.04.23 Azure Mobile Services

.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

Page 15: 2015.04.23 Azure Mobile Services

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/*

Page 16: 2015.04.23 Azure Mobile Services

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

Page 17: 2015.04.23 Azure Mobile Services

Auto-generated Columns

• id – unique guid

• __createdAt – date

• __updatedAt – date

• __version – timestamp• Helps with concurrency and offline

17Microsoft Azure

Page 18: 2015.04.23 Azure Mobile Services

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

Page 19: 2015.04.23 Azure Mobile Services

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

Page 20: 2015.04.23 Azure Mobile Services

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

Page 21: 2015.04.23 Azure Mobile Services

Demo: .NET Table API

Page 22: 2015.04.23 Azure Mobile Services

Offline Sync

Page 23: 2015.04.23 Azure Mobile Services

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

Page 24: 2015.04.23 Azure Mobile Services

Offline support

TableController

(with optimistic

concurrency)

Mobile ServiceDevice

SQL Database

BYOD

MongoDB

Table Storage

SQLite

Explicit Push/Pull

Conflict resolution

Page 25: 2015.04.23 Azure Mobile Services

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

Page 26: 2015.04.23 Azure Mobile Services

Demo: being offline

Page 27: 2015.04.23 Azure Mobile Services

Authorization&Authentication

Page 28: 2015.04.23 Azure Mobile Services

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

Page 29: 2015.04.23 Azure Mobile Services

User Auth Flow (server)

29Microsoft Azure

GOOGLE

FACEBOOK

TWITTER

MOBILE SERVICE

DEVICE

MICROSOFT

ACCOUNT

AAD

Page 30: 2015.04.23 Azure Mobile Services

User Auth Flow (client)

30Microsoft Azure

GOOGLE

FACEBOOK

TWITTER

MOBILE SERVICE

DEVICE

MICROSOFT

ACCOUNT

AAD

Page 31: 2015.04.23 Azure Mobile Services

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

Page 32: 2015.04.23 Azure Mobile Services

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

Page 33: 2015.04.23 Azure Mobile Services

Demo: Adding Auth

Page 34: 2015.04.23 Azure Mobile Services

Push Notifications

Page 35: 2015.04.23 Azure Mobile Services

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

Page 36: 2015.04.23 Azure Mobile Services

Push Notification Flow

36Microsoft Azure

Page 37: 2015.04.23 Azure Mobile Services

Demo: Adding Push Notifications

Page 38: 2015.04.23 Azure Mobile Services

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

Page 39: 2015.04.23 Azure Mobile Services

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

Page 40: 2015.04.23 Azure Mobile Services

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

Page 41: 2015.04.23 Azure Mobile Services

Demo: “Toasting” users

Page 42: 2015.04.23 Azure Mobile Services

DiagnosticsLoggingScale

Page 43: 2015.04.23 Azure Mobile Services

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

Page 44: 2015.04.23 Azure Mobile Services

Mobile Service Scaling

Free: 500k calls / month / subscription

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

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

Microsoft Azure

Page 45: 2015.04.23 Azure Mobile Services

Demo: tracing info

Page 46: 2015.04.23 Azure Mobile Services

Conclusions

Page 47: 2015.04.23 Azure Mobile Services

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