We enabled Platform Notification System Feedback a while back to improve monitoring and debugging, where all channel error feedback from Platform Notification Systems associated with your hub is put in a storage blob for you to peruse. If you haven’t yet, I recommend checking out the feature and the simple sample we prepared. Many customers found this very useful, but wished for a way to see these feedback per message request to Notification Hubs.
We thought about it and it was a wonderful idea!
With our latest updates, we’ve added a new field PnsErrorDetailsUri into Per Message Telemetry – if you haven’t worked with Per Message Telemetry, you can read about it here. This means that, as part of Per Message Telemetry, we process per message feedback from Platform Notification Systems as we push notifications out, extract the errors, and put them in a blob whose uri is then presented. This makes these feedback much more targeted and useful, helping you detect any errors in your pushes.
Here is an overview of the differences between Platform Notification System Feedback and the PNS Error Details we added to Per Message Telemetry:
Platform Notification System Feedback | Per Message Telemetry’s PNS Error Details | |
Scope | Notification hub | Notification ID |
Content | Expired channel and bad channel errors from PNS | Any errors from PNS |
Both PNS Feedback and PNS Error Details are available for Standard Tier namespaces.
If you are using REST, the return of Per Message Telemetry will have an additional PnsErrorDetailsUri when you work with Api-Version 2016-07 or above. The errors can be any of the following:
- Invalid PNS credentials
- PNS unreachable
- Bad channel
- Expired channel
- Wrong channel
- PNS throttled
- Invalid token
- Wrong token
- Dropped
Note that the error details are only fully available after the associated notification send operation is complete, and that you will get NULL for PnsErrorDetailsUri if there is no error.
If you are using our NuGet, simply add a few lines of code to extract the PnsErrorDetailUri from notification outcome details and its blob content.
// Get Notification ID from any send request var outcome = await client.SendWindowsNativeNotificationAsync(winPayload.ToString(), tag); // Get pns error detail uri once notification processing is complete var feedbackUri = string.Empty; var retryCount = 0; while (retryCount++ < 6) { var result = client.GetNotificationOutcomeDetailsAsync(outcome.NotificationId).Result; if (result.State != NotificationOutcomeState.Completed) { await Task.Delay(TimeSpan.FromSeconds(10)); } else { feedbackUri = result.PnsErrorDetailsUri; break; } } if (!string.IsNullOrEmpty(feedbackUri)) { Console.WriteLine("feedbackBlobUri: {0}", feedbackUri); var feedbackFromBlob = ReadFeedbackFromBlob(new Uri(feedbackUri)); Console.WriteLine("Feedback from blob: {0}", feedbackFromBlob); }
You can easily read the blob with the following call with the Azure Storage NuGet.
private static string ReadFeedbackFromBlob(Uri uri) { var currentBlock = new CloudAppendBlob(uri); var stringbuilder = new StringBuilder(); using (var streamReader = new StreamReader(currentBlock.OpenRead())) { while (!streamReader.EndOfStream) { string currentFeedbackString = streamReader.ReadLine(); if (currentFeedbackString != null) { stringbuilder.AppendLine(currentFeedbackString); } } } return stringbuilder.ToString(); }
We will be updating the Node.js SDK soon to enable this feature as well. Meanwhile, give it a try with our NuGet or REST APIs and let us know what you think!