Class: AceMQ::AMQP::ConsumeContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(queue:, envelope:, payload:, body:, content_type:, redelivered:) ⇒ ConsumeContext

Returns a new instance of ConsumeContext.



171
172
173
174
175
176
177
178
179
# File 'lib/acemq/amqp/interceptors.rb', line 171

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.



169
170
171
# File 'lib/acemq/amqp/interceptors.rb', line 169

def body
  @body
end

#content_type ⇒ Object (readonly)

Returns the value of attribute content_type.



169
170
171
# File 'lib/acemq/amqp/interceptors.rb', line 169

def content_type
  @content_type
end

#envelope ⇒ Object

Returns the value of attribute envelope.



157
158
159
# File 'lib/acemq/amqp/interceptors.rb', line 157

def envelope
  @envelope
end

#payload ⇒ Object (readonly)

Returns the value of attribute payload.



169
170
171
# File 'lib/acemq/amqp/interceptors.rb', line 169

def payload
  @payload
end

#queue ⇒ Object (readonly)

Returns the value of attribute queue.



169
170
171
# File 'lib/acemq/amqp/interceptors.rb', line 169

def queue
  @queue
end

#redelivered ⇒ Object (readonly)

Returns the value of attribute redelivered.



169
170
171
# File 'lib/acemq/amqp/interceptors.rb', line 169

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.

Returns:



167
168
169
# File 'lib/acemq/amqp/interceptors.rb', line 167

def settlement
  @settlement
end

Instance Method Details

#redelivered? ⇒ Boolean

Returns:

  • (Boolean)


181
# File 'lib/acemq/amqp/interceptors.rb', line 181

def redelivered? = !!@redelivered

#set_header(name, value) ⇒ Object

Raises:

  • (ArgumentError) —

    when the name is reserved



184
185
186
# File 'lib/acemq/amqp/interceptors.rb', line 184

def set_header(name, value)
  @envelope = @envelope.with(headers: @envelope.headers.merge(name.to_s => value))
end

#to_s ⇒ Object



188
# File 'lib/acemq/amqp/interceptors.rb', line 188

def to_s = "handle #{@envelope.id} from #{@queue}"