Skip to main content

Azure Notification Hub (Day 23 of 31)

List of all posts from this series: http://vunvulearadu.blogspot.ro/2014/11/azure-blog-post-marathon-is-ready-to.html

Short Description
Azure Notification Hub allow us to send notifications from any backend (hosted on cloud or on-premises) to our devices/clients.
I don’t know I you had the opportunity to work on a system that needs to work with different PNS providers (iOS, Android, WP), but managing all different platforms, tokens, trigger notification for each device of group of devices can be a time consuming task not only for developers but also for the person that trigger the notification.
For use cases like this Azure Notification Hub can become our best friend.


Main Features
Platform Agnostic
We can send notifications to any kind of device or system. From Android to iOS, to desktop application or even kindles.
Focus on content
Azure Notification Hubs enable us to focus on the content that we want to send to our applications and not on the notification system platform that we use. In this way we don’t care about the infrastructure and format of the notification that is send.
Scalable
With only one API call we can trigger a notification that is send to millions of devices across the glob.
Telemetry
This service has the capability to track notification. In this way, we ca know what is the status of each notification that was send, how many devices received it and so on.
Cross Platform
It has support for multiple platforms like iOS, Android, WP, desktop and even kindle.
No Integration development
There is no need to write custom code that integrates each PNS provider.
 Xamarin Support
There is full support for Xamarin cross-platform applications.
Support for Registration from Device or from Backend
Both registration mechanism are supported in the current architecture of Azure Notification Hub. It is recommended to use the second one, because it allow us to update the tags (user subscriptions) on all devices that are registered for that user, not only on devices that are online.
Tags
To be able to send a notification to a specific device, tags needs to be used. Each device can have associated one or more tags. When a notification is send it is send to a specific tag. All devices that are registered with that specific tag will receive the notification.
We can see tags as a mechanism to group devices, but in in the same time we can have a tag that unique identify a registered device.
Tag Expression
We can send a notification that target a combination of tags. For this use causes we can define an expression based on AND, OR and NOT. For example we can send a notification for all people from UK and Germany that are interested to receives notification about Christmas.
(( UK || Germany ) && Christmas)

Device Targeting  
As we can saw above when we send a notification we can target a specific tag or a tag expression. There 3 ways to target a notification:

  • Tags
  • Tag Expression
  • Broadcast (all devices that are registered in Notification Hub will receive the notification)

Templates
Because each device has a different notification platform with different functionalities, we need to a mechanism to specify different content based on device type and features. For example we may want to send a graphical image as a notification for devices that support this.
Templates allow us to specify a parameterized template for each device type. In this way the final content that will be received by a specific device will contain content that is supported by him.
This is a very powerful feature that you should use. More information about this can be found here http://msdn.microsoft.com/en-us/library/azure/dn530748.aspx
Security
The base mechanism that is used to manage access of different systems (that produce and send notification over the wire) is Shared Access Signature (SAS). Using SAS we can manage access of each system.
SAS is based on a token that can specify what kind of claims has each system. Below you can find the list of claims:

  • Listen (Create, Read, Delete Registrations)
  • Send (Send Notifications)
  • Manage (Create, Read, Update, Delete Notification Hubs, Read registration by tag)

Scheduling
We are allowed to register a notification that will be send at a specific time in future. In this way we can send notifications to our clients at a specific time.
Import/Export
We can export or import a bulk of registrations. In this way we can automatically manage the devices that are registered.

Limitations 
There are some limitation related to notification size, tag name and so on, but this are not real limitations.
For the Free and Basic tier there is also a limitation at the number of tags, devices registered with the same tag and so on. All this limitation are removed if you are using Standard tier that allow us to nock yourself out.

Applicable Use Cases 
Below you can find some use cases when I would use Azure Notification Hub
Discounts notification
If you have a store and every day or week you have special discounts, that you can use this notification system to notify users about special offers and discounts. Combined with scheduler support, you can setup your discounts offers in advance.
Breaking news
For application that share content and news to clients, a system like this can be used with success to send breaking news notification to users.
Alerts
Notification Hub can be used by applications that needs to send alerts to users when something is happening in their region. For example alerts can be used to send notifications when the risk level in a specific region was changed or a natural calamity will happen.


Code Sample 
// Send notification at a specific time
Notification notification = new AppleNotification("{\"aps\":{\"alert\":\"Special discount ony for you!\"}}");
var scheduled = await hub.ScheduleNotificationAsync(notification, new DateTime(2014, 12, 24, 10, 0, 0));

Pros and Cons 
Pros

  • Scalable
  • Template support allow us to use features that are specific for each platform
  • Simple to use
  • Telemetry support
  • Free tier is great for start-ups and is FREE.

Cons
-

Pricing
When you calculate the cost of Azure Notification Hub you should take into account the following:

  • Number of notification that will be send per month
  • Number of tags
  • Number of devices registered with the same tag
  • Scheduler support


Conclusion
Azure Notification Hub is design to any type of application and customer. From the small one that has a limited budget to the large one that needs strong SLAs and features like import/export. This is a service that you should keep in mind and use it when you need to send notifications.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see