Azure notification hub best practice in social network scenario

淺唱寂寞╮ 提交于 2020-01-03 06:45:08

问题


I am wondering which is the best practice in Azure notification hub to send push notifications to a couple of certain users (e.g. about followed activities).

Imagine, users can follow other users and these followers should be notified about new activities (facebook, twitter principle).

How to send these notifications in detail, there are two options I am thinking about, but which one is the best?

1) looping through all desired users by code and calling SendTemplateNotificationAsync for each individual user?

foreach(user in allSubscribedUsers) {
    tags.Add("userid:" + userId);
    await hub.SendTemplateNotificationAsync(notification, tags);
}

2) Having special tags a user can register to

registration.Tags = new HashSet<string>(deviceUpdate.Tags);

// the current user follows other users with the ids 1,2 and 3
registration.Tags.Add("followerUserid:1");
registration.Tags.Add("followerUserid:2");
registration.Tags.Add("followerUserid:3");
...
// an acivity by user with id 2 is happen
// send a push notification to all users who follow the user with id 2
tags.Add("followerUserid:2");
await hub.SendTemplateNotificationAsync(notification, tags);

It's possible that a user follows up to 1.000 other users, so he needs to register 1.000 of the followerUserId-Tag.

Is the second approach a reliable solution?

Are there any tag limitations a user can register to?


回答1:


This answer describes tag limits on NH. There is a limit of 60 tags per registration, so you won't be able to use your second approach if you want to allow 1k followers.

You can use the SendNotificationAsync(Notification, IEnumerable<String>) overload of the method to "batch" calls in your first scenario in groups of 20 max to save on the number of calls you make to the service.



来源:https://stackoverflow.com/questions/44431084/azure-notification-hub-best-practice-in-social-network-scenario

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!