Class: BunnyCarrot::ConsumerActor
- Inherits:
-
LoggingActor
- Object
- Concurrent::Actor
- LoggingActor
- BunnyCarrot::ConsumerActor
- Defined in:
- lib/bunny_carrot/consumer_actor.rb
Instance Method Summary collapse
- #act(queue_name, worker) ⇒ Object
-
#initialize(business_actor, pool_size) ⇒ ConsumerActor
constructor
A new instance of ConsumerActor.
Methods inherited from LoggingActor
Methods included from 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) } = 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() end end |