[英]FCM push with high priority to topic comes with delay
I'm sending push messages to small group of devices (less than 5) subscribed to one topic with priority parameter set to high我正在向订阅了一个主题且优先级参数设置为高的一小组设备(少于 5 个)发送推送消息
High priority.
高优先级。 FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when possible and open a network connection to your app server.
FCM 尝试立即传递高优先级消息,允许 FCM 服务在可能的情况下唤醒睡眠设备并打开与您的应用服务器的网络连接。 Apps with instant messaging, chat, or voice call alerts, for example, generally need to open a network connection and make sure FCM delivers the message to the device without delay.
例如,具有即时消息、聊天或语音呼叫提醒功能的应用程序通常需要打开网络连接并确保 FCM 将消息无延迟地传送到设备。 Set high priority only if the message is time-critical and requires the user's immediate interaction, but beware that setting your messages to high priority contributes more to battery drain compared with normal priority messages.
仅当消息对时间要求严格且需要用户立即交互时才设置高优先级,但请注意,与普通优先级消息相比,将消息设置为高优先级会导致更多电池消耗。
But when I put device to IDLE state it comes with big delay.但是当我将设备置于空闲状态时,它会带来很大的延迟。 On Nougat 7.1 delay is more than 10 mins.
在牛轧糖 7.1 上延迟超过 10 分钟。 This type of push requires delay less than 10 secs.
这种类型的推送需要少于 10 秒的延迟。
Setting time_to_live
to 0 solves issues only on Marshmallow.将
time_to_live
设置为 0 只能解决 Marshmallow 上的问题。 Nougat still failing.牛轧糖仍然失败。
So, I see only 3 possible causes of issue所以,我只看到 3 个可能的问题原因
Messages sent to topic can't be high priority.发送到主题的消息不能具有高优先级。 But sending independent messages to each device will increase app-server load.
但是向每个设备发送独立的消息会增加应用服务器的负载。 I need to load fresh token from Firebase Database, so the result will be - 10 http requests for 5 users instead of 1.
我需要从 Firebase 数据库加载新令牌,因此结果将是 - 5 个用户的 10 个 http 请求,而不是 1 个。
App must be in whitelist.应用程序必须在白名单中。 But according to docs it's not acceptable, if I'm using FCM.
但是根据文档,如果我使用 FCM,这是不可接受的。 And I don't want it, because it will cause battery drain.
我不想要它,因为它会导致电池耗尽。
Bug?错误? https://github.com/firebase/quickstart-android/issues/100
https://github.com/firebase/quickstart-android/issues/100
If real cause is first, then why it isn't described in documentation?如果真正的原因是第一位的,那么为什么文档中没有描述呢?
Issue solved by setting time_to_live
to 0. According to docs, this set's priority to "now or never"通过将
time_to_live
设置为 0 解决的问题。根据文档,此设置的优先级为“现在或永远”
Another advantage of specifying the lifespan of a message is that FCM never throttles messages with a time_to_live (TTL) value of 0 seconds.
指定消息生命周期的另一个优点是 FCM 从不限制 time_to_live (TTL) 值为 0 秒的消息。 In other words, FCM guarantees best effort for messages that must be delivered "now or never."
换句话说,FCM 保证对必须“现在或永远”传递的消息做出最大努力。 Keep in mind that a time_to_live value of 0 means messages that can't be delivered immediately are discarded.
请记住,time_to_live 值为 0 意味着无法立即传递的消息将被丢弃。 However, because such messages are never stored, this provides the best latency for sending notification messages.
但是,由于此类消息从不存储,因此这为发送通知消息提供了最佳延迟。
UPD: solved only for Marshmallow. UPD:仅针对棉花糖解决。 On Nougat is still an issue.
在牛轧糖上仍然是一个问题。
UPD2: just don't use topics, they aren't intended for sending pushes without delay. UPD2:只是不要使用主题,它们不是用于立即发送推送。
According to the Firebase Documentation :根据Firebase 文档:
Topic messages are optimized for throughput rather than latency .
主题消息针对吞吐量而不是延迟进行了优化。 For fast, secure delivery to single devices or small groups of devices, target messages to registration tokens , not topics.
为了快速、安全地传送到单个设备或小组设备, 将消息定位到注册令牌,而不是主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.