Difference between azure notification hub and azure mobile services

Rusty picture Rusty · Oct 17, 2013 · Viewed 12.2k times · Source

What are the main differences between azure notification hub and mobile services

Which is best to use when.

Thanks

Answer

Gene picture Gene · Oct 17, 2013

Those services have a totally different purpose.

Mobile Services allow you to provide a backend to (mobile) devices running your apps. Imagine a database that is exposed via a REST based API. You can react on CRUD operations by writing JavaScript code (Azure uses node.js for this purspose) and restrict the access to the database. This allows you to rapidly develop new apps (or at least proofs). Via JavaScript you can send push notifications by communicating the Windows Notification Service (WNS), the Apple Push Notification Service (APNS), etc. or by accessing an Azure Notification Hub, but that's not a native capability provided by the Mobile Services, it's just talking to external services.

Azure Notification Hub allows you to manage push subscriptions on multiple platforms (iOS, Android, WP8, Windows Store) with one single component. You no longer need to track the subscriptions in your own tables (like you would need to do with a solution just based on Mobile Services) and don't need to care about scaling. Imagine different devices registering at this hub and you have the ability to send a push message to those devices without the need to know, what kind of device you're talking to. It's just an abstraction of pushing messages.

To clearify:

Pseudo code with manual subscription handling vs. Notification Hub. Manual way with direct communication with WNS/APNS/...:

// query your data tables to determine the devices to notify
// note, that you need to manage (insert, delete) all of those entries as well
var subscriptions = ...; 

for (var subscription in subscriptions ) 
{
  if (subscription.Type == 0) // WP8
  {
    // communicate with the Windows Phone push service to push
  }
  else if (subscription.Type == 1) // iOS
  {
    // communicate with the Apple Push Notification Service push
  }
  else if // etc.
}

With Notification Hubs:

// determine subscriptions to notify by tag, it's just that simple
var tag = 'player:12345'; 

var hub = azure.createNotificationHubService(/* credentials */);

// you don't need to care about WNS/APNS/..., the hub will do that for you
hub.send(tag, yourMessage, /* callback */);

I hope you get the picture.