Parent

AMQP::Protocol::Header

Contains a properties hash that holds some potentially interesting information.

1 equals transient. 2 equals persistent. Unconsumed persistent messages will survive a server restart when they are stored in a durable queue.

True or False

The routing string used for matching this message to this queue.

An integer in the range of 0 to 9 inclusive.

Always "application/octet-stream" (byte stream)

The source exchange which published this message.

The number of unconsumed messages contained in the queue.

A monotonically increasing integer. This number should not be trusted as a sequence number. There is no guarantee it won't get reset.

Attributes

klass[RW]
properties[RW]
size[RW]
weight[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/amqp/protocol.rb, line 92
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

Public Instance Methods

==(header) click to toggle source
# File lib/amqp/protocol.rb, line 142
def == header
  [ :klass, :size, :weight, :properties ].inject(true) do |eql, field|
    eql and __send__(field) == header.__send__(field)
  end
end
method_missing(meth, *args, &blk) click to toggle source
# File lib/amqp/protocol.rb, line 148
def method_missing meth, *args, &blk
  @properties.has_key?(meth) || @klass.properties.find{|_,name| name == meth } ? @properties[meth] :
                                                                                 super
end
to_binary() click to toggle source
# File lib/amqp/protocol.rb, line 122
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) click to toggle source
# File lib/amqp/protocol.rb, line 138
def to_frame channel = 0
  Frame::Header.new(self, channel)
end
to_s() click to toggle source
# File lib/amqp/protocol.rb, line 134
def to_s
  to_binary.to_s
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.