Non collapsible and collapsible messages - shaikhalvee/FCM GitHub Wiki
Non-collapsible
Messages are non-collapsible by default except for notification messages, which are always collapsible.
Note
FCM does not guarantee the order of delivery.
Some typical use cases of non-collapsible messages are:
- chat messages
- critical messages.
For example, in an IM app, you would want to deliver every message, because every message has different content.
There is a limit of 100 messages that can be stored without collapsing. If the limit is reached, all stored messages are discarded.
Collapsible
A collapsible message is a message that may be replaced by a new message if it has yet to be delivered to the device.
Two common use cases of collapsible messages are:
- send-to-sync messages
- notification messages.
A send-to-sync message is a "ping" that tells a mobile app to sync data from the server. An example would be a sports app that updates users with the latest score. Only the most recent message is relevant.
To mark a message as collapsible, include the collapse_key parameter in the message payload.
{
"collapse_key" : "demo",
"to" : "xyz",
"data" : {
"key1" : "value1",
"key2" : "value2"
}
}
Note
FCM allows a maximum of 4 different collapse keys per device to be used by the app server at any given time. In other words, the FCM connection server can simultaneously store four different collapsible send-to-sync messages per device, each with a different collapse key.
If you exceed this number, FCM only keeps four collapse keys, with no guarantees about which ones are kept.