Apple Push Notifications 可以用作消息队列吗?

Can Apple Push Notifications be used as message queues?

假设我有一个聊天应用程序,我正在向另一个用户(用户 B)发送消息,我们的消息通常使用套接字接收,但是当用户 B 离线时,他与套接字服务器断开连接,但用户 A 是继续给他发短信,因此我的服务器会针对用户 A 发送的每条消息向用户 B 的设备发出推送通知。我的问题是 APNS 是否会充当消息代理并将所有消息排队,直到用户 B 重新登录并接收它们?或者我是否必须将未收到的消息存储在其他地方

答案很容易在Apple's documentation

中找到

Apple Push Notification service includes a Quality of Service (QoS) component that performs a store-and-forward function. If APNs attempts to deliver a notification and the destination device is offline, APNs stores the notification for a limited period of time and delivers it when the device becomes available again. This component stores only the most recent notification per device and per app. If a device is offline, sending a notification request targeting that device causes the previous request to be discarded. If a device remains offline for a long time, all its stored notifications in APNs are discarded.

所以,不,您不能将 APN 用作消息代理。

您可以使用推送通知作为信号唤醒并与服务器端消息队列同步。 RabbitMQ 或 Kafka 可能是候选代理,而 MQTT 作为一种协议看起来很有前途。您将需要弄清楚如何以及何时丢弃未成功传送到设备的消息队列的内容。