Do we need complex sending strategies for GCM / FCM?

a 夏天 提交于 2019-12-12 04:22:38

问题


Currently I'm working on a SaaS with support for multiple tenants that can enable push notifications for their user-bases. I'm thinking of using a message queue to store all pushes and send them with a separate service. That new service would need to read from the queue and send the push notifications.

My question now is: Do I need to come up with a complex sending strategy? I know that with GCM has a limit of 1000 devices per request, so this needs to be considered. I also can't wait for x pushes to fly in as this might delay a previous push from being sent. My next thought was to create a global array and fill it with pushes from the queue. A loop would then fetch that array every say 1 second and send pushes. This way pushes would get sent for sure and I wouldn't exceed the 1000 devices limit.

So ... although this might work I'm not sure if an infinite loop is the best way to go. I'm wondering if GCM / FCM even has a request limit? If not, I wouldn't need to aggregate the pushes in the first place and I could ditch the loop. I could simply fire a request for each push that gets pulled from the queue.

Any enlightenment on this topic or improvement of my prototypical algorithm would be great!


回答1:


Do I need to come up with a complex sending strategy?

Not really. GCM/FCM is pretty simple enough. Just send the message towards the GCM/FCM server and it would queue it on it's own, then (as per it's behavior) send it as soon as possible.

I know that with GCM has a limit of 1000 devices per request, so this needs to be considered.

I think you're confusing the 1000 devices per request limit. The 1000 devices limit refers to the number of registration tokens you add in the list when using the registration_ids parameter:

This parameter specifies a list of devices (registration tokens, or IDs) receiving a multicast message. It must contain at least 1 and at most 1000 registration tokens.

This means you can only send to 1000 devices with the same message payload in a single request (you can then do a batch request (1000/each request) if you need to).

I'm wondering if GCM / FCM even has a request limit?

AFAIK, there is no such limit. Ditch the loop. Whenever you successfully send a message towards the GCM/FCM server, it will enqueue and keep the message until such time that it is available to send.



来源:https://stackoverflow.com/questions/41547779/do-we-need-complex-sending-strategies-for-gcm-fcm

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