Class: Bunny::DeliveryInfo

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

Overview

Wraps AMQ::Protocol::Basic::Deliver to provide access to the delivery properties as immutable hash as well as methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basic_deliver, consumer, channel) ⇒ DeliveryInfo

Returns a new instance of DeliveryInfo.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bunny/delivery_info.rb', line 27

def initialize(basic_deliver, consumer, channel)
  @basic_deliver = basic_deliver
  @hash          = {
    :consumer_tag => basic_deliver.consumer_tag,
    :delivery_tag => VersionedDeliveryTag.new(basic_deliver.delivery_tag, channel.recoveries_counter),
    :redelivered  => basic_deliver.redelivered,
    :exchange     => basic_deliver.exchange,
    :routing_key  => basic_deliver.routing_key,
    :consumer     => consumer,
    :channel      => channel
  }
  @consumer      = consumer
  @channel       = channel
end

Instance Attribute Details

#channelBunny::Channel (readonly)

Returns Channel this delivery is on.

Returns:



24
25
26
# File 'lib/bunny/delivery_info.rb', line 24

def channel
  @channel
end

#consumerBunny::Consumer (readonly)

Returns Consumer this delivery is for.

Returns:



22
23
24
# File 'lib/bunny/delivery_info.rb', line 22

def consumer
  @consumer
end

Instance Method Details

#[](k) ⇒ Object

Accesses delivery properties by key

See Also:

  • Hash#[]


50
51
52
# File 'lib/bunny/delivery_info.rb', line 50

def [](k)
  @hash[k]
end

#consumer_tagString

Returns Consumer tag this delivery is for.

Returns:

  • (String)

    Consumer tag this delivery is for



70
71
72
# File 'lib/bunny/delivery_info.rb', line 70

def consumer_tag
  @basic_deliver.consumer_tag
end

#delivery_tagString

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

Returns:

  • (String)

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



75
76
77
# File 'lib/bunny/delivery_info.rb', line 75

def delivery_tag
  @basic_deliver.delivery_tag
end

#each(*args, &block) ⇒ Object

Iterates over delivery properties

See Also:

  • Enumerable#each


44
45
46
# File 'lib/bunny/delivery_info.rb', line 44

def each(*args, &block)
  @hash.each(*args, &block)
end

#exchangeString

Returns Name of the exchange this message was published to.

Returns:

  • (String)

    Name of the exchange this message was published to



86
87
88
# File 'lib/bunny/delivery_info.rb', line 86

def exchange
  @basic_deliver.exchange
end

#inspectObject



65
66
67
# File 'lib/bunny/delivery_info.rb', line 65

def inspect
  to_hash.inspect
end

#redeliveredBoolean Also known as: redelivered?

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

Returns:

  • (Boolean)

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



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

def redelivered
  @basic_deliver.redelivered
end

#routing_keyString

Returns Routing key this message was published with.

Returns:

  • (String)

    Routing key this message was published with



91
92
93
# File 'lib/bunny/delivery_info.rb', line 91

def routing_key
  @basic_deliver.routing_key
end

#to_hashHash

Returns Hash representation of this delivery info.

Returns:

  • (Hash)

    Hash representation of this delivery info



55
56
57
# File 'lib/bunny/delivery_info.rb', line 55

def to_hash
  @hash
end

#to_sObject



60
61
62
# File 'lib/bunny/delivery_info.rb', line 60

def to_s
  to_hash.to_s
end