Class: AMQP::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/amqp/header.rb

Overview

Message metadata (aka envelope).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, method, attributes) ⇒ Header

Returns a new instance of Header.



27
28
29
# File 'lib/amqp/header.rb', line 27

def initialize(channel, method, attributes)
  @channel, @method, @attributes = channel, method, attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

Returns AMQP message attributes.



115
116
117
118
119
120
121
# File 'lib/amqp/header.rb', line 115

def method_missing(meth, *args, &blk)
  if @attributes && args.empty? && blk.nil? && @attributes.has_key?(meth)
    @attributes[meth]
  else
    @method.__send__(meth, *args, &blk)
  end
end

Instance Attribute Details

#attributesHash (readonly)

AMQP message attributes

Returns:

  • (Hash)


24
25
26
# File 'lib/amqp/header.rb', line 24

def attributes
  @attributes
end

#channelAMQP::Channel (readonly)

Returns:



13
14
15
# File 'lib/amqp/header.rb', line 13

def channel
  @channel
end

#methodAMQ::Protocol::Method (readonly)

AMQP method frame this header is associated with. Carries additional information that varies between AMQP methods.

Returns:

  • (AMQ::Protocol::Method)


20
21
22
# File 'lib/amqp/header.rb', line 20

def method
  @method
end

Instance Method Details

#ack(multiple = false) ⇒ Object

Acknowledges the receipt of this message with the server.

Parameters:

  • multiple (Boolean) (defaults to: false)

    Whether or not to acknowledge multiple messages



34
35
36
# File 'lib/amqp/header.rb', line 34

def ack(multiple = false)
  @channel.acknowledge(@method.delivery_tag, multiple)
end

#consumer_tagObject

delivery_tag



55
56
57
# File 'lib/amqp/header.rb', line 55

def consumer_tag
  @method.consumer_tag
end

#content_typeObject

delivery_mode



84
85
86
# File 'lib/amqp/header.rb', line 84

def content_type
  @attributes[:content_type]
end

#correlation_idObject

reply_to



104
105
106
# File 'lib/amqp/header.rb', line 104

def correlation_id
  @attributes[:correlation_id]
end

#delivery_modeObject

headers



80
81
82
# File 'lib/amqp/header.rb', line 80

def delivery_mode
  @attributes[:delivery_mode]
end

#delivery_tagObject

to_hash



51
52
53
# File 'lib/amqp/header.rb', line 51

def delivery_tag
  @method.delivery_tag
end

#exchangeObject

redelivered?



67
68
69
# File 'lib/amqp/header.rb', line 67

def exchange
  @method.exchange
end

#headerObject

Deprecated.


72
73
74
# File 'lib/amqp/header.rb', line 72

def header
  @attributes
end

#headersObject

header



76
77
78
# File 'lib/amqp/header.rb', line 76

def headers
  @attributes[:headers]
end

#message_idObject

correlation_id



108
109
110
# File 'lib/amqp/header.rb', line 108

def message_id
  @attributes[:message_id]
end

#priorityObject

type



96
97
98
# File 'lib/amqp/header.rb', line 96

def priority
  @attributes[:priority]
end

#redeliveredObject

consumer_tag



59
60
61
# File 'lib/amqp/header.rb', line 59

def redelivered
  @method.redelivered
end

#redelivered?Boolean

redelivered

Returns:

  • (Boolean)


63
64
65
# File 'lib/amqp/header.rb', line 63

def redelivered?
  @method.redelivered
end

#reject(opts = {}) ⇒ Object

Reject this message.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :requeue (Hash) — default: false

    Whether message should be requeued.



41
42
43
# File 'lib/amqp/header.rb', line 41

def reject(opts = {})
  @channel.reject(@method.delivery_tag, opts.fetch(:requeue, false))
end

#reply_toObject

priority



100
101
102
# File 'lib/amqp/header.rb', line 100

def reply_to
  @attributes[:reply_to]
end

#timestampObject

content_type



88
89
90
# File 'lib/amqp/header.rb', line 88

def timestamp
  @attributes[:timestamp]
end

#to_hashHash

Returns AMQP message header w/o method-specific information.

Returns:

  • (Hash)

    AMQP message header w/o method-specific information.



47
48
49
# File 'lib/amqp/header.rb', line 47

def to_hash
  @attributes
end

#typeObject

timestamp



92
93
94
# File 'lib/amqp/header.rb', line 92

def type
  @attributes[:type]
end