Erlang 中的消息队列模型(Comet 聊天)?
我正在用 Erlang 进行 Comet 聊天。我只使用一个连接(长轮询)进行消息传输。但是,如您所知,长轮询连接无法始终保持连接。每次有新消息到来或达到超时时,它都会中断,然后重新连接到服务器。如果在连接重新连接之前发送消息,那么保持聊天的完整性就会出现问题。
而且,如果用户使用 Comet-chat 打开多个窗口,则所有聊天消息都必须保持同步,这意味着用户可以拥有大量长轮询连接。因此,很难保证每条消息都按时送达。
我应该为每个连接建立一个消息队列吗?或者还有什么更好的方法来解决这个问题?
I am doing Comet chat with Erlang. I only use one connection (long-polling) for the message transportation. But, as you know, the long-polling connection can not be stay connected all the time. Every time a new message comes or reaches the timeout, it will break and then connect to the server again. If a message is sent before the connection re-connected, it is a problem to keep the integrity of chat.
And also, if a user opens more than one window with Comet-chat, all the chat messages have to keep sync, which means a user can have lots of long-polling connections. So it is hard to keep every message delivered on time.
Should I build a message queue for every connection? Or what else better way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,让每个用户有一个进程/消息队列连接到聊天(甚至有多个聊天窗口)似乎是最简单的方法。跟踪聊天窗口应用程序中最后一条消息的时间戳,并在重新连接时询问此时间戳之后的消息。消息队列进程应该仅将消息保留合理的时间跨度。在这种情况下,重新连接完全取决于客户端。在另一种情况下,您可以从服务器发送某种心跳,但对我来说似乎不太可靠。它不能解决超时以外的其他原因断开连接的问题。服务器端队列有许多变体,每个客户端、每个用户、每个聊天室、每个......都有一个队列。
For me seems simplest way to have one process/message queue per user connected to chat (even have more than one chat window). Than keep track of timestamp of last message in chat window application and when reconnect ask for messages after this timestamp. Message queue process should keeps messages only for reasonable time span. In this scenario reconnecting is all up to client. In another scenario you can send some sort of hart beats from server but it seems less reliable for me. It is not solving issue with other reason of disconnection than timeout. There are many variant of server side queuing as one queue per client, per user, per chat room, per ...