Class: Distribot::BunnyConnector
- Defined in:
- lib/distribot/connector.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#subscribers ⇒ Object
Returns the value of attribute subscribers.
Attributes inherited from Connector
Instance Method Summary collapse
- #broadcast(topic, message) ⇒ Object
-
#initialize(*args) ⇒ BunnyConnector
constructor
A new instance of BunnyConnector.
- #publish(topic, message) ⇒ Object
- #queue_exists?(topic) ⇒ Boolean
- #subscribe(topic, options = {}, &block) ⇒ Object
- #subscribe_multi(topic, options = {}, &block) ⇒ Object
Methods inherited from Connector
Constructor Details
#initialize(*args) ⇒ BunnyConnector
Returns a new instance of BunnyConnector.
93 94 95 96 |
# File 'lib/distribot/connector.rb', line 93 def initialize(*args) super(*args) self.subscribers = [] end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
92 93 94 |
# File 'lib/distribot/connector.rb', line 92 def channel @channel end |
#subscribers ⇒ Object
Returns the value of attribute subscribers.
92 93 94 |
# File 'lib/distribot/connector.rb', line 92 def subscribers @subscribers end |
Instance Method Details
#broadcast(topic, message) ⇒ Object
134 135 136 137 138 |
# File 'lib/distribot/connector.rb', line 134 def broadcast(topic, ) exchange = channel.fanout(topic) logger.debug "broadcast(#{topic} -> #{message})" exchange.publish(.to_json, routing_key: topic) end |
#publish(topic, message) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/distribot/connector.rb', line 126 def publish(topic, ) queue = stubbornly :get_queue do channel.queue(topic, auto_delete: false, durable: true) end logger.debug "publish(#{topic} -> #{message})" channel.default_exchange.publish .to_json, routing_key: queue.name end |
#queue_exists?(topic) ⇒ Boolean
102 103 104 |
# File 'lib/distribot/connector.rb', line 102 def queue_exists?(topic) bunny.queue_exists?(topic) end |
#subscribe(topic, options = {}, &block) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/distribot/connector.rb', line 106 def subscribe(topic, = {}, &block) if [:solo] .delete :solo setup end subscriber = Subscription.new(bunny) subscribers << subscriber.start(topic, ) do || logger.debug "received(#{topic} -> #{message})" block.call() end end |
#subscribe_multi(topic, options = {}, &block) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/distribot/connector.rb', line 118 def subscribe_multi(topic, = {}, &block) subscriber = MultiSubscription.new(bunny) subscribers << subscriber.start(topic, ) do || logger.debug "received-multi(#{topic} -> #{message})" block.call() end end |