Class: Carrot::AMQP::Protocol::Header
- Inherits:
-
Object
- Object
- Carrot::AMQP::Protocol::Header
- Defined in:
- lib/amqp/protocol.rb
Overview
:startdoc:
Contains a properties hash that holds some potentially interesting information.
-
:delivery_mode
1 equals transient. 2 equals persistent. Unconsumed persistent messages will survive a server restart when they are stored in a durable queue.
-
:redelivered
True or False
-
:routing_key
The routing string used for matching this message to this queue.
-
:priority
An integer in the range of 0 to 9 inclusive.
-
:content_type
Always “application/octet-stream” (byte stream)
-
:exchange
The source exchange which published this message.
-
:message_count
The number of unconsumed messages contained in the queue.
-
:delivery_tag
A monotonically increasing integer. This number should not be trusted as a sequence number. There is no guarantee it won’t get reset.
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#size ⇒ Object
Returns the value of attribute size.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #==(header) ⇒ Object
-
#initialize(*args) ⇒ Header
constructor
A new instance of Header.
- #method_missing(meth, *args, &blk) ⇒ Object
- #to_binary ⇒ Object
- #to_frame(channel = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Header
Returns a new instance of Header.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/amqp/protocol.rb', line 89 def initialize *args opts = args.pop if args.last.is_a? Hash opts ||= {} first = args.shift if first.is_a? ::Class and first.ancestors.include? Protocol::Class @klass = first @size = args.shift || 0 @weight = args.shift || 0 @properties = opts elsif first.is_a? Buffer or first.is_a? String buf = first buf = Buffer.new(buf) unless buf.is_a? Buffer @klass = Protocol.classes[buf.read(:short)] @weight = buf.read(:short) @size = buf.read(:longlong) props = buf.read(:properties, *klass.properties.map{|type,_| type }) @properties = Hash[*klass.properties.map{|_,name| name }.zip(props).reject{|k,v| v.nil? }.flatten] else raise ArgumentError, 'Invalid argument' end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
145 146 147 148 |
# File 'lib/amqp/protocol.rb', line 145 def method_missing meth, *args, &blk @properties.has_key?(meth) || @klass.properties.find{|_,name| name == meth } ? @properties[meth] : super end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
117 118 119 |
# File 'lib/amqp/protocol.rb', line 117 def klass @klass end |
#properties ⇒ Object
Returns the value of attribute properties.
117 118 119 |
# File 'lib/amqp/protocol.rb', line 117 def properties @properties end |
#size ⇒ Object
Returns the value of attribute size.
117 118 119 |
# File 'lib/amqp/protocol.rb', line 117 def size @size end |
#weight ⇒ Object
Returns the value of attribute weight.
117 118 119 |
# File 'lib/amqp/protocol.rb', line 117 def weight @weight end |
Instance Method Details
#==(header) ⇒ Object
139 140 141 142 143 |
# File 'lib/amqp/protocol.rb', line 139 def == header [ :klass, :size, :weight, :properties ].inject(true) do |eql, field| eql and __send__(field) == header.__send__(field) end end |
#to_binary ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/amqp/protocol.rb', line 119 def to_binary buf = Buffer.new buf.write :short, klass.id buf.write :short, weight # XXX rabbitmq only supports weight == 0 buf.write :longlong, size buf.write :properties, (klass.properties.map do |type, name| [ type, properties[name] || properties[name.to_s] ] end) buf.rewind buf end |
#to_frame(channel = 0) ⇒ Object
135 136 137 |
# File 'lib/amqp/protocol.rb', line 135 def to_frame channel = 0 Frame::Header.new(self, channel) end |
#to_s ⇒ Object
131 132 133 |
# File 'lib/amqp/protocol.rb', line 131 def to_s to_binary.to_s end |