Class: Bunny::GetResponse

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bunny/get_response.rb

Overview

Wraps AMQ::Protocol::Basic::GetOk to provide access to the delivery properties as immutable hash as well as methods. Hash representation is created lazily.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channelBunny::Channel (readonly)

Returns Channel this basic.get-ok response is on.

Returns:

  • Channel this basic.get-ok response is on



20
21
22
# File 'lib/bunny/get_response.rb', line 20

def channel
  @channel
end

Instance Method Details

#[](k) ⇒ Object

Accesses delivery properties by key

See Also:

  • Hash#[]


36
37
38
39
40
41
42
43
44
45
# File 'lib/bunny/get_response.rb', line 36

def [](k)
  case k
  when :delivery_tag then @get_ok.delivery_tag
  when :redelivered  then @get_ok.redelivered
  when :exchange     then @get_ok.exchange
  when :routing_key  then @get_ok.routing_key
  when :channel      then @channel
  else nil
  end
end

#delivery_tagString

Returns Delivery identifier that is used to acknowledge, reject and nack deliveries.

Returns:

  • Delivery identifier that is used to acknowledge, reject and nack deliveries



69
70
71
# File 'lib/bunny/get_response.rb', line 69

def delivery_tag
  @get_ok.delivery_tag
end

#each(*args, &block) ⇒ Object

Iterates over the delivery properties

See Also:

  • Enumerable#each


30
31
32
# File 'lib/bunny/get_response.rb', line 30

def each(*args, &block)
  to_hash.each(*args, &block)
end

#exchangeString

Returns Name of the exchange this message was published to.

Returns:

  • Name of the exchange this message was published to



80
81
82
# File 'lib/bunny/get_response.rb', line 80

def exchange
  @get_ok.exchange
end

#redeliveredBoolean Also known as: redelivered?

Returns true if this delivery is a redelivery (the message was requeued at least once).

Returns:

  • true if this delivery is a redelivery (the message was requeued at least once)



74
75
76
# File 'lib/bunny/get_response.rb', line 74

def redelivered
  @get_ok.redelivered
end

#routing_keyString

Returns Routing key this message was published with.

Returns:

  • Routing key this message was published with



85
86
87
# File 'lib/bunny/get_response.rb', line 85

def routing_key
  @get_ok.routing_key
end

#to_hashHash

Returns Hash representation of this delivery info.

Returns:

  • Hash representation of this delivery info



48
49
50
51
52
53
54
55
56
# File 'lib/bunny/get_response.rb', line 48

def to_hash
  @hash ||= {
    :delivery_tag => @get_ok.delivery_tag,
    :redelivered  => @get_ok.redelivered,
    :exchange     => @get_ok.exchange,
    :routing_key  => @get_ok.routing_key,
    :channel      => @channel
  }
end