Class: Push::Backend::AMQP
- Inherits:
-
Object
- Object
- Push::Backend::AMQP
- Includes:
- Logging
- Defined in:
- lib/push/backend.rb
Instance Method Summary collapse
-
#async_publish(message, exchange) ⇒ Object
Run this puppy inside of Em.
-
#connection ⇒ Object
Make sure we setup and use one connection per Push instance.
- #publish(message, exchange) ⇒ Object
-
#sync_publish(message, exchange) ⇒ Object
Deal with running AMQP inside of a sync environment.
Instance Method Details
#async_publish(message, exchange) ⇒ Object
Run this puppy inside of Em.
21 22 23 24 25 26 27 28 |
# File 'lib/push/backend.rb', line 21 def async_publish(, exchange) channel = ::AMQP::Channel.new(connection) channel.fanout(exchange).publish() EM.next_tick { channel.close logger.debug "Channel closed" } end |
#connection ⇒ Object
Make sure we setup and use one connection per Push instance. AMQP wants to minimize connects/reconnects, so we connect once here and let publish use this connection.
33 34 35 |
# File 'lib/push/backend.rb', line 33 def connection @connection ||= ::AMQP.connect(Push.config.amqp.to_hash) end |
#publish(message, exchange) ⇒ Object
7 8 9 10 |
# File 'lib/push/backend.rb', line 7 def publish(, exchange) EM.reactor_running? ? async_publish(, exchange) : sync_publish(, exchange) logger.debug "Published '#{}' to exchange #{exchange}" end |
#sync_publish(message, exchange) ⇒ Object
Deal with running AMQP inside of a sync environment. This is useful for script/console testing and our pe_result_processor.
14 15 16 17 18 |
# File 'lib/push/backend.rb', line 14 def sync_publish(, exchange) Bunny.run(Push.config.amqp.to_hash) { |channel| channel.exchange(exchange, :type => :fanout).publish() } end |