Class: BunnyCarrot::ConsumerActor

Inherits:
LoggingActor
  • Object
show all
Defined in:
lib/bunny_carrot/consumer_actor.rb

Instance Method Summary collapse

Methods inherited from LoggingActor

#on_error

Methods included from Logger

included, #logger

Constructor Details

#initialize(business_actor, pool_size) ⇒ ConsumerActor

Returns a new instance of ConsumerActor.



4
5
6
7
8
9
# File 'lib/bunny_carrot/consumer_actor.rb', line 4

def initialize(business_actor, pool_size)
  super()
  @business_actor = business_actor
  @pool_size      = pool_size
  logger.info 'Consumer actor initialized'
end

Instance Method Details

#act(queue_name, worker) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bunny_carrot/consumer_actor.rb', line 11

def act(queue_name, worker)
  logger.info "Consumer is acting..."
  queue = channel.queue(queue_name, durable: true)
  queue.subscribe(block: true, ack: true) do |delivery_info, properties, payload|
    acknowledge_proc = lambda { channel.ack(delivery_info.delivery_tag) }
    message_hash     = Hamster.hash({ queue_name:       queue_name,
                                      payload:          JSON.parse(payload),
                                      message_headers:  Hamster.hash(properties.headers || {}),
                                      acknowledge_proc: acknowledge_proc,
                                      worker:           worker })
    @business_actor.post(message_hash)
  end
end