Class: AceMQ::AMQP::ConsumeContext
- Inherits:
-
Object
- Object
- AceMQ::AMQP::ConsumeContext
- Defined in:
- lib/acemq/amqp/interceptors.rb
Overview
A message that has arrived, as an interceptor sees it before the handler.
The payload is already decoded, which is the useful moment: an interceptor that had to decode the body itself would be doing the codec's work twice and could disagree with it.
The envelope can be replaced, and what replaces it is what the handler receives and what any dead letter is written with — so an interceptor can stamp something onto a message on the way in and have it survive all the way to the queue somebody looks at.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#envelope ⇒ Object
Returns the value of attribute envelope.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#redelivered ⇒ Object
readonly
Returns the value of attribute redelivered.
-
#settlement ⇒ Settlement?
What the consumer is about to do with this delivery.
Instance Method Summary collapse
-
#initialize(queue:, envelope:, payload:, body:, content_type:, redelivered:) ⇒ ConsumeContext
constructor
A new instance of ConsumeContext.
- #redelivered? ⇒ Boolean
- #set_header(name, value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(queue:, envelope:, payload:, body:, content_type:, redelivered:) ⇒ ConsumeContext
Returns a new instance of ConsumeContext.
176 177 178 179 180 181 182 183 184 |
# File 'lib/acemq/amqp/interceptors.rb', line 176 def initialize(queue:, envelope:, payload:, body:, content_type:, redelivered:) @queue = queue @envelope = envelope @settlement = nil @payload = payload @body = body @content_type = content_type @redelivered = redelivered end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
174 175 176 |
# File 'lib/acemq/amqp/interceptors.rb', line 174 def body @body end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
174 175 176 |
# File 'lib/acemq/amqp/interceptors.rb', line 174 def content_type @content_type end |
#envelope ⇒ Object
Returns the value of attribute envelope.
162 163 164 |
# File 'lib/acemq/amqp/interceptors.rb', line 162 def envelope @envelope end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
174 175 176 |
# File 'lib/acemq/amqp/interceptors.rb', line 174 def payload @payload end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
174 175 176 |
# File 'lib/acemq/amqp/interceptors.rb', line 174 def queue @queue end |
#redelivered ⇒ Object (readonly)
Returns the value of attribute redelivered.
174 175 176 |
# File 'lib/acemq/amqp/interceptors.rb', line 174 def redelivered @redelivered end |
#settlement ⇒ Settlement?
What the consumer is about to do with this delivery.
Nil until the handler has returned, and set before after_handle runs
— so an interceptor that wants to know whether the message is going
round again, and after how long, can read it there rather than work it
out from the ack, which cannot say.
172 173 174 |
# File 'lib/acemq/amqp/interceptors.rb', line 172 def settlement @settlement end |
Instance Method Details
#redelivered? ⇒ Boolean
186 |
# File 'lib/acemq/amqp/interceptors.rb', line 186 def redelivered? = !!@redelivered |
#set_header(name, value) ⇒ Object
189 190 191 |
# File 'lib/acemq/amqp/interceptors.rb', line 189 def set_header(name, value) @envelope = @envelope.with(headers: @envelope.headers.merge(name.to_s => value)) end |
#to_s ⇒ Object
193 |
# File 'lib/acemq/amqp/interceptors.rb', line 193 def to_s = "handle #{@envelope.id} from #{@queue}" |