Class: Bunny::DeliveryInfo
- Inherits:
-
Object
- Object
- Bunny::DeliveryInfo
- 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. Hash representation is created lazily.
Instance Attribute Summary collapse
-
#channel ⇒ Bunny::Channel
readonly
Channel this delivery is on.
-
#consumer ⇒ Bunny::Consumer
readonly
Consumer this delivery is for.
Instance Method Summary collapse
-
#[](k) ⇒ Object
Accesses delivery properties by key.
-
#consumer_tag ⇒ String
Consumer tag this delivery is for.
-
#delivery_tag ⇒ String
Delivery identifier that is used to acknowledge, reject and nack deliveries.
-
#each(*args, &block) ⇒ Object
Iterates over delivery properties.
-
#exchange ⇒ String
Name of the exchange this message was published to.
-
#initialize(basic_deliver, consumer, channel) ⇒ DeliveryInfo
constructor
A new instance of DeliveryInfo.
- #inspect ⇒ Object
-
#redelivered ⇒ Boolean
(also: #redelivered?)
True if this delivery is a redelivery (the message was requeued at least once).
-
#routing_key ⇒ String
Routing key this message was published with.
-
#to_hash ⇒ Hash
Hash representation of this delivery info.
- #to_s ⇒ Object
Constructor Details
#initialize(basic_deliver, consumer, channel) ⇒ DeliveryInfo
Returns a new instance of DeliveryInfo.
25 26 27 28 29 |
# File 'lib/bunny/delivery_info.rb', line 25 def initialize(basic_deliver, consumer, channel) @basic_deliver = basic_deliver @consumer = consumer @channel = channel end |
Instance Attribute Details
#channel ⇒ Bunny::Channel (readonly)
Returns Channel this delivery is on.
22 23 24 |
# File 'lib/bunny/delivery_info.rb', line 22 def channel @channel end |
#consumer ⇒ Bunny::Consumer (readonly)
Returns Consumer this delivery is for.
20 21 22 |
# File 'lib/bunny/delivery_info.rb', line 20 def consumer @consumer end |
Instance Method Details
#[](k) ⇒ Object
Accesses delivery properties by key
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bunny/delivery_info.rb', line 39 def [](k) case k when :consumer_tag then @basic_deliver.consumer_tag when :delivery_tag then @basic_deliver.delivery_tag when :redelivered then @basic_deliver.redelivered when :exchange then @basic_deliver.exchange when :routing_key then @basic_deliver.routing_key when :consumer then @consumer when :channel then @channel else nil end end |
#consumer_tag ⇒ String
Returns Consumer tag this delivery is for.
76 77 78 |
# File 'lib/bunny/delivery_info.rb', line 76 def consumer_tag @basic_deliver.consumer_tag end |
#delivery_tag ⇒ String
Returns Delivery identifier that is used to acknowledge, reject and nack deliveries.
81 82 83 |
# File 'lib/bunny/delivery_info.rb', line 81 def delivery_tag @basic_deliver.delivery_tag end |
#each(*args, &block) ⇒ Object
Iterates over delivery properties
33 34 35 |
# File 'lib/bunny/delivery_info.rb', line 33 def each(*args, &block) to_hash.each(*args, &block) end |
#exchange ⇒ String
Returns Name of the exchange this message was published to.
92 93 94 |
# File 'lib/bunny/delivery_info.rb', line 92 def exchange @basic_deliver.exchange end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/bunny/delivery_info.rb', line 71 def inspect to_hash.inspect end |
#redelivered ⇒ Boolean Also known as: redelivered?
Returns true if this delivery is a redelivery (the message was requeued at least once).
86 87 88 |
# File 'lib/bunny/delivery_info.rb', line 86 def redelivered @basic_deliver.redelivered end |
#routing_key ⇒ String
Returns Routing key this message was published with.
97 98 99 |
# File 'lib/bunny/delivery_info.rb', line 97 def routing_key @basic_deliver.routing_key end |
#to_hash ⇒ Hash
Returns Hash representation of this delivery info.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bunny/delivery_info.rb', line 53 def to_hash @hash ||= { consumer_tag: @basic_deliver.consumer_tag, delivery_tag: @basic_deliver.delivery_tag, redelivered: @basic_deliver.redelivered, exchange: @basic_deliver.exchange, routing_key: @basic_deliver.routing_key, consumer: @consumer, channel: @channel } end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/bunny/delivery_info.rb', line 66 def to_s to_hash.to_s end |