Azure Notification Hubs: Key features and use cases 

In the digital ecosystem, the efficiency of communication directly correlates with user engagement and satisfaction. Azure Notification Hubs serve as a pivotal element in this communication chain, offering developers a scalable and reliable platform to send notifications across various devices and platforms.

Azure Notification Hubs is a highly scalable mobile push notification engine by Microsoft that is compatible with all significant platforms like

  • APNs (Apple Push Notification Service)
  • GCM (Google Cloud Messaging)
  • WNS (Windows Push Notification Service)
  • MPNS (Microsoft Push Notification Service)

The Notification Hub can filter push notifications based on a customer, location, or any custom-defined tag.

This capability enables quick delivery of millions of notifications to iOS, Android, Windows, or Kindle devices.

With the Notification Hubs tagging functionality, you can send push alerts to everyone at once or narrow it to specific customer devices. Tags allow you to segment users by activity, interest, geography, or preference, ensuring that the right content gets delivered to the correct person at the right time. A tag could be up to 120 characters long string that includes alphanumeric and non-alphanumeric characters.

Azure Notification Hubs: Key features and use cases The notification tagged with Data_Scientist only reaches the device registered with the tag Data_Scientist, as shown in the diagram.

While sending a push notification with Notification Hubs, tag expressions allow you to target specified groups of devices or, more precisely, registrants. We can target individual device registrations only by associating tags with specific device registrations and then targeting those tags.

Both commercial and consumer scenarios benefit from Notification Hubs. Here are a few things you can do:

  • Send minimal latency breaking news alerts to millions of people.
  • Send coupons to user segments who are interested based on their location.
  • For media, sports, social, gaming, or e-commerce apps, send event or deals-related notifications to users or broadcast to groups.
  • To attract and advertise to customers, push promotional information to apps.
  • To notify a user about the status of an activity performed.

Push notifications play a crucial role in boosting user engagement in consumer apps and delivering real-time business updates in enterprise applications. They are efficient on mobile devices, customizable for senders, and remain accessible even when apps are not active, making them the preferred communication service from apps to users.

Below in this article, we will cover:

  1. Configuring the Notification Hub for APNs
  2. Prerequisite for Registering / Viewing / Deleting the devices with Notification Hub,
  3. Registering the devices,
  4. Viewing the registered devices,
  5. Deleting the registered devices.

 

1. Configuring the Notification Hub for APNs

Prerequisites:

  • A Notification Hub deployed in the Azure portal. In case you need to create a Notification Hub refer to this Documentation.
  • In case of Certificate-based authentication, you must have a .p12 certificate file available with the password.
  • In the case of Token-based authentication, you will require Team ID, Bundle ID, Key ID, and a Token value from a .p8 certificate file.
  • You can generate the above prerequisite details for authentication modes by following this Documentation.

To configure the Notification Hub with Apple Push Notification Services, we have two Authentication modes available as below:

  • Certificate-based
  • Token-based

You can select either Certificate or Token,

For Certificate-based mode:

  • Select the file icon and select the .p12 file from your local system that you want to upload.
  • Enter a password associated with the certificate file.
  • Select Sandbox mode while in development, select Production mode to send push notifications to users who purchased your app from the store.

Azure Notification Hubs: Key features and use cases 

For Token-based mode:

  • Enter the values for Key ID, Bundle ID, Team ID, and Token (obtained from a .p8 certificate file).
  • Like Certificate-based mode, Select Sandbox mode while in development and select Production mode to send push notifications to users who purchased your app from the store.

Azure Notification Hubs: Key features and use cases 

 

2. Prerequisite for Registering / Viewing / Deleting the devices with Notification Hub

To Register, View, or Delete the devices with the Notification Hub, we have HTTP’s PUT, GET and DELETE REST API methods. The first and foremost requirement to access these APIs is to generate the SAS Token, used as Authorization Header.

The Authorization Header should consist of Token generated as specified in SAS Authentication and authorization with Microsoft Azure Active Directory Access Control.

Microsoft provides a guide to generate SAS tokens using multiple programming languages for using Azure Service Bus REST APIs in this Document.

For the Python approach to generate SAS tokens for using Azure Service Bus REST APIs, we would require a few details as mentioned below:

  • Namespace Name: The Namespace resource name associated with Notification Hub (namespace could contain one or multiple hubs).
  • Notification Hub Name: The Notification Hub resource name.
  • SAS Name: The Shared Access Key Name.
  • SAS Value: The Shared Access Key Value.

You can find the Namespace name and Notification Hub name from the portal when you navigate to Notification Hub in the overview section, as shown below:

Azure Notification Hubs: Key features and use cases 

You can find those details for the SAS name and value parameters when navigating to Access policies under the Manage section in the left panel.

You can find two policies with different permissions. We require the details from the “DefaultFullSharedAccessSignature” policy since it has Full permissions (Listen, Manage, Send).

Azure Notification Hubs: Key features and use cases 

We require copying the connection string from DefaultFullSharedAccessSignature policy, which looks like something shown below and contains the Shared Access Key name and its value.

Azure Notification Hubs: Key features and use cases 

These details would be required to generate the SAS Token as Authorization Header for accessing APIs.

3. Registering the devices with Notification Hub

Using a Registration or Installation approach, we can accomplish the registration of devices with a Notification Hub.

An installation/registration will associate the PNS handle with tags that we maintain to send a notification to the appropriate user rather than broadcasting them. In the case of APNs, the PNS handle is a unique device token for each device, and to segregate device handles; we can then use Tags.

Note: Notification Hubs allow a maximum of 60 tags for each device. 

Compared to the Registration approach, an Installation approach is a much-enhanced approach to registering a device that provides multiple push-related properties. It is the recently developed and enhanced approach to registering your devices with Notification Hub.

Microsoft provides REST APIs for registration and installation, which are user-friendly and require minimal details. Just a Device Token for APNs is enough to register the device with Notification Hub. At the same time, the Tags are an optional element.

Below are a few critical points discussed to choose Installation over Registration for registering the device with Notification Hub:

  • We could use installation REST APIs to repeatedly make that same call while producing the same result, without any second thought of creating Duplicate registration. It would overwrite the existing registration while reflecting the latest change, if made any. 
  • The Installation approach provides an exceptional Tag format $InstallationId:{<INSTALLATION_ID_GOES_HERE>}, which enables the Notification Hub to classify the unique devices and send the notifications to particular devices rather than broadcasting them. 

Suppose a user provides Installation id as testinstallation123 for a particular device while registering with Notification Hub. He could then direct the message to the specific device only by applying $InstallationId:{testinstallation123} Tag, without even doing any extra programming stuff to do so. 

This article would move forward with the Installation Approach and a popular tool like Postman to make API calls to register, view, and delete the devices with Notification Hub. 

Microsoft provides multiple REST API Methods to perform these tasks, and we would be using Installation REST API for registering the devices with our Notification Hub: 

Prerequisites:  

  • Namespace Name 
  • Notification Hub Name 
  • SAS Token for Authorization Header 
  • PNS Handle from iOS device 

As discussed earlier in Prerequisite for Registering / Viewing / Deleting the devices with Notification Hub section, we will require the SAS Token generated for Authorization Header, which will look similar to as shown below: 

Azure Notification Hubs: Key features and use cases 

And the request body would contain parameters and their value as below: 

  • installationid: Any uniquely identifiable string value. 
  • tags(optional): Any string value that can uniquely identify or group the devices (#,:, _ and – are only accepted characters).  
  • platform: APNS. 
  • pushchannel: The PNS handle or device token from the device (device token must be a hexadecimal digit). 

The Request Body would look something similar to this: 

Azure Notification Hubs: Key features and use cases 

Once we send the request, the generated response with status code is 200 with an empty body, which means we have successfully created or overwritten and installation. 

Azure Notification Hubs: Key features and use cases 

4. Viewing the registered devices with Notification Hub

There are multiple possible ways to retrieve the registrations, and you can retrieve all registrations with a Notification Hub or even retrieve selected registrations using the installationid.

MSFT provides multiple REST APIs to deal according to the scenario if we have installationid to retrieve particular registration using Read installation or even retrieve all registrations made with the Notification Hub using Read registrations.

We would retrieve the earlier created registration where we used installationid as 21-2121. To verify if the update gets reflected, we will update its tags and then re-retrieve the registration.

We would make a GET call by providing only the installationid. The only prerequisites here would be the installationid and the SAS Token for Authorization:

Azure Notification Hubs: Key features and use cases 

We would now add a new tag to the same registration and see if it reflects the update. To add the tag, we would be using the earlier API that we used to register the device, as it will then overwrite an installation.

Azure Notification Hubs: Key features and use cases 

To verify the latest change reflects, let’s now retrieve the installation. 

Azure Notification Hubs: Key features and use cases 

We were able to retrieve the registered device using the installationid with the latest reflected change. 

We would use the similar API below that would return all registered devices with Notification Hub: 

Azure Notification Hubs: Key features and use cases 

We can even see that the installation has generated an exceptional Tag format, which we discussed earlier $InstallationId:{21-2121}, which would help Notification Hub to classify the unique devices and send the notifications to particular devices rather than broadcasting them.

5. Deleting a registered device

To delete multiple registrations in a single go, we currently don’t have any REST API. Possibly, there are two ways to delete a registered device using either the installationid or registration id. 

We would demonstrate by attempting to delete a registered device using the installationid as 21-2121, using the DELETE Method as discussed in this Documentation. 

Azure Notification Hubs: Key features and use cases 

The installation was successfully removed, and we could see the DELETE Method returned the 204 status code. Even if the installation was not present / not found, the service will return the status code 204. 

Later, when we try to retrieve the same registered device after it gets deleted, the GET method used to retrieve devices would return the status code as 404, stating it did not retrieve the installation as below: 

Azure Notification Hubs: Key features and use cases 

Now that we have completed this demonstration, you can configure your Notification Hub to send alerts and notify your customers about the deals and offers via a quick, simple notification sent using Azure.  

In one of our projects for a client, we leveraged Notification Hubs to notify the mobile device users whenever an image successfully uploads to Azure Data Lake Storage (ADLS) containers. Based on specific parameters set to validate the face in the image, a Machine Learning model would accept/reject the uploaded image and notify the device using Azure Notification Hubs. 

So why wait? Empower your app with Azure Notification Hub’s powerful capabilities. Contact us to seamlessly integrate and leverage this solution for targeted customer engagement and real-time business updates.  

Enhance user interaction across iOS, Android, Windows, and Kindle devices with Fractal’s expertise in deploying Azure Notification Hub to drive app-to-user communication like never before. 

View our Microsoft blog page
Industries
All