Class: Lepus::Consumers::Handler

Inherits:
Bunny::Consumer
  • Object
show all
Includes:
Web::HandlerExtensions
Defined in:
lib/lepus/consumers/handler.rb

Overview

Wraps the user-defined consumer to provide the expected interface to Bunny.

Instance Attribute Summary

Attributes included from Web::HandlerExtensions

#stats

Instance Method Summary collapse

Constructor Details

#initialize(consumer_class, channel, queue, consumer_tag, arguments = {}) ⇒ Handler

Returns a new instance of Handler.

Parameters:

  • consumer_class (Lepus::Consumer)

    The user-defined consumer implementation derived from Lepus::Consumer.

  • channel (Bunny::Channel)

    The channel used for the consumer.

  • queue (Bunny::Queue)

    The queue the consumer is subscribed to.

  • consumer_tag (String)

    A string identifying the consumer instance.

  • arguments (Hash) (defaults to: {})

    Arguments that are passed on to Bunny::Consumer.new.



12
13
14
15
# File 'lib/lepus/consumers/handler.rb', line 12

def initialize(consumer_class, channel, queue, consumer_tag, arguments = {})
  @consumer_class = consumer_class
  super(channel, queue, consumer_tag, _no_ack = false, _exclusive = false, arguments)
end

Instance Method Details

#process_delivery(delivery_info, metadata, payload) ⇒ Object

Called when a message is received from the subscribed queue.

Parameters:

  • delivery_info (Bunny::DeliveryInfo)

    The delivery info of the received message.

  • metadata (Bunny::MessageProperties)

    The metadata of the received message.

  • payload (String)

    The payload of the received message.



22
23
24
25
26
27
28
# File 'lib/lepus/consumers/handler.rb', line 22

def process_delivery(delivery_info, , payload)
  consumer
    .process_delivery(delivery_info, , payload)
    .tap do |result|
      process_result(result, delivery_info.delivery_tag)
    end
end