Class: Totoro::SubscribeService
- Inherits:
-
Object
- Object
- Totoro::SubscribeService
- Defined in:
- lib/totoro/services/subscribe_service.rb
Instance Method Summary collapse
- #channel ⇒ Object
-
#initialize(config) ⇒ SubscribeService
constructor
A new instance of SubscribeService.
- #subscribe(id) ⇒ Object
Constructor Details
#initialize(config) ⇒ SubscribeService
Returns a new instance of SubscribeService.
5 6 7 |
# File 'lib/totoro/services/subscribe_service.rb', line 5 def initialize(config) @config = config end |
Instance Method Details
#channel ⇒ Object
19 20 21 |
# File 'lib/totoro/services/subscribe_service.rb', line 19 def channel @channel ||= Bunny.new(@config.connect).tap(&:start).create_channel end |
#subscribe(id) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/totoro/services/subscribe_service.rb', line 9 def subscribe(id) queue = bind_queue(id) queue.purge if @config.clean_start?(id) queue.subscribe(manual_ack: @config.manual_ack?(id)) do |delivery_info, , payload| yield(delivery_info, , payload) ensure channel.ack(delivery_info.delivery_tag) if @config.force_ack?(id) end end |