1

So I'm attempting to setup em-websocket (or potentially Goliath), so that users can come to a different route and thusly be subscribed to only that channel, so for example:

example.com/channel_1

Browsers open there will only receive messages published to channel_1, actually to that point it doesn't have to be a route like this I'd settle for using params. So I'm using AMQP and it has the notion of a direct exchange, and routing keys. Is there something analogous to that with websockets?

I've got a Goliath server working but the issue is, that because it uses shared endpoints, I think that all the browsers open with a websocket connection are getting the same messages, here's what I'm doing:

channel.queue(params['channel'], :auto_delete => true).subscribe do |payload|
  config['channel'].push(payload)
end

So this example uses AMQP, which I'd still like to use, but the issue I think lies in that each client is reinstantiating EM::Channel.new, and then the messages are pushed to that channel, I just don't understand how I would have multiple clients subscribed to different channels.

Any help understanding this or guiding me to a more appropriate design pattern.

4

1 回答 1

3

如果你的频道是预定义的,你可以在你的服务器的配置文件中为每个频道做一个 EM::Channel.new,然后客户端将通过适当的频道发送/接收消息。

如果通道是由用户定义的,那么您需要在配置中设置一个哈希(或其他东西)来存储您的通道,当客户端连接时,检查配置哈希以查看通道是否存在,如果不存在' t, EM::Channel.new 并继续。如果存在,请使用现有频道。

在第二种情况下,您需要在客户端断开连接时执行一些逻辑,以处理在所有客户端都消失时关闭通道,否则您将发生内存泄漏。

于 2012-09-07T05:34:04.493 回答