Class: AceMQ::AMQP::Patterns::Replay Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

One pass over a queue.

Constant Summary collapse

REQUEUE_WAIT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

How long a release waits, by default, for the declined messages to be counted back on the queue. Bounded, because a consumer draining the queue at the same time keeps the depth below the target and would hold it for ever.

5.0

Instance Method Summary collapse

Constructor Details

#initialize(connection, from:, exchange:, routing_key:, limit:, deadline:, restart:, filter:, requeue_wait: REQUEUE_WAIT) ⇒ Replay

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Replay.

Raises:

  • (ArgumentError)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/acemq/amqp/patterns/replay.rb', line 146

def initialize(connection, from:, exchange:, routing_key:, limit:, deadline:, restart:,
               filter:, requeue_wait: REQUEUE_WAIT)
  # The raw publish, because a replayed message keeps the bytes and the
  # envelope it already had; re-encoding it would be inventing a new
  # message with an old one's identity.
  @transport = connection.respond_to?(:transport) ? connection.transport : connection
  @from = from
  @exchange = exchange
  @routing_key = routing_key
  @limit = limit.to_i
  @deadline = deadline.to_f
  @restart = restart
  @requeue_wait = Float(requeue_wait)
  raise ArgumentError, "requeue_wait cannot be negative" if @requeue_wait.negative?

  @filter = filter
  @result = ReplayResult.new(moved: 0, skipped: 0, reason: :drained)
  # Messages the filter declines are held unacknowledged, not returned
  # one at a time. Returning one immediately does not work: the broker
  # puts it back where it was, at the head of the queue, so the next
  # read hands over the same message and everything behind it is never
  # looked at. Holding them takes them out of the way for the length of
  # the pass, and the broker still has them, so a crash half way through
  # returns them rather than losing them.
  @declined = []
end

Instance Method Details

#run ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/acemq/amqp/patterns/replay.rb', line 173

def run
  ends_at = @deadline.positive? ? monotonic + @deadline : nil
  loop do
    break @result.reason = :deadline if ends_at && monotonic >= ends_at
    break @result.reason = :limit if @limit.positive? && @result.moved >= @limit

    delivery = @transport.pull(@from)
    break @result.reason = :drained if delivery.nil?

    consider(delivery)
  end
  @result
ensure
  release
end