class Warren::Den
A Den
is in charge of creating a Fox
from a consumer configuration It handles the registration of dead-letter queues, and configuration of {Warren::Subscription subscriptions} and {Warren::DelayExchange delay exchanges}
Constants
- DEFAULT_WORKER_COUNT
The number of simultaneous workers generated by default
Public Class Methods
new(app_name, config, adaptor:)
click to toggle source
Create a {Warren::Fox} work pool. @param app_name [String] The name of the application. Corresponds to the
subscriptions config in `config/warren.yml`
@param config [Warren::Config::Consumers] A configuration object, loaded from `config/warren.yml` by default @param adaptor [#recovered?,#handle,#env] An adaptor to handle framework specifics
# File lib/warren/den.rb, line 23 def initialize(app_name, config, adaptor:) @app_name = app_name @config = config @fox = nil @adaptor = adaptor end
Public Instance Methods
fox()
click to toggle source
# File lib/warren/den.rb, line 30 def fox @fox ||= spawn_fox end
register_dead_letter_queues()
click to toggle source
Ensures the dead_letter queues and exchanges are registered.
@return [Void]
# File lib/warren/den.rb, line 38 def register_dead_letter_queues config = dead_letter_config return unless config Warren.handler.with_channel do |channel| subscription = Warren::Subscription.new(channel: channel, config: config) subscription.activate! end end
Private Instance Methods
consumer_config()
click to toggle source
# File lib/warren/den.rb, line 50 def consumer_config @config.consumer(@app_name) end
dead_letter_config()
click to toggle source
# File lib/warren/den.rb, line 81 def dead_letter_config consumer_config.fetch('dead_letters') end
delay_config()
click to toggle source
# File lib/warren/den.rb, line 85 def delay_config consumer_config.fetch('delay', nil) end
queue_config()
click to toggle source
# File lib/warren/den.rb, line 77 def queue_config consumer_config.fetch('queue') end
spawn_fox()
click to toggle source
Spawn a new fox
@return [Warren::Fox]
# File lib/warren/den.rb, line 58 def spawn_fox # We don't use with_channel as our consumer persists outside the block, # and while we *can* share channels between consumers it results in them # sharing the same worker pool. This process lets us control workers on # a per-queue basis. Currently that just means one worker per consumer. channel = Warren.handler.new_channel(worker_count: worker_count) subscription = Warren::Subscription.new(channel: channel, config: queue_config) delay = Warren::DelayExchange.new(channel: channel, config: delay_config) Warren::Fox.new(name: @app_name, subscription: subscription, adaptor: @adaptor, subscribed_class: subscribed_class, delayed: delay) end
subscribed_class()
click to toggle source
# File lib/warren/den.rb, line 89 def subscribed_class Object.const_get(consumer_config.fetch('subscribed_class')) end
worker_count()
click to toggle source
# File lib/warren/den.rb, line 73 def worker_count consumer_config.fetch('worker_count', DEFAULT_WORKER_COUNT) end