Class: Carrot::AMQP::Exchange
- Inherits:
-
Object
- Object
- Carrot::AMQP::Exchange
- Defined in:
- lib/amqp/exchange.rb
Instance Attribute Summary collapse
-
#carrot ⇒ Object
readonly
Returns the value of attribute carrot.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #delete(opts = {}) ⇒ Object
-
#initialize(carrot, type, name, opts = {}) ⇒ Exchange
constructor
A new instance of Exchange.
- #publish(data, opts = {}) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(carrot, type, name, opts = {}) ⇒ Exchange
Returns a new instance of Exchange.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/amqp/exchange.rb', line 5 def initialize(carrot, type, name, opts = {}) @server, @type, @name, @opts = carrot.server, type, name, opts @key = opts[:key] @carrot = carrot unless name == "amq.#{type}" or name == '' server.send_frame( Protocol::Exchange::Declare.new( { :exchange => name, :type => type, :nowait => true }.merge(opts) ) ) end end |
Instance Attribute Details
#carrot ⇒ Object (readonly)
Returns the value of attribute carrot.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def carrot @carrot end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def opts @opts end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def server @server end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/amqp/exchange.rb', line 3 def type @type end |
Instance Method Details
#delete(opts = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/amqp/exchange.rb', line 40 def delete(opts = {}) server.send_frame( Protocol::Exchange::Delete.new({ :exchange => name, :nowait => true }.merge(opts)) ) carrot.exchanges.delete(name) end |
#publish(data, opts = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/amqp/exchange.rb', line 20 def publish(data, opts = {}) out = [] out << Protocol::Basic::Publish.new( { :exchange => name, :routing_key => opts.delete(:key) || key }.merge(opts) ) data = data.to_s out << Protocol::Header.new( Protocol::Basic, data.length, { :content_type => 'application/octet-stream', :delivery_mode => (opts.delete(:persistent) ? 2 : 1), :priority => 0 }.merge(opts) ) out << Frame::Body.new(data) server.send_frame(*out) end |
#reset ⇒ Object
47 48 49 |
# File 'lib/amqp/exchange.rb', line 47 def reset initialize(server, type, name, opts) end |