Badge management with Azure Notification Hubs - azure

I am investigating migrating from Azure Mobile Services push notifications to Azure Notification Hubs for two primary benefits: 1) pub/sub architecture using tags, and 2) abstracting the device registration.
However, I'm struggling to understand the pattern for device badge value management.
With mobile services push notifications it's straightforward to maintain the current badge value in the db for individual device registrations. But with Notifications Hubs where Azure maintains the 'subscribed' devices registrations and manages the fan out of device notifications, what is the best approach for the client devices to update their current badge value with Azure Notification Hubs?
I have reviewed the Azure documentation, viewed several of the excellent overview videos, such as Channel 9 Cloud Cover episode 100, but documentation and examples seem to be lacking with regard to Notification Hubs and management of badge values.
Thanks for your help, friends!

Unfortunately badge management is not straightforward in a pub/sub architecture. If you use tags to indicate individual users then you can keep your counter in your backend and then add it in your notification when sending to your hub.
In you are using tags as interest group, then things are not straightforward, and they depend on what you want that count to be. For some platforms (i.e. iOS and ANdroid) you can code some client code that keeps a personalized counter. Some other times however, one has to avoid keeping personalized counters and resort to use generic badges like "!" in Windows 8.

Related

Azure notification hubs - can they send psh notifications without third parties

Doing some learning around Azure Notification hubs and trying to understand one of the basic concepts but not able to find any documentation that states it explictly.
Is an azure notification hb able to send a push notification directly or does it have to have a third party set up in its settings (ie APNS, GCM.FCM, WNS, MPNS,ADM, Baidu)?
Azure Notification Hubs (ANH) must be configured with credentials for one or more of the push notification services (PNS) that you've enumerated.
Essentially, each of these providers have a reliable mechanism for delivering a specific notification to a specific device, some of them also provide mechanisms for delivering the same notification to many devices. But those solutions are usually limited to just their platform.
ANH seeks to provide a wrapper for each PNS that provides routing and scale to target many devices with a single request, so that you don't need to write that code separately for each platform. Using more advanced techniques, like templates, can even allow you to abstract away platform differences altogether.
However, ANH is not an alternative to the PNSs you've listed. I hope that helps.

Multitenancy - should Azure IoT customers share a hub?

I'm building an Azure IoT Hub application. I have several customers. Do you think all those customers should be connected to the same hub or a different one(s)?
And if that's even possible, how would such multi-tenancy work so that the customers (tenants) wouldn't see each other's data on that same hub?
And finally, do you have to pay for each new IoT hub? (in which case maybe it's a good idea looking into sharing one between customers)
A single hub would suffice but then there should be provisions needed to make sure that you are not hitting the maximum allowed message in a hub as IoT Hub SKU size is defined on the number of messages https://learn.microsoft.com/en-in/azure/iot-hub/iot-hub-scaling?branch=release-iotbasic
With single hub you need an almost near time throttling feature also in your application so that one rouge device won't eatup the maximum message allowed for IotHub Unit.
"And if that's even possible, how would such multi-tenancy work so
that the customers (tenants) wouldn't see each other's data on that
same hub?"
The message can have TenantId (please check https://azure.microsoft.com/en-in/blog/azure-iot-hub-message-enrichment-simplifies-downstream-processing-of-your-data/) which would differentiate messages from each tenant.The custom solution need to filter it based on the Tenantid or DeviceId which would be unique across every tenant in a IoTHub.You can have TenantId added in DeviceTwins once device is registered in IoTHub so that it would help identify Tenantid associated with the Device.

Webhook architecture for managing millions of subscribers (who are customers)

My Azure based SaaS system publishes events and I have customers who wish to subscribe to them - webhooks seem undeniably the right architecture (And I'm currently a happy consumer of webhooks). I've found lots of great documentation and case studies on best practices (e.g. http://resthooks.org) however I've not managed to find an existing architecture, framework, project, sample or solution that implements the best practices.
I could build my own solution however I don't want to reinvent the wheel. I was expecting to find an existing framework (e.g. on Github) created by people much smarter than I but haven't had any success.
I currently use a number of Azure services (such as Service Bus, Cosmos, Table Storage) internally and consume using Azure Functions but what I don't have is an architecture for allowing my customers to subscribe to these events.
Specifically I'm looking for best practices and code samples on how to manage potentially millions of subscribers (who are external customers) and the approach to distribute the webhooks out to each of them.
I already understand how to publish and consume webhooks where I am an individual subscriber and there are already some great samples available - https://github.com/aspnet/AspLabs/tree/master/src/WebHooks
Can anyone point me in the right direction? (Preferably to a .NET / C# based solution)
Not sure if this is the 'right' direction but here are my current thoughts on a solution.
We are currently using CosmosDb and are leveraging the change feed to trigger an Azure function execution. The code within the function does a specific task for all tenants in our system. This code will be changed to simply send a new event to the Event Grid topic. A 'in-house' subscription will then be added that will handle what the function code is currently doing today.
We will then follow the subscription management guidance Zapier offers. In a nutshell it is to expose the capability to our customers to subscribe to the events that we publish via a few endpoints. In addition to standard CRUD stuff when a tenant adds/removes a subscription the code will leverage the Event Grid Management SDK to add/remove subscriptions to the appropriate topics within Event Grid (samples here). The subscriptions that get added will have filters set to ensure each tenant only receives their own events.
There are limitations to the number of subscriptions and topics with in Azure (details here). These limitations are acceptable in our case but is something you might need to look into more if you need to reach 1mm subscribers.
Here is how I visualize it:
Not 100% we'll build this but if we do I'll post back here any gotchas we uncover.
Cheers!

Sending Azure Push Notifications Periodically

I currently have an MVC / SQL application hosted in Azure that I would like to add push notification functionality to.
The scenario is that users register for alerts on the native mobile app (iOS / Android) and specify a latitude / longitude / radius per alert type. I'd like for each alert type to have a rules engine that evaluates on a schedule, determines the latest entries and then based on the user specified location and radius determines which users should now receive a corresponding notification.
I'm struggling to determine which Azure services should be used for this solution. I think that the Notification Hubs is the correct tool to use for sending the notifications. What I'm most unsure of is how to run the background processes on a schedule that wakes up, checks the latest entries, and selects which users to alert. I've came across WebJobs but these appear to be based on QueueInputs and monitoring storage items rather than running independent tasks?
Can someone give me some advice on the correct Azure services / SDKs that should be used to solve this scenario?
Thanks,
Brian.
WebJobs can be triggered (e.g., QueueInputs),run on-demand, on schedule or continuously.
you can also use Azure Mobile Services as it has scheduling functionality and plugs-in well with Notifications as well.

Difference between azure notification hub and azure mobile services

What are the main differences between azure notification hub and mobile services
Which is best to use when.
Thanks
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.
Last week happened the #AzureChat and they answered this question too:
Q4: When should I use push in Mobile Services vs push in Notification
Hubs?
A4: Notification Hubs works with any backend, including Mobile
Services, your custom backend in the cloud, or your on-premises
backend. Use Notification Hubs with your custom backend (including
on-premises), if your backend needs rich high scale personable push.
Use Mobile Services direct push if your push needs in mobile services
are direct. Use Mobile Services and Notification Hubs if you need
richer push in your Mobile Services including broadcast & templating,
etc. - #kirillg_msft
A4: Notification Hubs are optimized to broadcast millions of highly
personalized push notifications within minutes. Mobile Services is
great for sending event-triggered push notifications. In a two player
game, for example, you would use push through Notification Hubs to
broadcast special offers to everyone at once, but push through Mobile
Services to notify Player B that Player A just completed his turn. -
#mlunes90
http://blogs.msdn.com/b/windowsazure/archive/2013/10/11/recap-mobile-services-azurechat.aspx
Check the features/pricing of both on the official pages:
Azure Mobile Services
Azure Mobile Services provides a scalable cloud backend for building
Windows Store, Windows Phone, Apple iOS, Android, and HTML/JavaScript
applications. Store data in the cloud, authenticate users, and send
push notifications to your application within minutes.
Azure Notification Hubs
Azure Notification Hubs provides a highly scalable, cross-platform
push notification infrastructure that enables you to either broadcast
push notifications to millions of users at once or tailor
notifications to individual users. You can use Notification Hubs with
any connected mobile application—whether it’s built on Azure Virtual
Machines, Cloud Services, Web Sites, or Mobile Services.
Use Azure Mobile Services if you need a server backend for your app, where you store data and implement server side logic. Azure Notification Hubs is included, which you can use for push notifications.
Use only Azure Notification Hubs if you don't need server side data or logic or are already using another service for this and only need a service to send push notifications.

Resources