Google cloud messaging: 100 multiple senders limitation - android

My android application needs to enable GCM push notifications from multiple senders. I've read that it is possible here: Receiving messages from multi-senders. However, it is mentioned that there is a limit of 100 multiple senders. In my use-case I might have more than 100 senders (servers with different sender ids and api keys), but each application installed on a device will register to a small number of senders (less than 100).
This is how I need it to work:
1. When the user logs in, the client app will send a rest directly to the app server to get the sender ids which are relevant to that user. The number of possible sender ids is larger than 100, but for a specific user the subset of sender ids which are relevant to that user is probably 1.
2. The client app would execute the following code for each senderId in the set of returned sender ids:
String token = instanceID.getToken(senderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
I want to make sure that the limit of 100 multiple senders doesn't apply to my use-case. I tried searching more about the limitation, but came up empty.
Thanks in advance!

The limit of 100 multiple senders mentioned in [0] refers to senders used by a single instance of your app. Thus your specific use case is supported.
[0] https://developers.google.com/cloud-messaging/concept-options#receiving-messages-from-multi-senders

Related

Firebase Cloud Function : Send notification to all user using sendToDevice()

I am already using Cloud Messaging feature in Firebase and utilized the sendToTopic() legacy method of sending notification to all subscribers but I've seen a limitation using topic in my app. Now I want to manage my way of sending and receiving notification by sending notification to each device using the registered device token in user's document which stored as map object. I will iterate to each device token and use sendToDevice() to send notification to each device.
I have now a function lets call it new_added that triggers whenever new document is added in a collection. Now every time new_added function gets called, this will iterate to each document in Users collection and write a new document under Notification collection. The structure would be this Users (collection) > uid (document) > Notifications > doc. Every new added item under Notification collection will trigger a function in server. This operation is too heavy specially if there is a million number of users, does this kind of operation can be perform in server side using Cloud Function within 540 seconds which is said to be the maximum runtime of a function after gets trigger? I really want it to work this way. Is there any tool that will help to minimize the operation?
If sounds like you're trying to implement your own FCM messaging fan-out, sending the same message to many users. This is similar to what FCM topic messaging already does, to I'd definitely consider using that for the moment.
But if you want to implement it yourself, consider how to optimize it for the underlying system. Since you're storing the tokens in Firestore, the number of documents you read is a key factor in the cost.
A way to reduce the number of documents you read could be to store the tokens for a group of devices into a single document. For example, you could create a document for each "topic", and add tokens to that doc as they are written to the database. Then when you need to send a message to all devices for a topic, you simply read that topic-document, and get all tokens in one go. This becomes especially simple if you name the document after the topic for which it contains the tokens, e.g. mytopic-tokens.
The main problem with this approach is that a document can be no bigger than 1Mb. Say that tokens are at most 256 bytes (they seem to be 152-162 characters), you can store 4000 tokens in a document. If you have more tokens, you will need to create multiple documents. A simple naming scheme can go a long way here, such as mytopic-tokens-1, mytopic-tokens-2, etc. You can get all these documents with a single range-query in Firestore.

Google cloud messaging Limit

I know that exists similar questions on site, but I confused because http and xmpp have difference limit:
this page say differences between http and xmpp.
first limit is [xmpp & http]: up to 4KB of data
second limit is:
http: You can send out a message to 1000 users at a time. (ref)
xmpp: For each sender ID, GCM allows 1000 connections in parallel. (ref)
You can send out a message to 1000 users at a time. so if you have more users you'll have to send the message multiple times from your server but to different users each time (ref)
third limit is:
http: I couldn't found this limit in android developer:
There is a limit on how many messages can be stored without collapsing. That limit is currently 100. If the limit is reached, all stored messages are discarded. Then when the device is back online, it receives a special message indicating that the limit was reached. The application can then handle the situation properly, typically by requesting a full sync. (ref)
xmpp:
Every message sent to CCS receives either an ACK or a NACK response. Messages that haven't received one of these responses are considered pending. If the pending message count reaches 100, the app server should stop sending new messages and wait for CCS to acknowledge some of the existing pending messages (ref)
my questions:
1.in second limit, if we use http method and have 2000 users, should we send message twice, every time to 1000 users?, can we do it?
2.xmpp can not support multicast messaging, can we use topic for multicast in xmpp?
any limit on broadcast messaging by topics? (except ref)
4.in third limit, if i send a message to 300 users, and One hundred top users be offline, do they recieve message or any notification when come back and online? (note: use broadcast for http and loop for xmpp)
do this limit effect in topic way ?
do exists any difference in third limit between http and xmpp?
7.exists other limit in http or xmpp?
Yes you can do that. While using HTTP you may have a batch size of 1000(recipients).
Yes. Topic messages is PubSub method and if your clients registered to a given topic, you can sent a push notification to all of them with just one request.
No limitation. Once there was a 1 million subscriber limit per app on Topic Messaging, which doesn't exist anymore.
You confused the third limit:
The first one (HTTP) is about a single client, not all of them. So if you send more than 100 messages to a single client while he is offline, when he gets back online again, none of them will be deliver.
The second one (XMPP) is about all of the queue and it happens in the server side. It means you have to send no messages to GCM if there exists more than 100 unACKed messages there.
So you have no problem considering offline users, GCM will handle to deliver message to all of them, when they come back online.
No.
I explained it in 4.
I don't remember any more.

how to send different push notifications from python server to multiple android devices?

We have a python script which do specific job and we want when it see the trigger occurred , it sends a push notification to android devices
but we don't want to send a default message to all of our users.
we want to send customize message based on the trigger to our users
for example :
"user1" the "trigger" hits.
"user2" the "trigger" hits.
.
.
can you help me how to send different messages to different unique android IDs?
I suggest that you're familiar with GCM (official documentation for start you could find here Set up a GCM Client App on Android
Now regarding your question:
you have to have storage on your server where you save registration id, device token + any info which will help you to differ one user/device from another. For example, I did same thing for different apps and stored package_name in addition.
To send custom message you'll need:
1) choose to which devices/users you'll send a message (on exit you'll have a list of device tokens)
2) get list of registration ids from device tokens (on exit list of registration ids)
I separated 1 and 2 for simplicity.
3) I suggest that you know that GCM supports for up to 1,000 recipients for a single message. So you should form here a string of registration ids separated by comma. If you need to send message to 2500 devices, you need to do 3 requests.
4) send request to GCM server and see custom message on specific devices.
Regards.

GCM has limit of 1000 users. What if we need more?

If I understand it correctly, Google Cloud Messaging can only send one message to 1000 different phones. But what if we need to increase this number to 1 million, is that possible ?
I tried to go through the documentation but I did not find anything.
If you need to send the same message to more than 1000 Registration IDs, you simply split the sending process into groups of 1000 Registration IDs. Each group would be sent in a separate request to GCM server.
FCM has replaced GCM, But still if someone is looking for this answer,
You can check this code from google.
multicast messages
Idea is to create a queue
Queue queue = QueueFactory.getQueue("MulticastMessagesQueue");
and add 1000 device ids to this queue and post a send message.
complete server side code implementation
server side implementation of google io 2016 app

Android GCM send only one message to device with multiple registration ids

Due to a bug on our system, we mistakenly stored multiple registration ids per device per user by appending to their profile, rather than replacing after an upgrade and the like.
We can obviously now correct that by handling the canonical ids from the response we get, but for some users (like myself, for instance...) they would get multiple notifications, instead of just one per device.
I've read what can be sent via,
http://developer.android.com/google/gcm/http.html
and
http://developer.android.com/google/gcm/server.html#params
But there doesn't seem to be a perfect solution. I've just checked there, and I could send a 'dry_run' request first, handle the multiple registration ids, replace what needs replacing, remove what needs removing, then send the second (pruned) request.
This certainly could be a solution, but I can't imagine it'd be friendly to our api quotas (though I don't really know). Is there no other property that can be set on the HTTP equest so as to only send to an individual device?
GCM is completely free no matter how big your messaging needs are, and there are no quotas.
(quote from here).
There are no quotas to GCM, so you can try your dry_run approach without fear. The only question is whether dry_run mode actually returns Canonical Registration ID, or simply returns immediately with just some fake message ID.
Using the Canonical Registration ID response is the only way you can use to clean your DB (other than deleting your DB and re-building it from scratch).
There is a small optimization you can make in your cleanup process. If you can fetch the registration IDs from your DB in the order they were inserted (from the oldest to the latest), you will likely get Canonical Registration ID responses for the first registration IDs you try. For each of them you'll know what the current (canonical) registration ID is, and you'll mark it, so you don't send to it during your cleanup process. This will prevent sending duplicate messages for all devices that have up to 2 registration IDs in your DB (and will reduce by one the number of duplicate messages for the other devices).

Categories

Resources