TechEd North America 2014, Houston
What’s New in Mobile Services and Notification Hubs – Elio Damaggio, Miranda Luna
Day 2, 13 May 2014, 3:15PM-4:30PM (DEV-B330)
Disclaimer: This post contains my own thoughts and notes based on attending TechEd North America 2014 presentations. Some content maps directly to what was originally presented. Other content is paraphrased or represents my own thoughts and opinions and should not be construed as reflecting the opinion of either Microsoft, the presenters or the speakers.
Executive Summary—Sean’s takeaways
-
Mobile Services is turnkey back-end service for mobile apps
- Adds features that you don’t need to write yourself
- Microsoft manages/runs/monitors back-end service
-
Lots of new stuff in Mobile Services
- Offline sync, push with Notification Hubs, etc.
-
Offline sync – for apps that are sometimes connected
- Easily sync with Push/Pull paradigm
- Hybrid Connections allow mobile app to connect to on-premise resource that has static IP
-
Push notifications in Mobile Services now use Notification Hubs
- High volume, low latency
- Use Push to silently sync app
Miranda Luna, Product Manager, Azure Mobile Team, Microsoft – @Mlunes90
Agenda
- Mobile Services Updates
- Notification Hubs Updates
- Questions & Resources
Mobile Services Investment Areas
-
What’s New
- .NET backend – Web API on server
- Heterogeneous data
- Hybrid connections – between on-prem and Azure
- Offline sync – occasionally-connected scenarios
- Xamarin
- AAD Authentication – Azure Active Directory
- Visual Studio – tighter integration
- API Management – publishing/managing access to API
- Notification Hubs – easier now to achieve high volume, low latency
- Sencha
Azure Active Directory
- Extend line-of-business to mobile
- Adds notion of AD user in Mobile Services
- Enable applications built around organizational structures
Active Directory Authentication Library (ADAL)
- Enables single sign-on
Basic ADAL + Mobile Services Flow
- Access Token / Refresh Token
Access resources on behalf of the user
- Mobile Service passes Access Token to AAD along with requested resource URI
Mobile Services .NET
- Easy backend
- Logic via .NET Web API
- Turn-key Mobile Backend Capabilities
- Local debugging
- Flexible data model
-
Client SDKs for major platforms
- iOS, Android, Windows, WinPhone, Xamarin, PhoneGap, Sencha
- Integration with on-premise systems
- We Manage/Run/Monitor your backend for you
Diagram showing data flow for Mobile Services – Value Add
- Service the runtime without restarting your app
- Can inject strings into app.config
New data model – Green field
- DataManager – DTO – Entity for SQL
Existing data model – Brown field
- DataManager – DTO / AutoMapper / Model
- Maps to existing database
Offline support
- Applications that are occasionally connected
- Conflict resolution – users
- Explicit Push/Pull to/from Mobile Service
- TableController – with optimistic concurrency
Offline support
- Store table operations in local data store
- SQL-lite out of the box
- Can use what’s out of the box or roll your own
Offline Methods
- PushAsync – on entire context
-
PullAsync – pull all or a subset of items from remote
- Pull triggers a push, for data inconsistency
-
PurgeAsync
- Clear local cache to update data which app no longer needs
- Purge triggers a push
Handling Offline Conflicts – code snippet
Hybrid Connections
- Fastest way to consume on-premises resources in Mobile Services app
- Connect to any on-premises resource that uses static TCP port
- BizTalk Services hybrid connections
API Management
- Mobile Services, Web Sites – Build & Host
-
API Management – Publish & Manage
- Acquisition – “Epiphany”
API Management diagram
- Admin portal – where you set policies, etc.
- Developer portal
API Management Features
- ADAPT
- EXPOSE – discovery
- PROTECT – authorization, quotas, rate limits
- UNDERSTAND – usage, health, latency, activity, trends
- MANAGE – lifecycle, versioning, monitoring
Elio Damaggio, Product Manager, Azure Mobile, Microsoft
@ElioDamaggio
Push Notifications
Notification Hubs – Azure hub that deals specifically with Push Notification
What’s New
- Kindle support
- Tag expressions
- Visual Studio integration – send debug notifications
- Mobile Services integration
- New push-based pricing – based on # pushes
- Build registration management APIs
- Xamarin
Push Notifications
- Push 101
- Use Notification Hubs ..
Push 101
Mobile push is everywhere
- Toasts, etc. in notification center
- E.g. breaking news, SMS replacement
- Healthcare LOB, e.g. prescription reminders
- Travel, etc.
Push notification lifecycle
-
Registration at app launch
- Retrieve current channel
- App updates handled in back-end
-
Sending Notification
- App back-end send notification to PNS (Platform Notification Service)
- PNS pushes notification to the app on the device
-
Maintenance
- Delete expired handles when PNS rejects them (tokens expire)
Challenges of push notifications
-
Platform dependency
- Different communication protocols
- Different presentation formats and caps
-
Routing
- PNS provides way to send message to device/channel
- Notifications targeted at users or interest groups
- App back-end has to maintain registry associating device handle to interest groups/users
-
Scale
- App back-end has to store handles for each device – high storage and VM costs
- Broadcast to millions of devices with low latency requires parallelization
Advantages of using Notification Hubs
-
Cross-platform
- REST-based
- Support many client platforms
-
No need to store device information in the app back-end
- Notification Hub does this
-
Routing and interest groups
- Target individual users and large interest groups using tags
- Free form, can use them for user IDs or for interest groups
- From single user/device to big groups
-
Personalization and localization
- Keep back-end free of presentation concerns like localization and user prefs using templates
-
Broadcast at scale, multicast, unicast
- Push notifications to multiple devices with single call
-
Telemetry
- Through portal or APIs
Using Notification Hubs
-
One-time setup
- Create Notification Hub
-
Register
- Client app gets handle from PNS
- App updates registration
Some snippets
- Register and Send
Tags
-
Tags as interest groups
- When device registers, it specifies a set of tags
-
You can use tags for
- Interest groups
- Tag devices with user id
- No need to pre-create
Tag expressions
- E.g. “all my group except me”
- OR, AND, NOT, etc.
- Send notifications at specific times, or to time zones
- Versions and platforms
Case Studies
-
Bing apps
- All use Notification Hubs to power their notifications
- 10s of millions of devices
- 3 million notifications/day
- <2 minutes to deliver
-
Sochi 2014
- 100s of interest groups (countries, disciplines, athletes)
- Localized notifications
- 3+ million devices
- 150+ million notifications, over 2 weeks
Notification Hubs & Mobile Services
New push engine for Mobile Services
- Based on Notification Hubs (powered by)
-
No more Channels table
- Simple two steps process to push notifications, no data handling
- 1 Unit of Notification Hubs included for free
- Node.js and .NET (back-ends)
From Mobile Services
- Register and Push
Secure tags for push to users
- Cases when Push used to enhance responsiveness of app
Register from your back-end
-
When tags have to be secured
- E.g. userId for tag
- App back-end can authenticate user before registering the device
- Mobile app can’t connect notification hub directly
-
When back-end has to modify tags
- Tags might depend not on user prefs, but on other global things
- Back-end has access to add/remove tags from what device sends
Registering from the back-end
-
Identify your device
- Keep long-living NH registration ids in device storage
-
Register
- First time only, on app start – get registration id from hub, store in local storage
- CreateOrUpdate device registration (every app start)
- Back-end can verify and/or add tags (e.g. performing authentication)
-
Notes
- Nothing stored in app back-end, not doing device management
- Don’t use device SDK – will create multiple things
Back-end driven tag updates
-
Use tag to identify user
- Back-end refers to users and not devices
- Register devices with tag like userid
-
Back-end updates tags
- Retrieve device registration by userid
-
Note
- No device information in back-end
- Back-end only refers to users
Very easy with Mobile Services (.NET)
- Registrations already through through back-end
- Just login the user in the device
- Register from device (RegisterNativeAsync)
-
Implement registration callback to inject user tag
- InotificationHandler.Register
-
Push to user
- SendAsync to user ID
Secure Push & Rich Push
-
Deliver content directly from back-end
- Rich media
- Retrieve content securely from BE
- Will look the same to user, but data won’t go through cloud service
-
Notes
- Platform dependent
- Secure push has to use long-lived auth token on app
- App pulls data directly from back-end, but not yet showing anything to user
Push to Sync
-
Updates app state
- Does not show message to the user
-
Example: music app
- User changes playlist on desktop
- Back-end send push-to-sync notifications to user’s devices
- Even w/o opening app
- User finds the new song already on their phone
-
User this feature with Offline feature of Mobile Services – local store
- So everything just already right there
- “This is what people expect from mobile apps” – no waiting
-
Platform-dependent
- Windows, et al
Telemetry
- Portal dashboard, programmatic access for all PNS outcomes
-
Security
- Role-based security available to restrict access to hub for various rights
-
Scale
- Guidance for high scale depends on specific scenarios
- <5 million devices and <5 million pushes per day can just use single hub – no problem
Pricing
- $20/unit/mo (“unit” is NH)
- 500,000 pushes per unit per month
Miranda again
Azure Mobile
Microsoft is making a massive investment to provide an end-to-end story for cross-platform mobile app development and management