Class: MarchHare::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/march_hare/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, consumer_tag, envelope, properties) ⇒ Headers

Returns a new instance of Headers.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/march_hare/metadata.rb', line 5

def initialize(channel, consumer_tag, envelope, properties)
  @channel      = channel
  @consumer_tag = consumer_tag
  @envelope     = envelope
  @properties   = properties

  # Prime the delivery tag when the instance is created. If #delivery_tag is first
  # called after a recovery, then it'll fail to mismatch and will allow an invalid
  # ack/nack, which will cause the channel to unexpectedly close
  @delivery_tag = delivery_tag
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



3
4
5
# File 'lib/march_hare/metadata.rb', line 3

def channel
  @channel
end

#consumer_tagObject (readonly)

Returns the value of attribute consumer_tag.



3
4
5
# File 'lib/march_hare/metadata.rb', line 3

def consumer_tag
  @consumer_tag
end

#envelopeObject (readonly)

Returns the value of attribute envelope.



3
4
5
# File 'lib/march_hare/metadata.rb', line 3

def envelope
  @envelope
end

#propertiesObject (readonly)

Returns the value of attribute properties.



3
4
5
# File 'lib/march_hare/metadata.rb', line 3

def properties
  @properties
end

Instance Method Details

#ack(options = {}) ⇒ Object



17
18
19
# File 'lib/march_hare/metadata.rb', line 17

def ack(options={})
  @channel.basic_ack(delivery_tag, options.fetch(:multiple, false))
end

#delivery_tagObject



37
38
39
# File 'lib/march_hare/metadata.rb', line 37

def delivery_tag
  @delivery_tag ||= VersionedDeliveryTag.new(@envelope.delivery_tag, @channel.recoveries_counter.get)
end

#headersObject



62
63
64
# File 'lib/march_hare/metadata.rb', line 62

def headers
  deep_normalize_headers(@properties.headers)
end

#persistent?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/march_hare/metadata.rb', line 66

def persistent?
  delivery_mode == 2
end

#redelivered?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/march_hare/metadata.rb', line 70

def redelivered?
  redeliver
end

#redelivery?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/march_hare/metadata.rb', line 74

def redelivery?
  redeliver
end

#reject(options = {}) ⇒ Object



21
22
23
# File 'lib/march_hare/metadata.rb', line 21

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