Thursday, 28 November 2013

Windows Azure Mobile Services has great built-in support for
making Push Notifications; however there’s a better more scalable option using
the Notifications Hub which is part of the Service Bus group of services.

We can call the hub from external backend services using the
Windows Azure Service Bus SDK (NuGet PM> Install-Package
WindowsAzure.ServiceBus) and this is fairly well documented; however if you
want to do a direct replacement for the build-in Push Notifications using
Notifications Hub, it’s not so well documented. I did some digging in the
source to work out how to use it: https://github.com/WindowsAzure/azure-sdk-for-node

In our Mobile Services scripts we can make use of NPM
packages which we install ourselves and pre-installed packages like the Windows
Azure SDK for Node which we will use for calling the Hub.

Accessing the Notifications Hub

We need two things to allow us to connect to the hub and
those are the DefaultFullSharedAccessSignature which you can get from the
Notifications Hub Dashboard and the Hub name. We can declare these as variables
like this:

Registering with the Hub from a Windows 8 App

This example shows how to register a Windows 8 Store App
with the DefaultListenSharedAccessSignature connection string this time (from
the Notifocations Hub Dashboard). This registers two tags, but you can use null
to receive everything: