Dealing with queued WebSocket messages in iOS
I'm using WebSockets to push real-time data from my server. The updates are frequent and the JavaScript code for handling new messages is not insignificant.
If the client is an iPhone (for example) and the user exits Safari, messages are still received and queued.
When the user next opens Safari all the messages that were queued are handled in order. This introduces a significant lag for the application.
But I only ever need the most recent message. So if a situation like this occurs is there any way I can skip to the most recent message discarding the rest of the queue? The WebSocket itself doesn't seem to expose any information about queued messages.
Cheers, St开发者_如何学Cu
I don't think there is any WebSocket-native way to achieve what I'm trying to do.
So I ended up implementing my own JS message queue, always processing the most recent message and clearing anything older from the queue.
I suggest looking at Kafka for storing queued messages. It seems to work really well with the use case of persisting a message queue or activity feed.
精彩评论