使用 Android 云到设备消息传递 (C2DM) 确保消息传递
文档说“C2DM 不保证消息的传递或顺序。因此,例如,虽然您可能使用此功能告诉即时消息应用程序用户有新消息,但您可能不会使用它来传递实际消息消息。”
我正在构建一个应用程序,消息将在其中传递,并且传递消息很重要。它在某些方面类似于即时通讯应用程序。
我想到的一些选项...
使用 C2DM 发送消息,但让移动应用程序在接收时执行回调以通知服务器(这有明显的限制,但应用程序不是关键任务)
使用 C2DM 通知应用程序有一条新消息,然后从应用程序服务器上读取它 -使用轮询处理 C2DM 未能通知
使用 C2DM 并接受一些消息消息将不会被传递。我不清楚为什么消息不会被传递。我猜想 C2DM 有重试限制,所以如果设备离线,它可能永远不会到达。我也不清楚预期失败的百分比是多少。
您会推荐什么方法?
The docs say "C2DM makes no guarantees about delivery or the order of messages. So, for example, while you might use this feature to tell an instant messaging application that the user has new messages, you probably would not use it to pass the actual messages."
I'm building an app where messages will be passed, and where it is important that they are delivered. It's in some ways analogous to an instant-messaging app.
Some options that come to mind...
Send the message using C2DM, but have the mobile app do a callback on receive to notify the server (this has the obvious limitation, but the app isn't mission critical)
Use C2DM to notify the app that there is a new message, and then read it off an app server - using polling to handle C2DM failing to notify
Use C2DM and accept some messages won't get delivered. It's not clear to me why a message wouldn't be delivered. I guess C2DM has a retry limit so if the device is offline, it may never arrive. It's also unclear to me what % to expect to fail.
What approach would you recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为C2DM是一个很好的解决方案供您实施。正如 Google 建议的那样,我相信您应该让设备在收到来自 C2DM 的通知时联系您的服务器。这样您就可以确保消息按照正确的顺序接收,因为 Google 也不保证消息的接收顺序。此外,如果一次推送丢失,该消息将会丢失,但如果您让手机在下一次推送时联系您的服务器,您可以显示整个历史记录并避免丢失任何消息。
I think C2DM is a good solution for you to implement. As Google recommends, I believe you should have the device contact your server when it receives a notification from C2DM. This way you are sure that messages are being received in the correct order, as Google also does not guarantee the order in which messages will be received. In addition, if one push if lost, that message would be lost, but if you have the phone contact your server on the next push, you can show the whole history and avoid losing any messages.
为什么需要在 C2DM 消息中传递有效负载?发送 C2DM 消息告诉应用程序有新内容,让应用程序去您的应用程序服务器获取新内容。使用最后一次调用作为 C2DM 消息传递的确认。这样您就可以在应用服务器中实现超时并再次发送 C2DM 消息。
否则我会说 C2DM 不是您正在寻找的。
Why do you need to deliver the payload inside the C2DM message? Send a C2DM message telling the app that there is new content, make the app go to your app server to fetch new content. Use this last call as a confirmation of the delivery of the C2DM message. This way you can implement a timeout in the app server and send again the C2DM message.
Else I would say that C2DM isn't what you are looking for.
关于:“在 200 多次推送中,我没有目睹过失败的交付”
根据我的经验,设备充电时与使用电池运行时的交付行为有所不同。当设备插入时,我做了很多初始测试,并在现场看到了不同的结果。还有其他人看过这个吗?有没有充电时不进入的更深层次的省电模式?
Regarding: "Out of more than 200 pushes, I haven't witnessed a failed delivery"
In my experience the delivery behaves differently when the device is charging v.s. running on battery. I did a lot of initial testing while the device was plugged in and saw different results in the field. Has anyone else seen this? Is there a deeper power save mode that is not entered while charging?