Module: Wakame::AMQPClient::ClassMethods
- Defined in:
- lib/wakame/amqp_client.rb
Instance Attribute Summary collapse
-
#defered_setup_calls ⇒ Object
readonly
Returns the value of attribute defered_setup_calls.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #add_subscriber(*args) ⇒ Object
- #amq ⇒ Object
- #define_exchange(name, type = :fanout) ⇒ Object
- #define_queue(name, exchange_name, opts = {}) ⇒ Object
- #publish_to(*args) ⇒ Object
- #start(*opts) ⇒ Object
- #stop(&blk) ⇒ Object
Instance Attribute Details
#defered_setup_calls ⇒ Object (readonly)
Returns the value of attribute defered_setup_calls.
21 22 23 |
# File 'lib/wakame/amqp_client.rb', line 21 def defered_setup_calls @defered_setup_calls end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
20 21 22 |
# File 'lib/wakame/amqp_client.rb', line 20 def instance @instance end |
Instance Method Details
#add_subscriber(*args) ⇒ Object
78 79 80 |
# File 'lib/wakame/amqp_client.rb', line 78 def add_subscriber(*args) self.instance.add_subscriber(*args) end |
#amq ⇒ Object
70 71 72 |
# File 'lib/wakame/amqp_client.rb', line 70 def amq Thread.current[:mq] end |
#define_exchange(name, type = :fanout) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wakame/amqp_client.rb', line 82 def define_exchange(name, type=:fanout) def_ex = proc { |inst| inst.amq.__send__(type, name) } (@defered_setup_calls ||= []) << def_ex #if [email protected]? && @instance.connected? # def_ex.call(@instance) #end end |
#define_queue(name, exchange_name, opts = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/wakame/amqp_client.rb', line 94 def define_queue(name, exchange_name, opts={}) def_q = proc { |inst| inst.define_queue(name, exchange_name, opts) } (@defered_setup_calls ||= []) << def_q #if [email protected]? && @instance.connected? # def_q.call(@instance) #end end |
#publish_to(*args) ⇒ Object
74 75 76 |
# File 'lib/wakame/amqp_client.rb', line 74 def publish_to(*args) self.instance.publish_to(*args) end |
#start(*opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wakame/amqp_client.rb', line 23 def start(*opts) pr = proc { if self.instance.nil? @instance = new(*opts) end @instance } if EM.reactor_running? return pr.call else EM.run pr end end |
#stop(&blk) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wakame/amqp_client.rb', line 39 def stop(&blk) #EM.add_timer(1){ EM.next_tick { end_proc = proc { EventDispatcher.reset unless blk.nil? blk.call end EM.stop } catch(:nop) { if @instance.nil? end_proc.call throw :nop end begin unless @instance.amqp_client.nil? @instance.close { end_proc.call } else end_proc.call end ensure @instance = nil end } } end |