lib/mq.rb in amqp-0.5.3 vs lib/mq.rb in amqp-0.5.5
- old
+ new
@@ -16,11 +16,15 @@
class MQ
include AMQP
include EM::Deferrable
- def initialize
+ def initialize connection = nil
+ raise 'MQ can only be used from within EM.run{}' unless EM.reactor_running?
+
+ @connection = connection || AMQP.start
+
conn.callback{ |c|
@channel = c.add_channel(self)
send Protocol::Channel::Open.new
}
end
@@ -135,15 +139,10 @@
return unless MQ.logging
pp args
puts
end
- # create a class level connection on demand
-
- def connection
- raise 'MQ can only be used within EM.run{}' unless EM.reactor_running?
- @@connection ||= AMQP.start
- end
+ attr_reader :connection
alias :conn :connection
end
# convenience wrapper for thread-local MQ object
\ No newline at end of file