Class: HotBunnies::Exchange
- Inherits:
-
Object
- Object
- HotBunnies::Exchange
- Defined in:
- lib/hot_bunnies/exchange.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #bind(exchange, options = {}) ⇒ Object
- #declare! ⇒ Object
- #delete(options = {}) ⇒ Object
-
#initialize(channel, name, options = {}) ⇒ Exchange
constructor
A new instance of Exchange.
- #predefined? ⇒ Boolean
- #publish(body, options = {}) ⇒ Object
Constructor Details
#initialize(channel, name, options = {}) ⇒ Exchange
Returns a new instance of Exchange.
7 8 9 10 11 |
# File 'lib/hot_bunnies/exchange.rb', line 7 def initialize(channel, name, ={}) @channel = channel @name = name @options = {:type => :fanout, :durable => false, :auto_delete => false, :internal => false, :passive => false}.merge() end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/hot_bunnies/exchange.rb', line 5 def channel @channel end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/hot_bunnies/exchange.rb', line 5 def name @name end |
Instance Method Details
#bind(exchange, options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/hot_bunnies/exchange.rb', line 22 def bind(exchange, ={}) exchange_name = if exchange.respond_to?(:name) then exchange.name else exchange.to_s end @channel.exchange_bind(@name, exchange_name, .fetch(:routing_key, '')) end |
#declare! ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/hot_bunnies/exchange.rb', line 31 def declare! unless predefined? if @options[:passive] then @channel.exchange_declare_passive(@name) else @channel.exchange_declare(@name, @options[:type].to_s, @options[:durable], @options[:auto_delete], @options[:internal], @options[:arguments]) end end end |
#delete(options = {}) ⇒ Object
18 19 20 |
# File 'lib/hot_bunnies/exchange.rb', line 18 def delete(={}) @channel.exchange_delete(@name, .fetch(:if_unused, false)) end |
#predefined? ⇒ Boolean
27 28 29 |
# File 'lib/hot_bunnies/exchange.rb', line 27 def predefined? @name.empty? || @name.start_with?("amq.") end |
#publish(body, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/hot_bunnies/exchange.rb', line 13 def publish(body, ={}) = {:routing_key => '', :mandatory => false, :immediate => false}.merge() @channel.basic_publish(@name, [:routing_key], [:mandatory], [:immediate], build_properties_from(.fetch(:properties, Hash.new)), body.to_java_bytes) end |