Class: ActionSubscriber::Middleware::Env
- Inherits:
-
Object
- Object
- ActionSubscriber::Middleware::Env
- Defined in:
- lib/action_subscriber/middleware/env.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#encoded_payload ⇒ Object
readonly
Returns the value of attribute encoded_payload.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#routing_key ⇒ Object
readonly
Returns the value of attribute routing_key.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
Instance Method Summary collapse
- #acknowledge ⇒ Object
-
#initialize(subscriber, encoded_payload, properties) ⇒ Env
constructor
A new instance of Env.
- #nack ⇒ Object
- #reject ⇒ Object
- #safe_acknowledge ⇒ Object
- #safe_nack ⇒ Object
- #safe_reject ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(subscriber, encoded_payload, properties) ⇒ Env
Returns a new instance of Env.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/action_subscriber/middleware/env.rb', line 29 def initialize(subscriber, encoded_payload, properties) @action = properties.fetch(:action) @channel = properties[:channel] @content_type = properties.fetch(:content_type) @delivery_tag = properties.fetch(:delivery_tag) @encoded_payload = encoded_payload @exchange = properties.fetch(:exchange) @has_been_acked = false @has_been_nacked = false @has_been_rejected = false @headers = properties.fetch(:headers, {}) @message_id = properties.fetch(:message_id, ::SecureRandom.hex(3)) @queue = properties.fetch(:queue) @routing_key = properties.fetch(:routing_key) @subscriber = subscriber @uses_acknowledgements = properties.fetch(:uses_acknowledgements, false) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def action @action end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def content_type @content_type end |
#encoded_payload ⇒ Object (readonly)
Returns the value of attribute encoded_payload.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def encoded_payload @encoded_payload end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def exchange @exchange end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def headers @headers end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def @message_id end |
#payload ⇒ Object
Returns the value of attribute payload.
6 7 8 |
# File 'lib/action_subscriber/middleware/env.rb', line 6 def payload @payload end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def queue @queue end |
#routing_key ⇒ Object (readonly)
Returns the value of attribute routing_key.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def routing_key @routing_key end |
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
8 9 10 |
# File 'lib/action_subscriber/middleware/env.rb', line 8 def subscriber @subscriber end |
Instance Method Details
#acknowledge ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/action_subscriber/middleware/env.rb', line 47 def acknowledge fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel = false @has_been_acked = true @channel.ack(@delivery_tag, ) true end |
#nack ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/action_subscriber/middleware/env.rb', line 55 def nack fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel = false = true @has_been_nacked = true @channel.nack(@delivery_tag, , ) true end |
#reject ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/action_subscriber/middleware/env.rb', line 64 def reject fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel = true @has_been_rejected = true @channel.reject(@delivery_tag, ) true end |
#safe_acknowledge ⇒ Object
72 73 74 |
# File 'lib/action_subscriber/middleware/env.rb', line 72 def safe_acknowledge acknowledge if uses_acknowledgements? && @channel && !has_used_delivery_tag? end |
#safe_nack ⇒ Object
76 77 78 |
# File 'lib/action_subscriber/middleware/env.rb', line 76 def safe_nack nack if uses_acknowledgements? && @channel && !has_used_delivery_tag? end |
#safe_reject ⇒ Object
80 81 82 |
# File 'lib/action_subscriber/middleware/env.rb', line 80 def safe_reject reject if uses_acknowledgements? && @channel && !has_used_delivery_tag? end |
#to_hash ⇒ Object Also known as: to_h
84 85 86 87 88 89 90 91 92 |
# File 'lib/action_subscriber/middleware/env.rb', line 84 def to_hash { :action => action, :content_type => content_type, :exchange => exchange, :routing_key => routing_key, :payload => payload } end |