Class: AceMQ::AMQP::Settlement

Inherits:
Object
  • Object
show all
Defined in:
lib/acemq/amqp/interceptors.rb

Overview

What the consumer has decided to do with a delivery, before it does it.

An Ack is what the handler asked for; this is what the retry engine settled on, which is not always the same thing and is the part worth reporting. A handler that asks for a retry on its last attempt is dead-lettered, and a retry that will happen has a delay attached — a number that does not exist until the retry policy has been asked, which is why this is worked out before the interceptors are told rather than guessed from the ack afterwards.

Read it off the ConsumeContext in after_handle:

def after_handle(context, _ack)
record(context.settlement.outcome, context.settlement.delay)
end

The outcomes are the words every AceMQ library writes on a span, and rejected is kept apart from dead_lettered even though both end in the dead-letter queue: a message the handler refused on purpose is the system working, and one that ran out of attempts is not. parked is kept apart from both, because a message nothing could read is a third thing again.

Constant Summary collapse

ACKED =

Acknowledged: the handler was happy.

"acked"
REJECTED =

Refused by the handler, and dead-lettered because of it.

"rejected"
RETRIED =

Going round again, after #delay seconds.

"retried"
DEAD_LETTERED =

Out of attempts, or marked as something retrying cannot fix.

"dead_lettered"
PARKED =

Set aside in {queue}.parked for somebody to look at: the body would not decode, or the handler said the message cannot be read.

"parked"
IN_PROGRESS =

Put back on its own queue after #delay seconds, attempt unchanged, because another consumer holds a live idempotency claim on it. Not a retry and never a dead letter: nobody has failed to handle it yet.

"in_progress"
STOPPED =

Not settled at all: the handler failed on a consumer that stops on failure, such as a stream reader, which then stopped at this message.

"stopped"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outcome:, delay: nil, reason: nil) ⇒ Settlement

Returns a new instance of Settlement.



122
123
124
125
126
127
# File 'lib/acemq/amqp/interceptors.rb', line 122

def initialize(outcome:, delay: nil, reason: nil)
  @outcome = outcome
  @delay = delay
  @reason = reason
  freeze
end

Instance Attribute Details

#delay ⇒ Float? (readonly)

Returns seconds this message will wait, when it is a retry or in progress.

Returns:

  • (Float, nil) —

    seconds this message will wait, when it is a retry or in progress



118
119
120
# File 'lib/acemq/amqp/interceptors.rb', line 118

def delay
  @delay
end

#outcome ⇒ String (readonly)

Returns one of the words above.

Returns:

  • (String) —

    one of the words above



115
116
117
# File 'lib/acemq/amqp/interceptors.rb', line 115

def outcome
  @outcome
end

#reason ⇒ String? (readonly)

Returns why, when it is not going round again.

Returns:

  • (String, nil) —

    why, when it is not going round again



120
121
122
# File 'lib/acemq/amqp/interceptors.rb', line 120

def reason
  @reason
end

Class Method Details

.acked ⇒ Object



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

def self.acked = new(outcome: ACKED)

.dead_lettered(reason) ⇒ Object



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

def self.dead_lettered(reason) = new(outcome: DEAD_LETTERED, reason: reason)

.in_progress(delay) ⇒ Object



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

def self.in_progress(delay) = new(outcome: IN_PROGRESS, delay: delay)

.parked(reason) ⇒ Object



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

def self.parked(reason) = new(outcome: PARKED, reason: reason)

.rejected(reason) ⇒ Object



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

def self.rejected(reason) = new(outcome: REJECTED, reason: reason)

.retried(delay) ⇒ Object



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

def self.retried(delay) = new(outcome: RETRIED, delay: delay)

.stopped(reason) ⇒ Object



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

def self.stopped(reason) = new(outcome: STOPPED, reason: reason)

Instance Method Details

#acked? ⇒ Boolean

Returns:

  • (Boolean)


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

def acked? = @outcome == ACKED

#dead_letters? ⇒ Boolean

Whether the message is going to the dead-letter queue, which a rejection and a give-up both do. Parking is not one of them: it goes to a queue of its own, on purpose.

Returns:

  • (Boolean)


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

def dead_letters? = @outcome == REJECTED || @outcome == DEAD_LETTERED

#in_progress? ⇒ Boolean

Returns:

  • (Boolean)


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

def in_progress? = @outcome == IN_PROGRESS

#parked? ⇒ Boolean

Returns:

  • (Boolean)


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

def parked? = @outcome == PARKED

#retried? ⇒ Boolean

Returns:

  • (Boolean)


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

def retried? = @outcome == RETRIED

#stopped? ⇒ Boolean

Returns:

  • (Boolean)


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

def stopped? = @outcome == STOPPED

#to_s ⇒ Object



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

def to_s = @reason.nil? ? @outcome : "#{@outcome}: #{@reason}"