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.

Instance Method Summary collapse

Constructor Details

#initialize(connection, from:, exchange:, routing_key:, limit:, deadline:, restart:, filter:) ⇒ 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.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/acemq/amqp/patterns/replay.rb', line 134

def initialize(connection, from:, exchange:, routing_key:, limit:, deadline:, restart:,
               filter:)
  # 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
  @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.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/acemq/amqp/patterns/replay.rb', line 158

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