Class: Ears::Middlewares::MaxRetries

Inherits:
Ears::Middleware show all
Defined in:
lib/ears/middlewares/max_retries.rb

Overview

A middleware that automatically puts messages on an error queue when the specified number of retries are exceeded.

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ MaxRetries

Returns a new instance of MaxRetries.

Parameters:

  • opts (Hash)

    The options for the middleware.

Options Hash (opts):

  • :retries (Integer)

    The number of retries before the message is sent to the error queue.

  • :error_queue (String)

    The name of the queue where messages should be sent to when the max retries are reached.



10
11
12
13
14
# File 'lib/ears/middlewares/max_retries.rb', line 10

def initialize(opts)
  super()
  @retries = opts.fetch(:retries)
  @error_queue = opts.fetch(:error_queue)
end

Instance Method Details

#call(delivery_info, metadata, payload, app) ⇒ Object



16
17
18
19
# File 'lib/ears/middlewares/max_retries.rb', line 16

def call(delivery_info, , payload, app)
  return handle_exceeded(payload) if retries_exceeded?()
  app.call(delivery_info, , payload)
end