Class: Ears::ConsumerWrapper

Inherits:
Bunny::Consumer
  • Object
show all
Defined in:
lib/ears/consumer_wrapper.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(consumer, channel, queue, consumer_tag, arguments = {}) ⇒ ConsumerWrapper

Returns a new instance of ConsumerWrapper.

Parameters:

  • consumer (Ears::Consumer)

    The user-defined consumer implementation derived from Ears::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+.



11
12
13
14
# File 'lib/ears/consumer_wrapper.rb', line 11

def initialize(consumer, channel, queue, consumer_tag, arguments = {})
  @consumer = consumer
  super(channel, queue, consumer_tag, false, 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.



21
22
23
24
25
# File 'lib/ears/consumer_wrapper.rb', line 21

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