2

I am trying to store failed notifications in a db, e.g. client does not have internet access. This will enable me to check from a backgroundService if there is a missing notification, and then create it from the backgroundService.

I therefore have the following, on my Azure App Service Mobile:

var notStat = await hub.SendWindowsNativeNotificationAsync(wnsToast, tag);
telemetry.TrackTrace("failure : " + notStat.Failure + " | Results : " + notStat.Results + " | State : " + notStat.State + " | Success : " + notStat.Success + " | trackingID : " + notStat.TrackingId + ");

The code snippet was to test the impact from the client, but no matter what I do the resulting log is just that the message was enqueued.

Question

So how to I detect failed Notifications?

Conclusion

To sum up the discussions made to the accepted answer:

When the notification has been send, the NotificationId and other relevant data, is stored in a separate Table.

The event on the client receiving the notification, will then send a message to the server stating that the notification is received. The entry is then removed from the Table.

The notifications that then are not received by the client, will through a background task be found. This will be every time the background task fires, e.g. every 6 hours, the background task will retrieve all the missing notifications. This enables the background task to create the relevant notifications and the user will not miss any notification.

Community
  • 1
  • 1
JTIM
  • 2,774
  • 1
  • 34
  • 74

1 Answers1

2

The return of enqueued is expected - please, refer to the troubleshooting guidance. For more insights on what is happened try to set the EnableTestSend -

"result.State will simply state Enqueued at the end of the execution without any insight into what happened to your push. Now you can use the EnableTestSend boolean" (c) documentation

But be aware that when EnableTestSend is enabled, there are some limits (described on the same page, so will not copy paste it here to avoid the future issues with the outdated info).

You can use Per Message Telemetry functionality or REST API as well - Fiddler+some documentation.

And, as a follow-up questions, there were some discussions on SO i saw that you may find helpful: first and second.

And, as a last one, i would highly recommend (if you did not yet) to take a look at FAQ - it is important to know how different platforms handle the notifications, to avoid the situation when you try to debug something that was done by desing (for example, maybe, if the device is offline, and there are notifications, only the last will be delivered, etc).

Community
  • 1
  • 1
Alex Belotserkovskiy
  • 4,012
  • 1
  • 13
  • 10
  • Hey, I am able to send notifications and they do hav an id. So my question was more in the range of can you have an event that, then is fired when notification is not received on the server, such that this can be stored. I will look into the rest api referenced in one of the quedtions you referred. I just thought this would be something everybody wanted to have :) – JTIM May 01 '16 at 07:31
  • Based on the telemetry, it seems like I need to have a server that frequently calls the the uri https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/{notification message id}?api-version=2015-04 with the relevant information. Sounds costly, or I should store tur notification id in a table, then call that from the background service and remove received messages. But I cant see how long the telemetry is retained. Do you know this? Is there another more obvious way to go? – JTIM May 01 '16 at 07:38
  • Ugh, that is a tough question. I believe that implementing such the event will be costly on the backend side. I did not see many people implementing per-message troubleshooting, anyway, as as i said, too many nuances related to how platforms handle the message, how long they are being saved before stalled, etc. I do see, however, people who are doing retry logic if they see any error, popular is the back-off one - https://blogs.windows.com/buildingapps/2013/10/22/recommended-practices-for-using-microsoft-push-notification-service-mpns/. But it is not recommended for the "disconnected" errors. – Alex Belotserkovskiy May 01 '16 at 09:21
  • It is not recommended per product group of notification hubs - WNS will cache up to 5 toasts and tiles per channel, or 1 raw notification when a device is offline. Retrying a notification for a disconnected device on toasts especially could just result in duplicate notifications. Retry is only needed if you get a 500 or 503 error from the service, or a 406 error (meaning your notification is being throttled) (c). – Alex Belotserkovskiy May 01 '16 at 09:22
  • So, basically - i recommend instead of trying to implement per-message logic, which i see costly and time-consuming, implement more agile (from my point of view, for sure) approach and implement retry logic. – Alex Belotserkovskiy May 01 '16 at 09:25
  • Hmm yeah I agree that the price would probably be high. Of course retry logic could be implemented, but only if the notification hub does not return enqueued right? Then that would mean in the cases where it exceeds the 10 minutes the notification is lost. The best view I can see is to have the retry logic as you say, but if no error has come then I would store the notification in a db. The client then responds I received the notification. And the entry is deleted in the db, if it does not reply, then when my background task in the client asks every 12 hours or so, it would get the missing 1/2 – JTIM May 01 '16 at 10:34
  • Notifications in the background and I merely make the client show the requirred notifications. Thereby ensuring that all notifications are received and the user will not be angered by lost messages. Would do you think of this approach? I then do not need to ask the hub, because I could just do some string comparison in a function from the received notification and the stored notification ? I can't really see another approach? The notifications are for turn based game, and you will lose your turn if you are too slow to respond, or forfeit the game. – JTIM May 01 '16 at 10:37
  • @JTIM that approach looks viable for me. – Alex Belotserkovskiy May 01 '16 at 13:44
  • I have now been implementing what we talked about on some demo devices. But the current devices without the new update start receiving notifications after battery saver mode and / or turned off. E.g. a notification was dated an 1 hour old when the mobile was started and the mobile had been shut down 30 minutes prior to when the notification should have been received. Do you know if there is some setting that stores the notifications ? Or if the notificationHub has been updated with a new capabaility, I have not been able to find information about this ? – JTIM May 19 '16 at 13:52
  • I found this https://msdn.microsoft.com/library/windows/apps/hh465435.aspx#pncodes_x_wns_cache about caching, it is stated it is not enabled for toasts, do you know a way of enabling this ? and if so a way to check if cache limit is reached? I can also create a new question, I just felt in fell under the old :) – JTIM May 26 '16 at 08:47