Android:在 FCM 中延迟接收消息(onMessageReceived)
Android: Delay in Receiving message in FCM(onMessageReceived)
在测试应用中,我实现了使用
发送通知消息的 FCM
https://github.com/firebase/quickstart-android/tree/master/messaging
为了测试,我使用通知下的 "New Message" 从 firebase 控制台发送消息 (8:42 PM)。
但是在我的模拟器中,我在 9:06 PM
收到了消息
如果有什么可以减少延迟的,请告诉我。
谢谢。
我最好的猜测是这与消息有关 priority
。
来自文档:
Setting the priority of a message
You have two options for assigning delivery priority to downstream messages on Android: normal and high priority. Delivery of normal and high priority messages works like this:
Normal priority. This is the default priority for data messages. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve the battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.
High priority. This is the default priority for notification messages. 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. 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. Set high priority 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.
我不确定,但我相信当您向 "All Android devices" 发送消息时使用 normal
优先级,您在上述问题中似乎正在这样做。它也可能被发送到 FCM 主题,即 optimized for throughput rather than latency
因此,将优先级设置为 high
,或者发送到一个特定的设备而不是一个主题,应该可以减少您看到的延迟。
还有;请注意,推送消息基于最大努力。无法保证消息会在给定时间送达,或根本无法送达。
此问题跟踪器专门用于解决与 Android 快速入门相关的问题。从事此项目的专家无权访问任何诊断来帮助解决 FCM 问题。请联系支持。 https://firebase.google.com/support/
这可能是由 Firebase Cloud Messaging 中的不切实际的心跳间隔引起的。
FCM 通过维护从 Android 设备到 Google 服务器的空闲套接字连接来工作。这很棒,因为它几乎不消耗电池电量(与轮询相反),并且它允许设备在消息到达时立即被唤醒。
为确保连接保持活动状态,Android 将在移动连接上每 28 分钟发送一次心跳,在 WiFi 上每 15 分钟发送一次心跳。如果心跳失败,则连接已终止,FCM 将重新建立它并尝试检索任何待处理的推送通知。心跳间隔越高,电池消耗越少,设备从睡眠中唤醒的次数越少。
然而,这是有代价的:心跳间隔越长,识别断开的套接字连接所需的时间就越长。 Google 在部署 FCM 之前,尚未在现实生活中对这些间隔进行足够彻底的测试。这些间隔的问题是由网络路由器和移动运营商引起的,它们会在几分钟不活动后断开空闲套接字连接。
更多信息可在我的博客上找到:
http://eladnava.com/google-cloud-messaging-extremely-unreliable/
作为解决方法,请考虑 Pushy (https://pushy.me),它是 GCM/FCM 的直接替代品,可大大提高通知速度和可靠性(完全披露 - 我创立了 Pushy)。
在测试应用中,我实现了使用
发送通知消息的 FCMhttps://github.com/firebase/quickstart-android/tree/master/messaging
为了测试,我使用通知下的 "New Message" 从 firebase 控制台发送消息 (8:42 PM)。
但是在我的模拟器中,我在 9:06 PM
收到了消息如果有什么可以减少延迟的,请告诉我。
谢谢。
我最好的猜测是这与消息有关 priority
。
来自文档:
Setting the priority of a message
You have two options for assigning delivery priority to downstream messages on Android: normal and high priority. Delivery of normal and high priority messages works like this:
Normal priority. This is the default priority for data messages. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve the battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.
High priority. This is the default priority for notification messages. 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. 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. Set high priority 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.
我不确定,但我相信当您向 "All Android devices" 发送消息时使用 normal
优先级,您在上述问题中似乎正在这样做。它也可能被发送到 FCM 主题,即 optimized for throughput rather than latency
因此,将优先级设置为 high
,或者发送到一个特定的设备而不是一个主题,应该可以减少您看到的延迟。
还有;请注意,推送消息基于最大努力。无法保证消息会在给定时间送达,或根本无法送达。
此问题跟踪器专门用于解决与 Android 快速入门相关的问题。从事此项目的专家无权访问任何诊断来帮助解决 FCM 问题。请联系支持。 https://firebase.google.com/support/
这可能是由 Firebase Cloud Messaging 中的不切实际的心跳间隔引起的。
FCM 通过维护从 Android 设备到 Google 服务器的空闲套接字连接来工作。这很棒,因为它几乎不消耗电池电量(与轮询相反),并且它允许设备在消息到达时立即被唤醒。
为确保连接保持活动状态,Android 将在移动连接上每 28 分钟发送一次心跳,在 WiFi 上每 15 分钟发送一次心跳。如果心跳失败,则连接已终止,FCM 将重新建立它并尝试检索任何待处理的推送通知。心跳间隔越高,电池消耗越少,设备从睡眠中唤醒的次数越少。
然而,这是有代价的:心跳间隔越长,识别断开的套接字连接所需的时间就越长。 Google 在部署 FCM 之前,尚未在现实生活中对这些间隔进行足够彻底的测试。这些间隔的问题是由网络路由器和移动运营商引起的,它们会在几分钟不活动后断开空闲套接字连接。
更多信息可在我的博客上找到:
http://eladnava.com/google-cloud-messaging-extremely-unreliable/
作为解决方法,请考虑 Pushy (https://pushy.me),它是 GCM/FCM 的直接替代品,可大大提高通知速度和可靠性(完全披露 - 我创立了 Pushy)。