Class: MQ::Exchange
Constant Summary
Constants included from AMQP
AMQP::DIR, AMQP::FIELDS, AMQP::HEADER, AMQP::PORT, AMQP::RESPONSES, AMQP::VERSION, AMQP::VERSION_MAJOR, AMQP::VERSION_MINOR
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(mq, type, name, opts = {}) ⇒ Exchange
constructor
A new instance of Exchange.
- #publish(data, opts = {}) ⇒ Object
Methods included from AMQP
client, client=, connect, settings, start, stop
Constructor Details
#initialize(mq, type, name, opts = {}) ⇒ Exchange
Returns a new instance of Exchange.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mq/exchange.rb', line 5 def initialize mq, type, name, opts = {} @mq = mq @type, @name = type, name @mq.exchanges[@name = name] ||= self @key = opts[:key] @mq.callback{ @mq.send Protocol::Exchange::Declare.new({ :exchange => name, :type => type, :nowait => true }.merge(opts)) } unless name == "amq.#{type}" or name == '' end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'lib/mq/exchange.rb', line 17 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/mq/exchange.rb', line 17 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
17 18 19 |
# File 'lib/mq/exchange.rb', line 17 def type @type end |
Instance Method Details
#publish(data, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mq/exchange.rb', line 19 def publish data, opts = {} @mq.callback{ @mq.send Protocol::Basic::Publish.new({ :exchange => name, :routing_key => opts.delete(:key) || @key }.merge(opts)) data = data.to_s @mq.send Protocol::Header.new(Protocol::Basic, data.length, { :content_type => 'application/octet-stream', :delivery_mode => (opts.delete(:persistent) ? 2 : 1), :priority => 0 }.merge(opts)) @mq.send Frame::Body.new(data) } self end |