[英]Ruby Redis with em-synchrony and PubSub problems
I'm using the Cramp framework together with the Redis gem and em-synchrony and WebSockets to build a chat related web application, and having some problems. 我将Cramp框架与Redis gem,em-synchrony和WebSockets一起使用来构建与聊天相关的Web应用程序,但遇到了一些问题。
consider the following code: 考虑以下代码:
class DrawingAction < Cramp::Action
use_fiber_pool
self.transport = :websocket
on_start :user_joined
on_data :message_received
on_finish :user_left
def user_joined
# Create pub/sub clients for the user who just joined
initialize_pub_sub
end
def initialize_pub_sub
@@redis_client ||= Redis.new(:driver => :synchrony)
@publisher ||= Redis.new(:driver => :synchrony)
@subscriber ||= Redis.new(:driver => :synchrony)
end
def handle_join(join_data)
room_name = join_data[:room_name]
@subscriber.subscribe(room_name) do |on|
on.message do |channel, message|
render message
end
end
puts "fetching history items"
history_items = history_for_room(room_name)
render "{ \"history\": true, \"time:\": #{Time.now.to_f}, \"data\": [#{history_items.join(',')}] }"
end
handle_join
is being called from the on_message
event handler of my Cramp action, since cramp supports synchrony and fibers, after a client joins a channel, the @subscriber.subscribe block operates as non-blocking like it should, meaning that it accepts messages fetched on the pubsub channel, and does not block everything else in the process (the application is not blocked), BUT it doesn't move on to the next line ( puts "fetching history items"
) which is a major problem for me, has anyone got a hint on what can be done to rectify this problem? handle_join
被从被叫on_message
我的痉挛作用的事件处理程序,由于抽筋支持同步和纤维,客户机加入的信道之后,@ subscriber.subscribe块作为非阻塞像它应该运行时,这意味着它接受邮件拿来pubsub通道,并且不会阻止进程中的其他所有内容(应用程序不会被阻止),但是它不会继续前进到下一行( puts "fetching history items"
),这对我来说是一个主要问题,有人得到了有关如何解决此问题的提示?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.